Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from rest_framework.permissions import BasePermission
3import sys
5class IsLocationSupervisor(BasePermission):
6 """
7 Custom permission to only allow supervisors of an object to edit it.
8 """
10 def has_object_permission(self, request, view, obj):
11 # Read permissions are allowed to any request,
12 # so we'll always allow GET, HEAD or OPTIONS requests.
13 #if request.method in permissions.SAFE_METHODS:
14 # return True
16 # Write permissions are only allowed to a supervisor of the object.
17 return request.user in obj.supervisors.all()
19class IsSameUser(BasePermission):
21 """
22 Custom permission to only same user as requested
23 """
25 def has_object_permission(self, request, view, obj):
26 return request.user == obj
28class IsSupervisorUser(BasePermission):
30 """
31 Custom permission to supervisor user in request
32 """
34 def has_object_permission(self, request, view, obj):
35 return request.user.is_supervisor