Skip to content
Snippets Groups Projects
Commit b0b37c11 authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[team] Show objects shared; Hide delete button if not deletable

Show objects shared through a team. This is done w.r.t. the user viewing the
team information.

Furthermore, if objects are not deletable, then don't show the delete button.
parent 5d8a7d15
No related branches found
No related tags found
No related merge requests found
...@@ -93,23 +93,48 @@ class Team(models.Model): ...@@ -93,23 +93,48 @@ class Team(models.Model):
return (self.owner.username, self.name) return (self.owner.username, self.name)
def total_shares(self): def total_shares(self, user=None):
'''Count number of objects shared with this team
If ``user`` is passed, counts objects shared with this team that the
given user has access to.
'''
used_at = 0 used_at = 0
used_at += self.shared_algorithms.count()
used_at += self.shared_databases.count() if user is None:
used_at += self.shared_dataformats.count()
used_at += self.shared_environments.count() used_at += self.shared_algorithms.count()
used_at += self.shared_experiments.count() used_at += self.shared_databases.count()
used_at += self.shared_librarys.count() used_at += self.shared_dataformats.count()
used_at += self.shared_plotterparameters.count() used_at += self.shared_environments.count()
used_at += self.shared_plotters.count() used_at += self.shared_experiments.count()
used_at += self.shared_searchs.count() used_at += self.shared_librarys.count()
used_at += self.shared_toolchains.count() used_at += self.shared_plotterparameters.count()
used_at += self.usable_algorithms.count() used_at += self.shared_plotters.count()
used_at += self.usable_librarys.count() used_at += self.shared_searchs.count()
used_at += self.usable_plotterparameters.count() used_at += self.shared_toolchains.count()
used_at += self.usable_plotters.count() used_at += self.usable_algorithms.count()
used_at += self.usable_librarys.count()
used_at += self.usable_plotterparameters.count()
used_at += self.usable_plotters.count()
else:
used_at += self.shared_algorithms.for_user(user, add_public=True).count()
used_at += self.shared_databases.for_user(user, add_public=True).count()
used_at += self.shared_dataformats.for_user(user, add_public=True).count()
used_at += self.shared_environments.for_user(user, add_public=True).count()
used_at += self.shared_experiments.for_user(user, add_public=True).count()
used_at += self.shared_librarys.for_user(user, add_public=True).count()
used_at += self.shared_plotterparameters.for_user(user, add_public=True).count()
used_at += self.shared_plotters.for_user(user, add_public=True).count()
used_at += self.shared_searchs.for_user(user, add_public=True).count()
used_at += self.shared_toolchains.for_user(user, add_public=True).count()
used_at += self.usable_algorithms.for_user(user, add_public=True).count()
used_at += self.usable_librarys.for_user(user, add_public=True).count()
used_at += self.usable_plotterparameters.for_user(user, add_public=True).count()
used_at += self.usable_plotters.for_user(user, add_public=True).count()
return used_at return used_at
......
{% comment %} {% comment %}
* Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/ * Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/
* Contact: beat.support@idiap.ch * Contact: beat.support@idiap.ch
* *
* This file is part of the beat.web module of the BEAT platform. * This file is part of the beat.web module of the BEAT platform.
* *
* Commercial License Usage * Commercial License Usage
* Licensees holding valid commercial BEAT licenses may use this file in * Licensees holding valid commercial BEAT licenses may use this file in
* accordance with the terms contained in a written agreement between you * accordance with the terms contained in a written agreement between you
* and Idiap. For further information contact tto@idiap.ch * and Idiap. For further information contact tto@idiap.ch
* *
* Alternatively, this file may be used under the terms of the GNU Affero * Alternatively, this file may be used under the terms of the GNU Affero
* Public License version 3 as published by the Free Software and appearing * Public License version 3 as published by the Free Software and appearing
* in the file LICENSE.AGPL included in the packaging of this file. * in the file LICENSE.AGPL included in the packaging of this file.
* The BEAT platform is distributed in the hope that it will be useful, but * The BEAT platform is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. * or FITNESS FOR A PARTICULAR PURPOSE.
* *
* You should have received a copy of the GNU Affero Public License along * You should have received a copy of the GNU Affero Public License along
* with the BEAT platform. If not, see http://www.gnu.org/licenses/. * with the BEAT platform. If not, see http://www.gnu.org/licenses/.
{% endcomment %} {% endcomment %}
{% load team_tags %}
<div class="btn-group btn-group-sm action-buttons pull-right"> <div class="btn-group btn-group-sm action-buttons pull-right">
{% if display_count %} {% if display_count %}
<a class="btn btn-default btn-references" href="{% url 'teams:view' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Number of members in this team"><span class="badge">{{ object.members.count }}</span></a> <a class="btn btn-default btn-references" href="{% url 'teams:view' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Number of objects shared through this team"><span class="badge">{% total_shares_for_user object %}</span></a>
<a class="btn btn-default btn-references" href="{% url 'teams:view' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Number of members in this team">{{ object.members.count }} <i class="fa fa-group"></i></a>
{% endif %} {% endif %}
{% ifequal request.user object.owner %} {% ifequal request.user object.owner %}
<!-- Delete, needs to be the owner --> <!-- Delete, needs to be the owner -->
{% if object.deletable %}
<a class="btn btn-default btn-delete" onclick="modal_delete('team', '{{ object.name }}', '{% url 'api_teams:user_teamlist' request.user.username %}', '{% url 'teams:list' request.user.username %}');" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fa fa-times fa-lg"></i></a> <a class="btn btn-default btn-delete" onclick="modal_delete('team', '{{ object.name }}', '{% url 'api_teams:user_teamlist' request.user.username %}', '{% url 'teams:list' request.user.username %}');" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fa fa-times fa-lg"></i></a>
{% endif %}
<!-- Edit --> <!-- Edit -->
<a class="btn btn-default btn-edit" href="{% url 'teams:edit' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit fa-lg"></i></a> <a class="btn btn-default btn-edit" href="{% url 'teams:edit' object.owner.username object.name %}" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit fa-lg"></i></a>
......
...@@ -86,10 +86,21 @@ def team_actions(context, obj, display_count): ...@@ -86,10 +86,21 @@ def team_actions(context, obj, display_count):
} }
register.inclusion_tag('ui/contribution_list.html') #--------------------------------------------------
@register.inclusion_tag('ui/contribution_list.html')
def user_list(id): def user_list(id):
return { 'panel_id': id, return { 'panel_id': id,
'URL_PREFIX': settings.URL_PREFIX, 'URL_PREFIX': settings.URL_PREFIX,
'finder_placeholder': 'Find an User...', 'finder_placeholder': 'Find an User...',
'owner': False, 'owner': False,
} }
#--------------------------------------------------
@register.simple_tag(takes_context=True)
def total_shares_for_user(context, team):
return team.total_shares(context['request'].user)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment