Get the permissions for a list of resources.

@param User $user the user to check the permissions
@param array $resources the resources to get the permissions
@return array the available rights and the permissions per resource
345921
public function getResourcesPermissions(User $user, $resources)
    {
        $permissions = [];
        if(!is_null($user)){
            try {
                $permissionManager = $this->getServiceManager()->get(PermissionInterface::SERVICE_ID);
                $supportedRights   = $permissionManager->getSupportedRights();
                $permissions['supportedRights'] = $supportedRights;

                if(count($supportedRights) > 0){
                    $uris = $this->getUris($resources);

                    $permissions['data'] = $permissionManager->getPermissions($user, $uris);
                }
            } catch(\Exception $e){
                \common_Logger::w('Unable to retrieve permssions ' . $e->getMessage());
            }
        }
        return $permissions;

    }
534340
private function listUserAuthorizedCollections(User $user)
    {
        $acl = $this->getAclForUser($user);
        $rights = $acl->get_bas_rights();
        $bases = $acl->get_granted_base();

        $grants = [];

        $statusMapper = new RestrictedStatusExtractor($acl, $this->getApplicationBox());

        foreach ($bases as $base) {
            $baseGrants = [];

            foreach ($rights as $right) {
                if (!$acl->has_right_on_base($base->get_base_id(), $right)) {
                    continue;
                }

                $baseGrants[] = $right;
            }

            $grants[] = [
                'databox_id'    => $base->get_sbas_id(),
                'base_id'       => $base->get_base_id(),
                'collection_id' => $base->get_coll_id(),
                'name'          => $base->get_name(),
                'logo'          => $base->get_binary_minilogos() ? base64_encode($base->get_binary_minilogos()) : '',
                'labels'        => [
                    'fr' => $base->get_label('fr'),
                    'en' => $base->get_label('en'),
                    'de' => $base->get_label('de'),
                    'nl' => $base->get_label('nl'),
                ],
                'rights'        => $baseGrants,
                'statuses'      => $statusMapper->getRestrictedStatuses($base->get_base_id())
            ];
        }

        return $grants;
    }
536353
public function grantAccessByPermissions($permissions, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser;
        return count(array_diff($permissions, $this->gatherPermissions($user))) === 0;
    }
893789
public function userWorkspaceListAction(User $user, $page, $max)
    {
        $pager = $this->workspaceManager->getOpenableWorkspacesByRolesPager($user->getRoles(), $page, $max);

        return array('user' => $user, 'pager' => $pager, 'page' => $page, 'max' => $max);
    }
517891
public function getResourcePermissions(ResourceInterface $resource) : array
    {
        $query = $this->getRepository()->createQueryBuilder('r')
            ->select('r')
            ->where('r.resource_class = :resourceClass AND r.resource_id=:resourceId')
            ->setParameter('resourceClass', $resource->getClass())
            ->setParameter('resourceId', $resource->getId())
            ->getQuery();

        return $query->getResult();
    }
1098472
public function getRolesFor(User $user)
    {

        $userRoles = $user->roles()->get();

        $roles  = Role::where('order', '<=', $this->maxRole()->order);

        foreach ($userRoles as $role) {
            $roles = $roles->where('name', '!=', $role->name);
        }

        return $roles->get();
    }
578111
public function getPermissions(Subject $subject, Resource $resource = null, array $params = [])
    {
        $permissions = [];

        foreach ($this->getPermissionsForSubject($subject) as $permissionName => $permission) {
            if ($resource === null && $permission->hasRules()) {
                continue;
            }

            if ($resource !== null && !$this->evaluatePermission($permission, $subject, $resource, $params)) {
                continue;
            }

            $permissions[] = $permissionName;
        }

        return $permissions;
    }
217827
public function getGroups(User $user)
    {
        $groups = $user->getPropertyValues(self::PROPERTY_MEMBERS_URI);
        array_walk($groups, function(&$group) { $group = new core_kernel_classes_Resource($group);});
        return $groups;
    }
1283439
public function hasPrivileges(User $user, array $required) {
        foreach ($required as $resourceId=>$right) {
            if ($right === 'WRITE' && !$this->hasWritePrivilege($user, $resourceId)) {
                common_Logger::d('User \''.$user->getIdentifier().'\' does not have lock for resource \''.$resourceId.'\'');
                return false;
            }
            if (!in_array($right, $this->getPermissionProvider()->getSupportedRights())) {
                $required[$resourceId] = PermissionInterface::RIGHT_UNSUPPORTED;
            }
        }
        
        $permissions = $this->getPermissionProvider()->getPermissions($user, array_keys($required));
        foreach ($required as $id => $right) {
            if (!isset($permissions[$id]) || !in_array($right, $permissions[$id])) {
                common_Logger::d('User \''.$user->getIdentifier().'\' does not have \''.$right.'\' permission for resource \''.$id.'\'');
                return false;
            }
        }
        return true;
    }
853395
public function findUserList(User $user)
    {
        $dql = 'SELECT e FROM Phraseanet:UsrListEntry e
            WHERE e.user = :usr_id';

        $params = [
            'usr_id' => $user->getId(),
        ];

        $query = $this->_em->createQuery($dql);
        $query->setParameters($params);

        return $query->getResult();
    }
1221239
protected function gatherPermissions(UserInterface $user = null)
    {
        $user = $user ?: $this->currentUser();
        $roles = $user->getRoles();
        $permissions = $user->getPermissions();

        foreach ($roles as $role) {
            if (isset($this->roleDictionary[$role])) {
                $permissions = array_merge($permissions, $this->roleDictionary[$role]);
            }
        }

        return $permissions;
    }
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);
    }
624831
public function includeRoles(User $user)
    {
        $roles = $user->roles;
        return $this->collection($roles, new RoleTransformer());
    }
1258569
private static function userHasResource($resources)
    {
        if (!is_array($resources)) {
            $resources = [$resources];
        }

        $container = Container::getInstance();

        /** @var Rbac $rbac */
        $rbac = $container->get('rbac');

        /** @var Auth $auth */
        $auth = $container->get('auth');

        foreach($resources as $resource){
            foreach ($auth->getStorage()->read()['roles'] as $roleName) {
                if (true === $rbac->isGranted($roleName, $resource)) {
                    return true;
                }
            }
        }

        return false;
    }
905009
private function hasPermission(AuthenticatedUserInterface $user, string $uri) {

        // Collect permissions
        $permissions = $this->getParameterByKey("permissions");

        // Iterate over permission
        foreach ($permissions as $permissionPath => $acceptableRoles) {
            if($permissionPath[0] !== "/") {
                $permissionPath = "/".$permissionPath;
            }
            if(substr($permissionPath,-1) !== "/") {
                $permissionPath = $permissionPath."/";
            }
            $match = preg_match($permissionPath,$uri);
            if ($match == 1) {
                if(in_array(Role::ANON_USER,$acceptableRoles)) return true;
                foreach ($acceptableRoles as $permissionRole) {
                    if(in_array($permissionRole,$user->getRoles())) return true;
                }
                return false;
            }
        }
        return false;
    }
1270715
protected function validateRules($rules, User $user, array $restriction)
    {
        $return = array('validRules' => 0, 'rules' => array());

        if (0 < count($rules)) {
            foreach ($rules as $rule) {
                $rule->setUser($user);
                $checkedLogs = $this->validateRule($rule, $restriction);

                if (false !== $checkedLogs) {
                    $return['validRules']++;
                    $return['rules'][] = array(
                        'rule' => $rule, 'logs' => $checkedLogs
                    );
                }
            }
        }

        return $return;
    }
54428
public function all(User $user = null)
    {
        $query = Tag::query();

        return $this->scopeVisibleTo($query, $user)->get();
    }