Return all the permissions the model has via roles.
544359
public function getPermissionsViaRoles(): Collection
    {
        return $this->load('roles', 'roles.permissions')
            ->roles->flatMap(function ($role) {
                return $role->permissions;
            })->sort()->values();
    }
826124
def _apply_role_tree(self, perm_tree, role):
        """"""
        role_permissions = role.get_permissions()
        for perm in role_permissions:
            self._traverse_tree(perm_tree, perm)['checked'] = True
        return perm_tree
475743
def get_user_permissions(self, user_id):
        """"""
        permissions = self.user_service.getPermissions(id=user_id)
        return sorted(permissions, key=itemgetter('keyName'))
803131
def _checkPermissions(self, user, event):
        """"""

        for role in user.account.roles:
            if role in event.roles:
                self.log('Access granted', lvl=verbose)
                return True

        self.log('Access denied', lvl=verbose)
        return False
945189
def check_permissions(self, request):
        """"""
        objs = [None]
        if hasattr(self, 'get_perms_objects'):
            objs = self.get_perms_objects()
        else:
            if hasattr(self, 'get_object'):
                try:
                    objs = [self.get_object()]
                except Http404:
                    raise
                except:
                    pass
            if objs == [None]:
                objs = self.get_queryset()
            if len(objs) == 0:
                objs = [None]

        if (hasattr(self, 'permission_filter_queryset') and
           self.permission_filter_queryset is not False and
           self.request.method == 'GET'):
            if objs != [None]:
                self.perms_filter_queryset(objs)
        else:
            has_perm = check_perms(self.request.user,
                                   self.get_permission_required(),
                                   objs, self.request.method)

            if not has_perm:
                msg = self.get_permission_denied_message(
                    default="Permission denied."
                )
                if isinstance(msg, Sequence):
                    msg = msg[0]
                self.permission_denied(request, message=msg)
994539
def has_any_roles(self, *roles):
        
        roles = map(utils.slugify, list(roles))

        return True \
            if AuthUserRole.query() \
            .join(AuthUser) \
            .filter(AuthUserRole.name.in_(roles)) \
            .filter(AuthUser.id == self.id) \
            .count() \
            else False
283916
def permissions(self, **kwargs):
        
        self._validate_loaded()
        return TailoredAudiencePermission.all(self.account, self.id, **kwargs)
151641
public function getRolesWithPermissions(): Collection
    {
        return $this->roleRepository->makeQuery()
            ->with('permissions')
            ->notSuperAdmin()
            ->orderBy('name')
            ->get()
            ->map(function (HCAclRole $role) {
                return [
                    'id' => $role->id,
                    'role' => $role->name,
                    'slug' => $role->slug,
                    'permissions' => $role->permissions->pluck('id')->all(),
                ];
            });
    }
1089482
def has_permission(user, *permissions, **role_kwargs):
    
    Role = get_model('role')
    Perm = get_model('permission')
    if isinstance(user, (unicode, str)):
        User = get_model('user')
        user = User.get(User.c.username==user)
        
    for name in permissions:
        perm = Perm.get(Perm.c.name==name)
        if not perm:
            continue
        
        flag = has_role(user, *list(perm.perm_roles.with_relation().all()), **role_kwargs)
        if flag:
            return flag
        
    return False
736024
def get_all_roles(resource_root, service_name, cluster_name="default", view=None):
  
  return call(resource_root.get,
      _get_roles_path(cluster_name, service_name),
      ApiRole, True, params=view and dict(view=view) or None)
246678
def has_perm(self, user, perm, obj=None):
        """"""
        if not user.is_active:
            return False
        return perm in self.get_all_permissions(user, obj)
1349808
def roles(self):
        """"""
        result = AuthGroup.objects(creator=self.client).only('role')
        return json.loads(result.to_json())
1222626
def role_entities(self):
        
        return [self.service.roles[name] for name in self.content.roles]
1133763
public List<Permission> getPermissions(Principal p) {
		List<Permission> perms = new ArrayList<Permission>();
		lur.fishAll(p, perms);
		return perms;
	}
1100395
def permissions(self):
        
        response = self.graph.get('%s/permissions' % self.id)

        permissions = []
        for permission, state in response['data'][0].items():
            permissions.append(permission)
        
        return permissions
32460
def get_all_roles(self, view = None):
    
    return roles.get_all_roles(self._get_resource_root(), self.name,
        self._get_cluster_name(), view)
268988
def get_permissions(self, obj):
        
        # TODO: Optimize this for bulk running
        filters = {
            'object_pk': obj.id,
            'content_type': ContentType.objects.get_for_model(obj),
            'permission__codename__startswith': 'view',
        }
        return {
            'users': list(
                UserObjectPermission.objects.filter(**filters).distinct('user').values_list('user_id', flat=True)
            ),
            'groups': list(
                GroupObjectPermission.objects.filter(**filters).distinct('group').values_list('group', flat=True)
            ),
            'public': UserObjectPermission.objects.filter(user__username=ANONYMOUS_USER_NAME, **filters).exists(),
        }