2020-12-26 20:26:26 +00:00
|
|
|
# Copyright (C) 2020 by Animath
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2020-10-15 19:07:18 +00:00
|
|
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
|
|
|
from django.core.exceptions import PermissionDenied
|
|
|
|
from haystack.generic_views import SearchView
|
|
|
|
|
|
|
|
|
2020-10-20 11:14:02 +00:00
|
|
|
class AdminMixin(LoginRequiredMixin):
|
2020-10-15 19:07:18 +00:00
|
|
|
def dispatch(self, request, *args, **kwargs):
|
|
|
|
if not request.user.is_authenticated:
|
|
|
|
return self.handle_no_permission()
|
|
|
|
if not request.user.registration.is_admin:
|
2020-10-20 11:14:02 +00:00
|
|
|
raise PermissionDenied
|
2020-10-15 19:07:18 +00:00
|
|
|
return super().dispatch(request, *args, **kwargs)
|
2020-10-20 11:14:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AdminSearchView(AdminMixin, SearchView):
|
|
|
|
pass
|