2023-11-13 18:22:53 +08:00
|
|
|
from rest_framework.permissions import BasePermission
|
|
|
|
|
|
|
|
|
|
|
|
class IsTechnician(BasePermission):
|
|
|
|
message = "You must be a technician to perform this action."
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
|
|
|
return request.user.is_authenticated and request.user.is_technician
|
|
|
|
|
|
|
|
def has_object_permission(self, request, view, obj):
|
|
|
|
return request.user.is_authenticated and request.user.is_technician
|
2023-12-08 23:00:15 +08:00
|
|
|
|
|
|
|
|
|
|
|
class IsTeacher(BasePermission):
|
|
|
|
message = "You must be a teacher to perform this action."
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
|
|
|
return request.user.is_authenticated and request.user.is_teacher
|
|
|
|
|
|
|
|
def has_object_permission(self, request, view, obj):
|
|
|
|
return request.user.is_authenticated and request.user.is_teacher
|
|
|
|
|
|
|
|
|
|
|
|
class IsStudent(BasePermission):
|
|
|
|
message = "You must be a student to perform this action."
|
|
|
|
|
|
|
|
def has_permission(self, request, view):
|
2023-12-21 14:57:42 +08:00
|
|
|
return request.user.is_authenticated and (not request.user.is_teacher and not request.user.is_technician)
|
2023-12-08 23:00:15 +08:00
|
|
|
|
|
|
|
def has_object_permission(self, request, view, obj):
|
2023-12-21 14:57:42 +08:00
|
|
|
return request.user.is_authenticated and (not request.user.is_teacher and not request.user.is_technician)
|