Return a perm_dict where only the highest permission for each subject is
        included.
546366
def _highest_perm_dict_from_perm_dict(self, perm_dict):
        """"""
        highest_perm_dict = copy.copy(perm_dict)
        for ordered_str in reversed(ORDERED_PERM_LIST):
            for lower_perm in self._lower_perm_list(ordered_str):
                highest_perm_dict.setdefault(lower_perm, set())
                highest_perm_dict[lower_perm] -= perm_dict.get(ordered_str, set())
        return highest_perm_dict
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
255739
def validate_permission(self, key, permission):
        
        if permission.perm_name not in self.__possible_permissions__:
            raise AssertionError(
                "perm_name is not one of {}".format(self.__possible_permissions__)
            )
        return permission
292748
def _load_group_permissions(self):
        
        group_names = self._get_groups().get_group_names()

        perms = Permission.objects.filter(group__name__in=group_names)
        perms = perms.values_list('content_type__app_label', 'codename')
        perms = perms.order_by()

        self._group_permissions = set(["%s.%s" % (ct, name) for ct, name in perms])
987161
public String checkAccess (Permission perm, Object context)
    {
        if (_permPolicy == null) {
            _permPolicy = createPermissionPolicy();
        }
        return _permPolicy.checkAccess(perm, context);
    }
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)
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
1225636
async def _check_perm(self, session) -> bool:
        
        return await perm.check_permission(session.bot, session.ctx,
                                           self.permission)
1168707
def perm_to_permission(perm):
    
    from django.contrib.auth.models import Permission
    try:
        app_label, codename = perm.split('.', 1)
    except (ValueError, IndexError):
        raise AttributeError(
            'The format of identifier string permission (perm) is wrong. '
            "It should be in 'app_label.codename'."
        )
    else:
        permission = Permission.objects.get(
            content_type__app_label=app_label,
            codename=codename
        )
        return permission
961887
def get_requested_aosp_permissions(self):
        
        aosp_permissions = []
        all_permissions = self.get_permissions()
        for perm in all_permissions:
            if perm in list(self.permission_module.keys()):
                aosp_permissions.append(perm)
        return aosp_permissions
1014908
def perform_permissions_check(self, user, obj, perms):
        
        return self.request.forum_permission_handler.can_lock_topics(obj, user)
844650
def _get_group_cached_perms(self):
        
        if not self.group:
            return {}
        perms = Permission.objects.filter(
            group=self.group,
        )
        group_permissions = {}
        for perm in perms:
            group_permissions[(
                perm.object_id,
                perm.content_type_id,
                perm.codename,
                perm.approved,
            )] = True
        return group_permissions
39783
def _get_user_cached_perms(self):
        
        if not self.user:
            return {}, {}
        group_pks = set(self.user.groups.values_list(
            'pk',
            flat=True,
        ))
        perms = Permission.objects.filter(
            Q(user__pk=self.user.pk) | Q(group__pk__in=group_pks),
        )
        user_permissions = {}
        group_permissions = {}
        for perm in perms:
            if perm.user_id == self.user.pk:
                user_permissions[(
                    perm.object_id,
                    perm.content_type_id,
                    perm.codename,
                    perm.approved,
                )] = True
            # If the user has the permission do for something, but perm.user !=
            # self.user then by definition that permission came from the
            # group.
            else:
                group_permissions[(
                    perm.object_id,
                    perm.content_type_id,
                    perm.codename,
                    perm.approved,
                )] = True
        return user_permissions, group_permissions
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
813871
def has_permission(self):
        """"""
        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 (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)
            return True
        else:
            return check_perms(self.request.user,
                               self.get_permission_required(),
                               objs, self.request.method)
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
901386
def has_permission(self, perm):
        
        return self.user.superuser or self.auth.has_permission(perm)