Helper to get a user's permissions for a ContentType.

@param string             $contentTypeSlug
@param array|Entity\Users $user

@return bool[]
431440
protected function getContentTypeUserPermissions($contentTypeSlug, $user = null)
    {
        if ($user === null) {
            return $this->app['permissions']->getContentTypePermissions();
        }

        return $this->app['permissions']->getContentTypeUserPermissions($contentTypeSlug, $user);
    }
1080245
private function restrictPermissions(array $userPermission, array $permissions)
    {
        return $this->mapPermissions($userPermission, $permissions, function($permission1, $permission2) {
            return $permission1 && $permission2;
        });
    }
907177
private function listUserAuthorizedSubdefs(User $user)
    {
        $acl = $this->getAclForUser($user);
        $ret = [];

        foreach ($acl->get_granted_sbas() as $databox) {
            $databoxId = $databox->get_sbas_id();
            $subdefs = $databox->get_subdef_structure();
            foreach ($subdefs as $subGroup) {
                foreach ($subGroup->getIterator() as $sub) {
                    $opt = [];
                    $data = [
                      'name'             => $sub->get_name(),
                      'databox_id'       => $databoxId,
                      'class'            => $sub->get_class(),
                      'preset'           => $sub->get_preset(),
                      'downloadable'     => $sub->isDownloadable(),
                      'devices'          => $sub->getDevices(),
                      'labels'           => [
                        'fr' => $sub->get_label('fr'),
                        'en' => $sub->get_label('en'),
                        'de' => $sub->get_label('de'),
                        'nl' => $sub->get_label('nl'),
                      ],
                    ];
                    $options = $sub->getOptions();
                    foreach ($options as $option) {
                        $opt[$option->getName()] = $option->getValue();
                    }
                    $data['options'] = $opt;
                    $ret[$subGroup->getName()][$sub->get_name()] = $data;
                }
            }
        }

        return $ret;
    }
1301063
private function getSharedForUser(User $user, array $shared)
    {
        $userLink = null;
        foreach ($shared as $shareLink) {
            if ($shareLink->getUser() === $user) {
                $userLink = $shareLink;
                break;
            }
        }

        return $userLink;
    }
326379
public function getAllPermissionsForUser($user)
    {
        $user = $this->resolveUser($user);

        if ( ! $user) {
            return [];
        }

        $permissions = [];

        // Get all permissions for the roles this user belongs to
        foreach ($user->getRoles() as $role) {
            /** @var EloquentRole $role */
            $permissions = array_merge(
                $permissions,
                array_keys(array_filter($role->getPermissions()))
            );
        }

        // Add permissions set specifically for the user
        $permissions = array_merge(
            $permissions,
            array_keys(array_filter($user->getPermissions()))
        );

        sort($permissions);

        return array_unique($permissions);
    }
864645
protected function getContent($contentTypeSlug, array $contentParameters, ListingOptions $options)
    {
        $contentParameters = array_filter($contentParameters);
        $records = $this->query->getContent($contentTypeSlug, $contentParameters);
        if ($records === null && $options->getPage() !== null) {
            $contentParameters['page'] = $options->getPreviousPage();
            $records = $this->query->getContent($contentTypeSlug, $contentParameters);
        }
        $this->runPagerQueries($records);
        if ($options->getGroupSort() && !$options->getOrder()) {
            $records = $this->runGroupSort($records);
        }

        return $records;
    }
307196
private function getPermissionList($baseDn, $userFilter)
    {
        if (null === $this->permissionAttribute) {
            return [];
        }

        $ldapEntries = $this->ldapClient->search(
            $baseDn,
            $userFilter,
            [$this->permissionAttribute]
        );

        if (0 === $ldapEntries['count']) {
            // user does not exist
            return [];
        }

        return self::extractPermission($ldapEntries, $this->permissionAttribute);
    }
647695
private function computePermissions($actions, $user, $node)
    {
        if (isset($node['attributes']['data-uri'])) {
            if($node['type'] == 'class'){
                $params = array('classUri' => $node['attributes']['data-uri']);
            } else {
                $params = array();
                foreach ($node['attributes'] as $key => $value) {
                    if (substr($key, 0, strlen('data-')) == 'data-') {
                        $params[substr($key, strlen('data-'))] = $value;
                    }
                }
            }
            $params['id'] = $node['attributes']['data-uri'];

            $node['permissions'] = $this->getActionService()->computePermissions($actions, $user, $params);
        }
        if (isset($node['children'])) {
            foreach($node['children'] as $index => $child){
                $node['children'][$index] = $this->computePermissions($actions, $user, $child);
            }
        }
        return $node;
    }
1242591
public function getUserPermissions()
    {
        $permissions = $this->getPermissions();

        if (!$this->isOwner()) {
            foreach (self::$ownerPermissions as $permission) {
                $key = array_search($permission, $permissions, true);
                if (false !== $key) {
                    unset($permissions[$key]);
                }
            }
        }

        return $permissions;
    }
981395
private function getUserObjectPermissionByArray($permissions, UserInterface $user)
    {
        if (empty($permissions)) {
            return [];
        }

        $userPermission = [];
        $roles = $user->getRoleObjects();
        foreach ($roles as $role) {
            $roleId = $role->getId();
            if (!isset($permissions[$roleId])) {
                continue;
            }

            $userPermission = $this->cumulatePermissions($userPermission, $permissions[$roleId]);
        }

        return $userPermission;
    }
700629
public function access($user)
    {
        $user = User::findOrFail($user->id);

        return $user->hasPermission('laralum::users.access') || $user->superAdmin();
    }
11200
protected static function getSecurityIdentityForAllOrganizations(UserInterface $user, $roleHierarchy = null)
    {
        $sids = [];

        if ($user instanceof UserOrganizationUsersInterface) {
            foreach ($user->getUserOrganizations() as $userOrg) {
                $sids[] = self::fromAccount($userOrg->getOrganization());
                $sids = array_merge($sids, static::getOrganizationGroups($userOrg));
                $roles = static::getOrganizationUserRoles($userOrg, $roleHierarchy);

                foreach ($roles as $role) {
                    $sids[] = RoleSecurityIdentity::fromAccount($role);
                }
            }
        }

        return $sids;
    }
1238953
private function getPermissionTable(User $user) {
		$userId = $user->getId();
		if ($this->permissionTable->has($userId)) {
			return $this->permissionTable->get($userId);
		}

		// always allow what guests can do
		$guestGroup = GroupQuery::create()->findOneByIsGuest(true);

		// collect groups from user
		$groups = GroupQuery::create()->filterByUser($user)->find();
		$userGroup = GroupQuery::create()->filterByOwnerId(($userId))->findOne();
		if ($userGroup) {
			$groups[] = $userGroup;
		}
		$groups[] = $guestGroup;

		// ... structure them
		$permissionTable = new Set();
		foreach ($groups as $group) {
			foreach ($group->getActions() as $action) {
				$permissionTable->add($action->getId());
			}
		}

		$this->permissionTable->set($userId, $permissionTable);

		return $this->permissionTable->get($userId);
	}
924748
public function hasAccess(array $url, array $user): bool
    {
        $result = parent::hasAccess($url, $user);
        if (!$result) {
            return false;
        }
        //  permissions are assigned to the specified entity only!
        if (empty($url['pass'][0])) {
            return false;
        }

        $table = TableRegistry::get('RolesCapabilities.Capabilities');
        Assert::isInstanceOf($table, CapabilitiesTable::class);

        $groups = $table->getUserGroups($user['id']);
        $query = TableRegistry::get('RolesCapabilities.Permissions')
            ->find('all')
            ->select('foreign_key')
            ->where([
                'model' => $url['controller'],
                'type IN ' => $url['action'],
                'foreign_key' => $url['pass'][0],
                'OR' => [
                    [
                        'owner_foreign_key IN ' => array_keys($groups),
                        'owner_model' => 'Groups',
                    ],
                    [
                        'owner_foreign_key' => $user['id'],
                        'owner_model' => 'Users',
                    ]
                ]
            ])
            ->applyOptions(['accessCheck' => false]);

        return $query->count() > 0 ? true : false;
    }
29080
private function getPermissionTypes()
    {
        $types = [];

        /**
         * @var $route \Symfony\Component\Routing\Route
         */
        foreach ($this->get('router')->getRouteCollection()->all() as $name => $route) {
            if ($route->hasOption('require_admin_permission')) {
                list($permissionType,) = explode('.', $route->getOption('require_admin_permission'));
                $types[$permissionType] = [
                    'id'   => $permissionType,
                    'name' => $permissionType
                ];
            }
        }

        ksort($types);

        return array_values($types);
    }
536353
public function grantAccessByPermissions($permissions, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser;
        return count(array_diff($permissions, $this->gatherPermissions($user))) === 0;
    }
897225
public static function getRequiredPermissions()
    {
        $class = get_called_class();
        // If the user is accessing LeftAndMain directly, only generic permissions are required.
        if ($class === self::class) {
            return 'CMS_ACCESS';
        }
        $code = Config::inst()->get($class, 'required_permission_codes');
        if ($code === false) {
            return false;
        }
        if ($code) {
            return $code;
        }
        return 'CMS_ACCESS_' . $class;
    }