Intitial teams support #147

Merged
Oleg-Komarov merged 34 commits from teams-support into main 2024-05-23 19:43:54 +02:00
4 changed files with 69 additions and 5 deletions
Showing only changes of commit 523628739c - Show all commits

View File

@ -0,0 +1,38 @@
{% extends "common/base.html" %}
{% load i18n %}
{% block content %}
<div class="row">
<div class="col col-md-8 mx-auto my-4">
<div class="box">
<h2>
{% blocktranslate with team_name=object.name %}Leave team {{ team_name }}?{% endblocktranslate %}
</h2>
<p>
{% if will_lose_access_to %}
{% blocktranslate %}
You will lose access to all team extensions that were not uploaded by you:
{% endblocktranslate %}
<ul>
{% for extension in will_lose_access_to %}
<li><a href="{{ extension.get_absolute_url }}">{{ extension }}</a></li>
{% endfor %}
</ul>
{% endif %}
</p>
<div class="btn-row-fluid">
<a href="#" class="btn js-btn-back">
<i class="i-cancel"></i>
<span>{% trans 'Cancel' %}</span>
</a>
<form method="post">
{% csrf_token %}
<button type="submit" class="btn btn-block btn-danger">
<i class="i-log-out"></i>
<span>{% trans 'Confirm Leave' %}</span>
</button>
</form>
</div>
</div>
</div>
</div>
{% endblock content %}

View File

@ -45,9 +45,7 @@
</button>
<ul class="dropdown-menu dropdown-menu-right js-dropdown-menu" id="team-{{ team.id }}">
<li>
{# TODO: @back-end add page leave team base and link #}
{# TODO: @back-end add conditional class 'dropdown-item-disabled' if user is the only manager #}
<a class="dropdown-item {% comment %}dropdown-item-disabled{% endcomment %}" href="#"><i class="i-log-out"></i>Leave Team</a>
<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>
</li>
</ul>
</div>

View File

@ -5,4 +5,9 @@ import teams.views
app_name = 'teams'
urlpatterns = [
path('settings/teams/', teams.views.TeamsView.as_view(), name='list'),
path(
'settings/leave-team/<slug:slug>/',
teams.views.LeaveTeamView.as_view(),
name='leave-team',
),
]

View File

@ -1,12 +1,35 @@
"""Team pages."""
from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import redirect
from django.views.generic import ListView
from django.views.generic.detail import DetailView
import teams.models
from extensions.models import Extension
from teams.models import Team, TeamsUsers
class TeamsView(LoginRequiredMixin, ListView):
model = teams.models.Team
model = Team
def get_queryset(self):
return self.request.user.teams.all()
class LeaveTeamView(LoginRequiredMixin, DetailView):
model = Team
template_name = 'teams/confirm_leave.html'
def post(self, request, *args, **kwargs):
team = self.get_object()
team_user = TeamsUsers.objects.filter(team=team, user=self.request.user).first()
team_user.delete()
return redirect('teams:list')
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['will_lose_access_to'] = list(
Extension.objects.authored_by(self.request.user)
.exclude(maintainer__user_id=self.request.user.pk)
.all()
)
return context