1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-12-25 07:02:22 +00:00
This commit is contained in:
Yohann D'ANELLO 2020-05-04 22:27:45 +02:00
parent ac2790d327
commit 9499e10524
5 changed files with 39 additions and 9 deletions

View File

@ -1,7 +1,7 @@
from django.urls import path from django.urls import path
from django.views.generic import RedirectView from django.views.generic import RedirectView
from .views import CreateUserView, MyAccountView, UserDetailView,\ from .views import CreateUserView, MyAccountView, UserDetailView, MyTeamView,\
ProfileListView, OrphanedProfileListView, OrganizersListView, ResetAdminView ProfileListView, OrphanedProfileListView, OrganizersListView, ResetAdminView
app_name = "member" app_name = "member"
@ -12,7 +12,7 @@ urlpatterns = [
path("information/<int:pk>/", UserDetailView.as_view(), name="information"), path("information/<int:pk>/", UserDetailView.as_view(), name="information"),
path("add-team/", RedirectView.as_view(pattern_name="index"), name="add_team"), path("add-team/", RedirectView.as_view(pattern_name="index"), name="add_team"),
path("join-team/", RedirectView.as_view(pattern_name="index"), name="join_team"), path("join-team/", RedirectView.as_view(pattern_name="index"), name="join_team"),
path("my-team/", RedirectView.as_view(pattern_name="index"), name="my_team"), path("my-team/", MyTeamView.as_view(), name="my_team"),
path("my-team/update/", RedirectView.as_view(pattern_name="index"), name="update_my_team"), path("my-team/update/", RedirectView.as_view(pattern_name="index"), name="update_my_team"),
path("profiles/", ProfileListView.as_view(), name="all_profiles"), path("profiles/", ProfileListView.as_view(), name="all_profiles"),
path("orphaned-profiles/", OrphanedProfileListView.as_view(), name="orphaned_profiles"), path("orphaned-profiles/", OrphanedProfileListView.as_view(), name="orphaned_profiles"),

View File

@ -9,7 +9,8 @@ from django.views import View
from django.views.generic import CreateView, UpdateView, DetailView from django.views.generic import CreateView, UpdateView, DetailView
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from tournament.views import AdminMixin from tournament.models import Team
from tournament.views import AdminMixin, TeamMixin
from .forms import SignUpForm, TFJMUserForm from .forms import SignUpForm, TFJMUserForm
from .models import TFJMUser, Document from .models import TFJMUser, Document
from .tables import UserTable from .tables import UserTable
@ -64,6 +65,30 @@ class UserDetailView(LoginRequiredMixin, DetailView):
return context return context
class MyTeamView(TeamMixin, DetailView):
model = Team
def get_object(self, queryset=None):
return self.request.user.team
def dispatch(self, request, *args, **kwargs):
if isinstance(request.user, AnonymousUser):
raise PermissionDenied
team = self.get_object()
if not request.user.participates or team is None:
raise PermissionDenied
return super().dispatch(request, *args, **kwargs)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["title"] = str(self.object)
return context
class DocumentView(LoginRequiredMixin, View): class DocumentView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
doc = Document.objects.get(file=self.kwargs["file"]) doc = Document.objects.get(file=self.kwargs["file"])

View File

@ -135,10 +135,11 @@ class TeamDetailView(LoginRequiredMixin, DetailView):
class TeamUpdateView(LoginRequiredMixin, UpdateView): class TeamUpdateView(LoginRequiredMixin, UpdateView):
model = Team model = Team
form_class = TeamForm form_class = TeamForm
extra_context = dict(title=_("Udpate team"),) extra_context = dict(title=_("Update team"),)
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
if not request.user.admin and self.request.user not in self.get_object().tournament.organizers: if not request.user.admin and self.request.user not in self.get_object().tournament.organizers.all() \
and self.get_object() != self.request.user.team:
raise PermissionDenied raise PermissionDenied
return super().dispatch(request, *args, **kwargs) return super().dispatch(request, *args, **kwargs)

View File

@ -143,7 +143,7 @@
<ul class="navbar-nav"> <ul class="navbar-nav">
{% if "_fake_user_id" in request.session %} {% if "_fake_user_id" in request.session %}
<li class="nav-item active"> <li class="nav-item active">
<a class="nav-link" href="{% url "member:reset_admin" %}?path={{ request.path }}"><i class="fas fa-cog"></i> {% trans "Return to admin view" %}</a> <a class="nav-link" href="{% url "member:reset_admin" %}?path={{ request.path }}"><i class="fas fa-tools"></i> {% trans "Return to admin view" %}</a>
</li> </li>
{% endif %} {% endif %}
{% if not user.is_authenticated %} {% if not user.is_authenticated %}

View File

@ -26,13 +26,17 @@
</dl> </dl>
</div> </div>
{% if user.admin or user in team.tournament.organizers.all %} {% if user.admin or user in team.tournament.organizers.all or team == user.team %}
<div class="card-footer text-center"> <div class="card-footer text-center">
<a href="{% url "tournament:team_update" pk=team.pk %}"><button class="btn btn-secondary">{% trans "Edit team" %}</button></a> <a href="{% url "tournament:team_update" pk=team.pk %}"><button class="btn btn-secondary">{% trans "Edit team" %}</button></a>
{% if user.admin and team.invalid %} {% if team.invalid %}
<form method="post"> <form method="post">
{% csrf_token %} {% csrf_token %}
<button name="delete" class="btn btn-danger">{% trans "Delete team" %}</button> {% if user.admin %}
<button name="delete" class="btn btn-danger">{% trans "Delete team" %}</button>
{% elif team == user.team %}
<button name="leave" class="btn btn-danger">{% trans "Leave this team" %}</button>
{% endif %}
</form> </form>
{% endif %} {% endif %}
</div> </div>