Intitial teams support #147
@ -68,3 +68,17 @@ class TeamsUsers(CreatedModifiedMixin, models.Model):
|
|||||||
extension.save(update_fields={'team'})
|
extension.save(update_fields={'team'})
|
||||||
|
|
||||||
return super().delete()
|
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>
|
<h1 class="mb-3">Teams</h1>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col">
|
<div class="col">
|
||||||
{% if user.team_users.all %}
|
{% if team_memberships %}
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
@ -21,7 +21,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for team_member in user.team_users.all %}
|
{% for team_member in team_memberships %}
|
||||||
{% with team=team_member.team %}
|
{% with team=team_member.team %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
@ -38,14 +38,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{# TODO: @back-end disable dropdown btn leave team if user is the only manager #}
|
|
||||||
<div class="dropdown">
|
<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>
|
<i class="i-more-vertical"></i>
|
||||||
</button>
|
</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>
|
<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>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -11,8 +11,10 @@ from teams.models import Team, TeamsUsers
|
|||||||
class TeamsView(LoginRequiredMixin, ListView):
|
class TeamsView(LoginRequiredMixin, ListView):
|
||||||
model = Team
|
model = Team
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_context_data(self, **kwargs):
|
||||||
return self.request.user.teams.all()
|
context = super().get_context_data(**kwargs)
|
||||||
|
context['team_memberships'] = self.request.user.team_users.select_related('team').all()
|
||||||
|
return context
|
||||||
|
|
||||||
|
|
||||||
class LeaveTeamView(LoginRequiredMixin, DetailView):
|
class LeaveTeamView(LoginRequiredMixin, DetailView):
|
||||||
|
Loading…
Reference in New Issue
Block a user