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:
13
corres2math/views.py
Normal file
13
corres2math/views.py
Normal 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)
|
Reference in New Issue
Block a user