:param permission: return only roles having this permission

        :returns: an dict where keys are `permissions` and values `roles` iterable.
770340
def get_permissions_assignments(self, obj=None, permission=None):
        
        session = None
        if obj is not None:
            assert isinstance(obj, Entity)
            session = object_session(obj)

            if obj.id is None:
                obj = None

        if session is None:
            session = db.session()

        pa = session.query(
            PermissionAssignment.permission, PermissionAssignment.role
        ).filter(PermissionAssignment.object == obj)

        if permission:
            pa = pa.filter(PermissionAssignment.permission == permission)

        results = {}
        for permission, role in pa.yield_per(1000):
            results.setdefault(permission, set()).add(role)

        return results
776984
def document_permissions(self):
        
        if self._document_permissions is None:
            self._document_permissions = DocumentPermissionList(
                self._version,
                service_sid=self._solution['service_sid'],
                document_sid=self._solution['sid'],
            )
        return self._document_permissions
478596
def which_roles_can(self, name):
        
        targetPermissionRecords = AuthPermission.objects(creator=self.client, name=name).first()
        return [{'role': group.role} for group in targetPermissionRecords.groups]
976484
def print_permissions(permissions):
    """"""

    table = formatting.Table(['keyName', 'Description'])
    for perm in permissions:
        table.add_row([perm['keyName'], perm['name']])
    return table
283916
def permissions(self, **kwargs):
        
        self._validate_loaded()
        return TailoredAudiencePermission.all(self.account, self.id, **kwargs)
1239598
def permission_table(user_permissions, all_permissions):
    """"""

    table = formatting.Table(['Description', 'KeyName', 'Assigned'])
    table.align['KeyName'] = 'l'
    table.align['Description'] = 'l'
    table.align['Assigned'] = 'l'
    for perm in all_permissions:
        assigned = user_permissions.get(perm['keyName'], False)
        table.add_row([perm['name'], perm['keyName'], assigned])
    return table
590681
def create(self, permission):
        
        parent_url = self.client.get_url(self.parent_object._manager._URL_KEY, 'GET', 'single', {'id': self.parent_object.id})
        target_url = parent_url + self.client.get_url_path(self._URL_KEY, 'POST', 'single')
        r = self.client.request('POST', target_url, json=permission._serialize())
        return permission._deserialize(r.json(), self)
454525
def get_group_permissions(self):
        
        if self._group_permissions is None:
            self._group_permissions = set()

            if self.settings.FIND_GROUP_PERMS:
                try:
                    self._load_group_permissions()
                except ldap.LDAPError as e:
                    results = ldap_error.send(self.backend.__class__,
                                              context='get_group_permissions',
                                              exception=e)
                    if len(results) == 0:
                        logger.warning("Caught LDAPError loading group permissions: %s",
                                       pprint.pformat(e))

        return self._group_permissions
175676
def request_permission(cls, permissions):
        
        app = AndroidApplication.instance()
        f = app.create_future()

        def on_result(perms):
            allowed = True
            for p in permissions:
                allowed = allowed and perms.get(p, False)
            f.set_result(allowed)

        app.request_permissions(permissions).then(on_result)

        return f
148891
def check_permission(cls, role, permission):
        
        result = permission in settings.ARCTIC_ROLES[role]
        # will try to call a method with the same name as the permission
        # to enable an object level permission check.
        if result:
            try:
                return getattr(cls, permission)(role)
            except AttributeError:
                pass
        return result
516109
def permission_to_04_acls(permissions):
    
    acls = []
    for perm in permissions:
        if perm.type == "user":
            acls.append((perm.user.id, perm.perm_name))
        elif perm.type == "group":
            acls.append(("group:%s" % perm.group.id, perm.perm_name))
    return acls
1323997
def which_users_can(self, name):
        
        _roles = self.which_roles_can(name)
        result =  [self.get_role_members(i.get('role')) for i in _roles]
        return result
648254
def list_user_permissions(self, name):
        
        return self._api_get('/api/users/{0}/permissions'.format(
            urllib.parse.quote_plus(name)
        ))
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
360489
def permission_attributes=(permissions)
      self.permissions = [] # Reset permissions in anticipation for re-population
    
      permissions.each do |key, value|
        key, value = key.dup, value.dup
      
        # Component Permissions
        if key.ends_with? "_permissions"
          grant_permissions(value)
        # Singular Permission
        elsif key.chomp! "_permission"
          grant_permissions(key) if value.to_i != 0
        end
      end
    end
559084
def get_all_permissions(self):
        """"""
        perms = set()
        for role in self.get_user_roles():
            for perm_view in role.permissions:
                t = (perm_view.permission.name, perm_view.view_menu.name)
                perms.add(t)
        return perms
415653
def check_permission(*permissions, **args_map):
    
    def f1(func, permissions=permissions):
        @wraps(func)
        def f2(*args, **kwargs):
            from uliweb import request, error

            arguments = {}
            for k, v in args_map.items():
                if v in kwargs:
                    arguments[k] = kwargs[v]
            if not has_permission(request.user, *permissions, **arguments):
                error(_("You have no permissions to visit this page."))
            return func(*args, **kwargs)
        return f2
    return f1