feat(dgsi.mixins): Introduce StaffRequiredMixin
This commit is contained in:
parent
f56961c7bb
commit
3b2937b6d1
1 changed files with 16 additions and 0 deletions
16
src/dgsi/mixins.py
Normal file
16
src/dgsi/mixins.py
Normal 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
|
Loading…
Reference in a new issue