2024-11-24 02:20:18 +08:00
|
|
|
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(
|
2024-12-16 14:58:50 +08:00
|
|
|
request.user and request.user.role in (
|
|
|
|
"head", "admin", "planning", "staff")
|
2024-11-24 02:20:18 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-12-04 01:29:30 +08:00
|
|
|
class IsPlanning(BasePermission):
|
|
|
|
"""
|
|
|
|
Allows access only to users with head, admin planning role
|
|
|
|
"""
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
2025-01-17 11:39:00 +08:00
|
|
|
return bool(request.user and request.user.role in ("planning", "admin"))
|
2024-12-04 01:29:30 +08:00
|
|
|
|
|
|
|
|
2024-11-24 02:20:18 +08:00
|
|
|
class IsHead(BasePermission):
|
|
|
|
"""
|
|
|
|
Allows access only to users with staff role
|
|
|
|
"""
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
2025-01-17 11:39:00 +08:00
|
|
|
return bool(request.user and request.user.role in ("head", "admin"))
|
2025-01-16 19:54:49 +08:00
|
|
|
|
|
|
|
|
|
|
|
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")
|