<s> from rest_framework import permissions <EOL> from huxley . core . models import Assignment <EOL> class IsSuperuserOrReadOnly ( permissions . BasePermission ) : <EOL> '''<STR_LIT>''' <EOL> def has_permission ( self , request , view ) : <EOL> return ( request . user . is_superuser or <EOL> request . method in permissions . SAFE_METHODS ) <EOL> class IsUserOrSuperuser ( permissions . BasePermission ) : <EOL> '''<STR_LIT>''' <EOL> def has_object_permission ( self , request , view , obj ) : <EOL> return request . user . is_superuser or request . user == obj <EOL> class IsAdvisorOrSuperuser ( permissions . BasePermission ) : <EOL> '''<STR_LIT>''' <EOL> def has_object_permission ( self , request , view , obj ) : <EOL> return request . user . is_superuser or request . user == obj . advisor <EOL> class IsSchoolAdvisorOrSuperuser ( permissions . BasePermission ) : <EOL> '''<STR_LIT>''' <EOL> def has_permission ( self , request , view ) : <EOL> if request . user . is_superuser : <EOL> return True <EOL> school_id = view . kwargs . get ( '<STR_LIT>' , None ) <EOL> user = request . user <EOL> return ( user . is_authenticated ( ) and user . is_advisor ( ) and <EOL> user . school_id == int ( school_id ) ) <EOL> class IsPostOrSuperuserOnly ( permissions . BasePermission ) : <EOL> '''<STR_LIT>''' <EOL> def has_permission ( self , request , view ) : <EOL> return request . method == '<STR_LIT:POST>' or request . user . is_superuser <EOL> class IsSchoolAssignmentAdvisorOrSuperuser ( permissions . BasePermission ) : <EOL> '''<STR_LIT>''' <EOL> def has_permission ( self , request , view ) : <EOL> if request . user . is_superuser : <EOL> return True <EOL> assignment_id = view . kwargs . get ( '<STR_LIT>' , None ) <EOL> assignment = Assignment . objects . get ( id = assignment_id ) <EOL> user = request . user <EOL> return ( user . is_authenticated ( ) and user . is_advisor ( ) and <EOL> user . school . id == assignment . school . id ) </s>
