Intitial teams support #147
@ -68,3 +68,17 @@ class TeamsUsers(CreatedModifiedMixin, models.Model):
|
||||
extension.save(update_fields={'team'})
|
||||
|
||||
return super().delete()
|
||||
|
||||
def may_leave(self) -> bool:
|
||||
nr_of_managers = TeamsUsers.objects.filter(role=TEAM_ROLE_MANAGER, team=self.team).count()
|
||||
user_is_manager = (
|
||||
TeamsUsers.objects.filter(
|
||||
role=TEAM_ROLE_MANAGER,
|
||||
team=self.team,
|
||||
user=self.user,
|
||||
).first()
|
||||
is not None
|
||||
)
|
||||
if user_is_manager and nr_of_managers < 2:
|
||||
return False
|
||||
return True
|
||||
|
@ -4,7 +4,7 @@
|
||||
<h1 class="mb-3">Teams</h1>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
{% if user.team_users.all %}
|
||||
{% if team_memberships %}
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -21,7 +21,7 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for team_member in user.team_users.all %}
|
||||
{% for team_member in team_memberships %}
|
||||
{% with team=team_member.team %}
|
||||
<tr>
|
||||
<td>
|
||||
@ -38,14 +38,16 @@
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{# TODO: @back-end disable dropdown btn leave team if user is the only manager #}
|
||||
<div class="dropdown">
|
||||
<button class="btn btn-link dropdown-toggle js-dropdown-toggle" data-toggle-menu-id="team-{{ team.id }}">
|
||||
<button class="btn btn-link dropdown-toggle js-dropdown-toggle" data-toggle-menu-id="team-{{ team.slug }}">
|
||||
<i class="i-more-vertical"></i>
|
||||
</button>
|
||||
<ul class="dropdown-menu dropdown-menu-right js-dropdown-menu" id="team-{{ team.id }}">
|
||||
{{ team.user_may_leave }}
|
||||
<ul class="dropdown-menu dropdown-menu-right js-dropdown-menu" id="team-{{ team.slug }}">
|
||||
<li>
|
||||
<a class="dropdown-item {% comment %}dropdown-item-disabled{% endcomment %}" href="{% url 'teams:leave-team' slug=team.slug %}"><i class="i-log-out"></i>Leave Team</a>
|
||||
<a class="dropdown-item {% if not team_member.may_leave %}dropdown-item-disabled{% endif %}" href="{% url 'teams:leave-team' slug=team.slug %}">
|
||||
<i class="i-log-out"></i>Leave Team
|
||||
</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -11,8 +11,10 @@ from teams.models import Team, TeamsUsers
|
||||
class TeamsView(LoginRequiredMixin, ListView):
|
||||
model = Team
|
||||
|
||||
def get_queryset(self):
|
||||
return self.request.user.teams.all()
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
context['team_memberships'] = self.request.user.team_users.select_related('team').all()
|
||||
return context
|
||||
|
||||
|
||||
class LeaveTeamView(LoginRequiredMixin, DetailView):
|
||||
|
Loading…
Reference in New Issue
Block a user