1
0
mirror of https://gitlab.com/animath/si/plateforme-corres2math.git synced 2025-07-05 20:03:55 +02:00

Protect search page to be read from non-admin users

This commit is contained in:
Yohann D'ANELLO
2020-10-15 21:07:18 +02:00
parent 144577bd89
commit 2a9e0f2692
4 changed files with 48 additions and 29 deletions

13
corres2math/views.py Normal file
View File

@ -0,0 +1,13 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.utils.translation import gettext_lazy as _
from haystack.generic_views import SearchView
class AdminSearchView(LoginRequiredMixin, SearchView):
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated:
return self.handle_no_permission()
if not request.user.registration.is_admin:
raise PermissionDenied(_("Only administrators are allowed to perform a full research."))
return super().dispatch(request, *args, **kwargs)