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

32 lines
1.1 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 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):
def dispatch(self, request, *args, **kwargs):
user = request.user
if user.is_authenticated and not user.registration.is_admin and user.registration.pk != kwargs["pk"]:
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