Python rest_framework.permissions.BasePermission() Examples
The following are 25
code examples of rest_framework.permissions.BasePermission().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.permissions
, or try the search function
.
Example #1
Source File: has_role.py From omniport-backend with GNU General Public License v3.0 | 6 votes |
def get_has_role(role_name, active_status=ActiveStatus.IS_ACTIVE): """ Returns a permission class that checks if a person has a specific role :param role_name: the name of the role to check for :param active_status: the active status to look for :return: a permission class that can be used with DRF """ class HasRole(BasePermission): """ Allows access only to users having the given role """ def has_permission(self, request, view): return get_role( person=request.person, role_name=role_name, active_status=active_status, silent=True ) is not None return HasRole
Example #2
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def write_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_WRITE_OPERATION, AdminPermission.OBJ_TYPE_POOL, *args, **kwargs ) return Perm
Example #3
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_objv6_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv6( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #4
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def write_objv6_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv6( request, AdminPermission.OBJ_WRITE_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #5
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_objv4_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv4( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #6
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_PEER_GROUP, *args, **kwargs ) return Perm
Example #7
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def delete_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_DELETE_OPERATION, AdminPermission.OBJ_TYPE_PEER_GROUP, *args, **kwargs ) return Perm
Example #8
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def write_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_WRITE_OPERATION, AdminPermission.OBJ_TYPE_PEER_GROUP, *args, **kwargs ) return Perm
Example #9
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #10
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def delete_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_DELETE_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #11
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def deploy_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_UPDATE_CONFIG_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #12
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_POOL, *args, **kwargs ) return Perm
Example #13
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def delete_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_DELETE_OPERATION, AdminPermission.OBJ_TYPE_POOL, *args, **kwargs ) return Perm
Example #14
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def deploy_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_UPDATE_CONFIG_OPERATION, AdminPermission.OBJ_TYPE_POOL, *args, **kwargs ) return Perm
Example #15
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def delete_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_DELETE_OPERATION, AdminPermission.OBJ_TYPE_VIP, *args, **kwargs ) return Perm
Example #16
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def write_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_WRITE_OPERATION, AdminPermission.OBJ_TYPE_VIP, *args, **kwargs ) return Perm
Example #17
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def deploy_obj_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_obj( request, AdminPermission.OBJ_UPDATE_CONFIG_OPERATION, AdminPermission.OBJ_TYPE_VIP, *args, **kwargs ) return Perm
Example #18
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_objv6_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv6( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #19
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def delete_objv6_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv6( request, AdminPermission.OBJ_DELETE_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #20
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def deploy_objv6_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv6( request, AdminPermission.OBJ_UPDATE_CONFIG_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #21
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def read_objv4_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv4( request, AdminPermission.OBJ_READ_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #22
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def delete_objv4_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv4( request, AdminPermission.OBJ_DELETE_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #23
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def write_objv4_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv4( request, AdminPermission.OBJ_WRITE_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #24
Source File: permissions.py From GloboNetworkAPI with Apache License 2.0 | 5 votes |
def deploy_objv4_permission(request, *args, **kwargs): class Perm(BasePermission): def has_permission(self, request, view): return perm_objv4( request, AdminPermission.OBJ_UPDATE_CONFIG_OPERATION, AdminPermission.OBJ_TYPE_VLAN, *args, **kwargs ) return Perm
Example #25
Source File: rolemixins.py From kobo-predict with BSD 2-Clause "Simplified" License | 4 votes |
def dispatch(self, request, *args, **kwargs): if request.group.name == "Super Admin": return super(RegionRoleMixin, self).dispatch(request, *args, **kwargs) region_id = self.kwargs.get('pk') user_id = request.user.id project = Region.objects.get(pk=region_id).project user_role_aspadmin = request.roles.filter(user_id = user_id, project_id = project.id, group_id=2) if user_role_aspadmin: return super(RegionRoleMixin, self).dispatch(request, *args, **kwargs) organization_id = project.organization.id user_role_asorgadmin = request.roles.filter(user_id = user_id, organization_id = organization_id, group_id=1) if user_role_asorgadmin: return super(RegionRoleMixin, self).dispatch(request, *args, **kwargs) raise PermissionDenied() # for api mixins/permissions # class ProjectPermission(BasePermission): # def has_permission(self, request, view): # if request.group.name == "Super Admin": # return super(ProjectRoleMixin, self).dispatch(request, *args, **kwargs) # project_id = self.kwargs.get('pk') # user_id = request.user.id # user_role = request.roles.filter(user_id = user_id, project_id = project_id, group__name="Project Manager") # if user_role: # return True # organization_id = Project.objects.get(pk=project_id).organization.id # user_role_asorgadmin = request.roles.filter(user_id = user_id, organization_id = organization_id, group__name="Organization Admin") # if user_role_asorgadmin: # return True # return False