1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2024-11-27 01:27:09 +00:00
plateforme-tfjm2/tfjm/views.py

45 lines
1.8 KiB
Python
Raw Normal View History

2020-12-27 10:49:54 +00:00
# Copyright (C) 2020 by Animath
# SPDX-License-Identifier: GPL-3.0-or-later
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.models import User
2020-12-27 10:49:54 +00:00
from haystack.generic_views import SearchView
class AdminMixin(LoginRequiredMixin):
def dispatch(self, request, *args, **kwargs):
2020-12-29 15:14:56 +00:00
if request.user.is_authenticated and not request.user.registration.is_admin:
2021-01-17 11:40:23 +00:00
self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
class VolunteerMixin(LoginRequiredMixin):
def dispatch(self, request, *args, **kwargs):
if request.user.is_authenticated and not request.user.registration.is_volunteer:
self.handle_no_permission()
2020-12-29 15:14:56 +00:00
return super().dispatch(request, *args, **kwargs)
class UserMixin(LoginRequiredMixin):
2021-01-23 10:02:26 +00:00
def dispatch(self, request, *args, **kwargs):
user = request.user
if user.is_authenticated and not user.registration.is_admin and user.pk != kwargs["pk"]:
self.handle_no_permission()
return super().dispatch(request, *args, **kwargs)
class UserRegistrationMixin(LoginRequiredMixin):
2020-12-29 15:14:56 +00:00
def dispatch(self, request, *args, **kwargs):
user = request.user
user_object = User.objects.get(registration__pk=kwargs["pk"])
if user.is_authenticated and not user.registration.is_admin and user.registration.pk != kwargs["pk"] and \
not (user.registration.is_volunteer and user_object.registration.team is not None
and user_object.registration.team.participation.tournament
in user.registration.organized_tournaments.all()):
2021-01-17 11:40:23 +00:00
self.handle_no_permission()
2020-12-27 10:49:54 +00:00
return super().dispatch(request, *args, **kwargs)
class AdminSearchView(AdminMixin, SearchView):
pass