Remove parent permissions from flattenpermissions when subpermissions aren't found within it
190638
function getParent(role) {
        var result = [];

        for (var parentRole in permissions) {
            if (permissions[parentRole].indexOf(role) > -1) {
                result.push(parentRole);
                result = result.concat(getParent(parentRole));
            }
        }
        return result;
    }
931835
public function losePermissions($permissions): void
    {
        if (!is_array($permissions) && !$permissions instanceof Collection) {
            $permissions = func_get_args();
        }

        foreach ($permissions as $permission) {
            $permission = $this->resolvePermission($permission);

            $this->permissions()->detach($permission);
        }
    }
944968
def object_permission_set(self):
        ''''''
        return Or(
            AllowOnlySafeHttpMethod,
            AllowAdmin,
            And(
                AllowPermission('org:admin'),
                ObjAttrTrue(lambda _, u: not u.is_superuser),
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True)
            ),
            And(
                AllowModify,
                ObjAttrTrue(
                    lambda req, user: user == req.user),
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True)
            ),
        )
557612
function(permissions, negative) {
            if (!negative) {
              negative = false;
            }
            if (permissions !== null && Array.isArray(permissions)) {
              if (negative) {
                this.permissions.exclude = permissions;
              } else {
                this.permissions.include = permissions;
              }
            }
          }
759181
private static List<String> getRationalePermissions(Source source, String... permissions) {
        List<String> rationaleList = new ArrayList<>(1);
        for (String permission : permissions) {
            if (source.isShowRationalePermission(permission)) {
                rationaleList.add(permission);
            }
        }
        return rationaleList;
    }
12457
function handlePermissions(options) {
            return canThis(options.context).destroy.user(options.id).then(() => {
                options.status = 'all';
                return options;
            }).catch((err) => {
                return Promise.reject(new common.errors.NoPermissionError({
                    err: err,
                    context: common.i18n.t('errors.api.users.noPermissionToDestroyUser')
                }));
            });
        }
650992
def destroy(self, request, pk=None, parent_lookup_organization=None):
        ''''''
        user = get_object_or_404(User, pk=pk)
        org = get_object_or_404(
            SeedOrganization, pk=parent_lookup_organization)
        self.check_object_permissions(request, org)
        org.users.remove(user)
        return Response(status=status.HTTP_204_NO_CONTENT)
1288337
void removeEmptyRole(Grantee role) {

        for (int i = 0; i < map.size(); i++) {
            Grantee grantee = (Grantee) map.get(i);

            grantee.roles.remove(role);
        }
    }
449741
def security_cleanup(self, baseviews, menus):
        
        viewsmenus = self.get_all_view_menu()
        roles = self.get_all_roles()
        for viewmenu in viewsmenus:
            found = False
            for baseview in baseviews:
                if viewmenu.name == baseview.__class__.__name__:
                    found = True
                    break
            if menus.find(viewmenu.name):
                found = True
            if not found:
                permissions = self.find_permissions_view_menu(viewmenu)
                for permission in permissions:
                    for role in roles:
                        self.del_permission_role(role, permission)
                    self.del_permission_view_menu(
                        permission.permission.name, viewmenu.name
                    )
                self.del_view_menu(viewmenu.name)
877568
def _multi_permission_mask(mode):
    
    def compose(f, g):
        return lambda *args, **kwargs: g(f(*args, **kwargs))
    return functools.reduce(compose, map(_permission_mask, mode.split(',')))
857892
protected synchronized void unsetPermission(ServiceReference<JavaPermissionsConfiguration> permission) {
        permissions.removeReference(permission);
        if (wsjarUrlStreamHandlerAvailable) {
            clearPermissions();
            initializePermissions();
        }
    }
268407
private void populatePermissionOverwrites() {
        if (overwrittenUserPermissions == null) {
            overwrittenUserPermissions = new HashMap<>();
            overwrittenUserPermissions.putAll(((ServerChannelImpl) channel).getInternalOverwrittenUserPermissions());
        }
        if (overwrittenRolePermissions == null) {
            overwrittenRolePermissions = new HashMap<>();
            overwrittenRolePermissions.putAll(((ServerChannelImpl) channel).getInternalOverwrittenRolePermissions());
        }
    }
39111
private FSPermissionChecker checkPermission(String path, INode[] inodes, boolean doCheckOwner,
                                              FsAction ancestorAccess, FsAction parentAccess, FsAction access,
                                              FsAction subAccess)
    throws AccessControlException {
    boolean permissionCheckFailed = false;
    FSPermissionChecker pc = new FSPermissionChecker(
      fsOwner.getUserName(), supergroup, this.getCurrentUGI());
    if (!pc.isSuper) {
      dir.waitForReady();
      readLock();
      try {
        pc.checkPermission(path, inodes, doCheckOwner,
          ancestorAccess, parentAccess, access, subAccess);
      } catch (AccessControlException e) {
        if (!this.permissionAuditOnly) {
          throw e;
        }
        permissionCheckFailed = true;
      } finally {
        readUnlock();
      }
    }
    if (permissionCheckFailed) {
      // do not throw the exception, we would like to only log.
      LOG.warn("PermissionAudit failed on " + path +
        " checkOwner:" + doCheckOwner +
        " ancestor:" + ancestorAccess +
        " parent:" + parentAccess +
        " access:" + access +
        " subaccess:" + subAccess);
    }
    return pc;
  }
1331924
def clean_perms(self):
        """"""
        logging.info('Cleaning faulty perms')
        sesh = self.get_session
        pvms = (
            sesh.query(ab_models.PermissionView)
            .filter(or_(
                ab_models.PermissionView.permission == None,  # NOQA
                ab_models.PermissionView.view_menu == None,  # NOQA
            ))
        )
        deleted_count = pvms.delete()
        sesh.commit()
        if deleted_count:
            logging.info('Deleted {} faulty permissions'.format(deleted_count))
717666
def autodiscover():
    """"""
    # Get permissions based on urlpatterns from urls.py
    url_conf = getattr(settings, 'ROOT_URLCONF', ())
    resolver = urlresolvers.get_resolver(url_conf)
    urlpatterns = resolver.url_patterns
    permissions = generate_permissions(urlpatterns)
    # Refresh permissions
    refresh_permissions(permissions)
770345
private void removeFromPermissionsCache(IAuthorizationPrincipal[] principals)
            throws AuthorizationException {
        for (int i = 0; i < principals.length; i++) {
            cacheRemove(principals[i]);
        }
    }
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