mirror of
https://github.com/lemeow125/Borrowing-TrackerBackend.git
synced 2024-11-17 06:19:26 +08:00
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
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
|
|
|
|
|
|
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):
|
|
return request.user.is_authenticated and (not request.user.is_teacher and not request.user.is_technician)
|
|
|
|
def has_object_permission(self, request, view, obj):
|
|
return request.user.is_authenticated and (not request.user.is_teacher and not request.user.is_technician)
|