Get list of permissions for a user

        :param obj_id: int
        :param permissions: str|list|tuple
        :return: dict|str
9238
def check_permission(self, obj_id, permissions):
        
        response = self._client.session.post(
            '{url}/{id}/permissioncheck'.format(
                url=self.endpoint_url, id=obj_id
            ),
            data={'permissions': permissions}
        )
        return self.process_response(response)
1159861
def get_users_with_permission(obj, permission):
    
    user_model = get_user_model()
    return user_model.objects.filter(
        userobjectpermission__object_pk=obj.pk,
        userobjectpermission__permission__codename=permission,
    ).distinct()
633571
def get_user_group_perms(user_or_group, obj):
    
    user, group = get_identity(user_or_group)

    if user and not user.is_active:
        return [], []
    user_model = get_user_model()
    ctype = ContentType.objects.get_for_model(obj)

    group_model = get_group_obj_perms_model(obj)
    group_rel_name = group_model.permission.field.related_query_name()
    if user:
        user_rel_name = user_model.groups.field.related_query_name()
        group_filters = {user_rel_name: user}
    else:
        group_filters = {'pk': group.pk}
    if group_model.objects.is_generic():
        group_filters.update({
            '{}__content_type'.format(group_rel_name): ctype,
            '{}__object_pk'.format(group_rel_name): obj.pk,
        })
    else:
        group_filters['{}__content_object'.format(group_rel_name)] = obj

    user_perms, group_perms = [], []

    if user:
        perms_qs = Permission.objects.filter(content_type=ctype)
        if user.is_superuser:
            user_perms = list(chain(perms_qs.values_list("codename", flat=True)))
        else:
            model = get_user_obj_perms_model(obj)
            related_name = model.permission.field.related_query_name()
            user_filters = {'{}__user'.format(related_name): user}
            if model.objects.is_generic():
                user_filters.update({
                    '{}__content_type'.format(related_name): ctype,
                    '{}__object_pk'.format(related_name): obj.pk,
                })
            else:
                user_filters['{}__content_object'.format(related_name)] = obj

            user_perms_qs = perms_qs.filter(**user_filters)
            user_perms = list(chain(user_perms_qs.values_list("codename", flat=True)))

    group_perms_qs = Group.objects.filter(**group_filters)
    group_perms = list(chain(group_perms_qs.order_by("pk").values_list(
        "pk", "name", "{}__permission__codename".format(group_rel_name))))

    group_perms = _group_groups(group_perms)

    return user_perms, group_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
562260
def get_owner_names_value(self, obj):
        """"""
        return [
            self._get_user(user)
            for user in get_users_with_permission(obj, get_full_perm('owner', obj))
        ]
960096
def _get_all_permissions(opts, tools):
    """"""
    perms = []
    for tool in tools:
        perms.append((_get_permission_codename(tool, opts), 'Can %s %s' % \
                (tool.name, opts.verbose_name_plural)))
    return perms
527660
def get_requested_aosp_permissions_details(self):
        
        l = {}
        for i in self.permissions:
            try:
                l[i] = self.permission_module[i]
            except KeyError:
                # if we have not found permission do nothing
                continue
        return l
23710
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_update_topics_to_announces(obj, user)
904089
def permissions(self, perms):
        

        if not isinstance(perms, (list, tuple)):
            perms = [perms]

        instances = []

        for perm in perms:
            if isclass(perm):
                instances.append(perm())
            else:
                instances.append(perm)

        def decorator(func):
            func.permissions = instances
            return func
        return decorator
1314633
def users_list(self, permission_set=None, role=None, **kwargs):
        ""
        api_path = "/api/v2/users.json"
        api_query = {}
        if "query" in kwargs.keys():
            api_query.update(kwargs["query"])
            del kwargs["query"]
        if permission_set:
            api_query.update({
                "permission_set": permission_set,
            })
        if role:
            api_query.update({
                "role": role,
            })
        return self.call(api_path, query=api_query, **kwargs)
317087
def _permission_trees(permissions):
        """"""
        treecache = PermissionTreeCache()
        cached = treecache.get()
        if not cached:
            tree = PermissionTreeBuilder()
            for permission in permissions:
                tree.insert(permission)
            result = tree.serialize()
            treecache.set(result)
            return result
        return cached
636429
def get_all_permissions(self):
        
        if self.all_permissions is None:
            permissions = self.client.call('User_Customer_CustomerPermission_Permission', 'getAllObjects')
            self.all_permissions = sorted(permissions, key=itemgetter('keyName'))
        return self.all_permissions
380689
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_move_topics(obj, user)
244429
def get_authzd_permissions(self, identifier, perm_domain):
        
        related_perms = []
        keys = ['*', perm_domain]

        def query_permissions(self):
            msg = ("Could not obtain cached permissions for [{0}].  "
                   "Will try to acquire permissions from account store."
                   .format(identifier))
            logger.debug(msg)

            # permissions is a dict:  {'domain': json blob of lists of dicts}
            permissions = self.account_store.get_authz_permissions(identifier)
            if not permissions:
                msg = "Could not get permissions from account_store for {0}".\
                    format(identifier)
                raise ValueError(msg)
            return permissions

        try:
            msg2 = ("Attempting to get cached authz_info for [{0}]"
                    .format(identifier))
            logger.debug(msg2)

            domain = 'authorization:permissions:' + self.name

            # related_perms is a list of json blobs whose contents are ordered
            # such that the order matches that in the keys parameter:
            related_perms = self.cache_handler.\
                hmget_or_create(domain=domain,
                                identifier=identifier,
                                keys=keys,
                                creator_func=query_permissions,
                                creator=self)
        except ValueError:
            msg3 = ("No permissions found for identifiers [{0}].  "
                    "Returning None.".format(identifier))
            logger.warning(msg3)

        except AttributeError:
            # this means the cache_handler isn't configured
            queried_permissions = query_permissions(self)

            related_perms = [queried_permissions.get('*'),
                             queried_permissions.get(perm_domain)]

        return related_perms
862853
def get_all_permissions(self, user, obj=None):
        
        if user.is_anonymous or obj is not None:
            return set()
        # TODO(gabrielhurley): Integrate policy-driven RBAC
        #                      when supported by Keystone.
        role_perms = {utils.get_role_permission(role['name'])
                      for role in user.roles}

        services = []
        for service in user.service_catalog:
            try:
                service_type = service['type']
            except KeyError:
                continue
            service_regions = [utils.get_endpoint_region(endpoint) for endpoint
                               in service.get('endpoints', [])]
            if user.services_region in service_regions:
                services.append(service_type.lower())
        service_perms = {"openstack.services.%s" % service
                         for service in services}
        return role_perms | service_perms
1267117
def get_permissions_for_registration(self):
        
        qs = Permission.objects.none()
        for instance in self.modeladmin_instances:
            qs = qs | instance.get_permissions_for_registration()
        return qs
359317
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_update_topics_to_normal_topics(obj, user)