mirror of
https://github.com/lemeow125/DocManagerBackend.git
synced 2025-01-19 01:23:02 +08:00
40 lines
1,005 B
Python
40 lines
1,005 B
Python
from rest_framework.permissions import BasePermission
|
|
|
|
|
|
class IsStaff(BasePermission):
|
|
"""
|
|
Allows access only to users with staff role
|
|
"""
|
|
|
|
def has_permission(self, request, view):
|
|
return bool(
|
|
request.user and request.user.role in (
|
|
"head", "admin", "planning", "staff")
|
|
)
|
|
|
|
|
|
class IsPlanning(BasePermission):
|
|
"""
|
|
Allows access only to users with head, admin planning role
|
|
"""
|
|
|
|
def has_permission(self, request, view):
|
|
return bool(request.user and request.user.role in ("planning", "admin"))
|
|
|
|
|
|
class IsHead(BasePermission):
|
|
"""
|
|
Allows access only to users with staff role
|
|
"""
|
|
|
|
def has_permission(self, request, view):
|
|
return bool(request.user and request.user.role in ("head", "admin"))
|
|
|
|
|
|
class IsAdmin(BasePermission):
|
|
"""
|
|
Allows access only to users with admin role
|
|
"""
|
|
|
|
def has_permission(self, request, view):
|
|
return bool(request.user and request.user.role == "admin")
|