Get the organization roles of user.

@param OrganizationUserInterface   $user          The organization user
@param null|RoleHierarchyInterface $roleHierarchy The role hierarchy

@return string[]
775699
protected static function getOrganizationUserRoles(OrganizationUserInterface $user, $roleHierarchy = null)
    {
        $roles = [];

        if ($user instanceof RoleableInterface && $user instanceof OrganizationUserInterface) {
            $org = $user->getOrganization();
            $roles = self::buildOrganizationUserRoles($roles, $user, $org->getName());
            $roles = self::buildOrganizationRoles($roles, $org);

            if ($roleHierarchy instanceof RoleHierarchyInterface) {
                $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles));
            }
        }

        return $roles;
    }
1158934
public function grantAccessByRole($role, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();
        return in_array($role, $user->getRoles());
    }
1039895
public function findWorkspaceRolesForUser(User $user, Workspace $workspace)
    {
        $dql = "
            SELECT r FROM Claroline\CoreBundle\Entity\Role r
            JOIN r.workspace ws
            JOIN r.users user
            WHERE ws.guid = '{$workspace->getGuid()}'
            AND r.name != 'ROLE_ADMIN'
            AND user.id = {$user->getId()}
        ";

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

        return $query->getResult();
    }
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;
    }
1055231
public function userPendingItems(Member $user)
    {
        // Don't restrict anything for ADMIN users
        $userInstances = DataList::create(WorkflowInstance::class)
            ->where('"WorkflowStatus" != \'Complete\'')
            ->sort('LastEdited DESC');

        if (Permission::checkMember($user, 'ADMIN')) {
            return $userInstances;
        }
        $instances = new ArrayList();
        foreach ($userInstances as $inst) {
            $instToArray = $inst->getAssignedMembers();
            if (!count($instToArray)>0 || !in_array($user->ID, $instToArray->column())) {
                continue;
            }
            $instances->push($inst);
        }

        return $instances;
    }
731210
protected function getUserThrottles(UserInterface $user)
    {
        $key = $user->getUserId();

        if (! array_key_exists($key, $this->userThrottles)) {
            $this->userThrottles[$key] = $this->loadUserThrottles($user);
        }

        return $this->userThrottles[$key];
    }
775616
protected function getAllRoles(User $user)
    {
        $roles = [
            'Neos.Flow:Everybody' => $this->policyService->getRole('Neos.Flow:Everybody'),
            'Neos.Flow:AuthenticatedUser' => $this->policyService->getRole('Neos.Flow:AuthenticatedUser')
        ];

        /** @var Account $account */
        foreach ($user->getAccounts() as $account) {
            $accountRoles = $account->getRoles();
            /** @var $currentRole Role */
            foreach ($accountRoles as $currentRole) {
                if (!in_array($currentRole, $roles)) {
                    $roles[$currentRole->getIdentifier()] = $currentRole;
                }
                /** @var $currentParentRole Role */
                foreach ($currentRole->getAllParentRoles() as $currentParentRole) {
                    if (!in_array($currentParentRole, $roles)) {
                        $roles[$currentParentRole->getIdentifier()] = $currentParentRole;
                    }
                }
            }
        }

        return $roles;
    }
296961
public function getRoles()
    {
        $roles = array();
        foreach ($this->groups as $group) {
            $roles[] = $group->getAsRole();
        }
        $roles[] = 'ROLE_USER';
        return $roles;
    }
180588
protected function buildContexts(RoleInterface $role)
    {
        $contexts = null;

        if ($role instanceof OrganizationalInterface) {
            $contexts = [null !== $role->getOrganization() ? PermissionContexts::ORGANIZATION_ROLE : PermissionContexts::ROLE];
        }

        return $contexts;
    }
957884
protected function getRoleSets()
    {
        return Util::getRoleSets($this->getUsername(), new String($this->lookupName), new String($this->rolesQuery), $this);
    }
624831
public function includeRoles(User $user)
    {
        $roles = $user->roles;
        return $this->collection($roles, new RoleTransformer());
    }
1254643
def get_user_roles(self, user):
        """"""
        memberShipRecords = AuthMembership.objects(creator=self.client, user=user).only('groups')
        results = []
        for each in memberShipRecords:
            for group in each.groups:
                results.append({'role':group.role})
        return results
689104
private function loadAllUserGroupsIdsOfUser(User $user): array
    {
        $allUserGroups = [];
        $offset = 0;

        do {
            $userGroups = $this->userService->loadUserGroupsOfUser($user, $offset, self::USER_GROUPS_LIMIT);
            foreach ($userGroups as $userGroup) {
                $allUserGroups[] = $userGroup->contentInfo->id;
            }
            $offset += self::USER_GROUPS_LIMIT;
        } while (\count($userGroups) === self::USER_GROUPS_LIMIT);

        return $allUserGroups;
    }
881987
protected function loadUserRolesViaManyToMany($user)
    {
        $roles = ['ROLE_USER'];
        if (is_string($this->userRoleIdentifier)) {
            foreach ($user->get($this->userRoleIdentifier) as $role) {
                $roles[] = $role['name'];
            }
        }
        return $roles;
    }
731195
protected static function getOrganizationRoles(OrganizationInterface $organization, $roleHierarchy = null)
    {
        $roles = [];

        if ($organization instanceof RoleableInterface && $organization instanceof OrganizationInterface) {
            $roles = self::buildOrganizationRoles([], $organization);

            if ($roleHierarchy instanceof RoleHierarchyInterface) {
                $roles = RoleUtil::formatNames($roleHierarchy->getReachableRoles($roles));
            }
        }

        return $roles;
    }
789259
public function getUserDashboards(array $user): QueryInterface
    {
        // get all dashboards
        $query = $this->find('all')->order('name');

        // return all dashboards if current user is superuser
        if (isset($user['is_superuser']) && $user['is_superuser']) {
            return $query;
        }

        $roles = [];
        /** @var \Groups\Model\Table\GroupsTable */
        $table = $this->Roles->Groups->getTarget();
        $groups = $table->getUserGroups($user['id']);
        // get group(s) roles
        if (!empty($groups)) {
            $roles = $this->Roles->Capabilities->getGroupsRoles($groups);
        }

        if (empty($roles)) {
            // get all dashboards not assigned to any role
            $query->where(['Dashboards.role_id IS NULL']);

            return $query;
        }

        // return all dashboards for Admins
        if (in_array(Configure::read('RolesCapabilities.Roles.Admin.name'), $roles)) {
            return $query;
        }

        // get role(s) dashboards
        $query->where(['OR' => [
            ['Dashboards.role_id IN' => array_keys($roles)],
            ['Dashboards.role_id IS NULL']
        ]]);

        return $query;
    }
942099
public function grantAccessByRoles($roles, UserInterface $user = null)
    {
        $user = $user ? : $this->currentUser();
        return count(array_diff($roles, $user->getRoles())) === 0;
    }