feat(dgsi.mixins): Introduce StaffRequiredMixin

This commit is contained in:
Tom Hubrecht 2024-09-14 15:44:52 +02:00
parent f56961c7bb
commit 3b2937b6d1
Signed by: thubrecht
SSH key fingerprint: SHA256:r+nK/SIcWlJ0zFZJGHtlAoRwq1Rm+WcKAm5ADYMoQPc

16
src/dgsi/mixins.py Normal file
View file

@ -0,0 +1,16 @@
from django.contrib.auth.mixins import UserPassesTestMixin
from django.http import HttpRequest
from dgsi.models import User
class StaffRequiredMixin(UserPassesTestMixin):
request: HttpRequest
def test_func(self) -> bool | None:
if self.request.user.is_authenticated:
return False
assert isinstance(self.request.user, User)
return self.request.user.is_admin