/*
get the roles assigned to a group, or to the users default group
489385
public function get_roles($group = null)
	{
		// When group is empty, attempt to get groups from a current login
		if ($group === null)
		{
			if ($login = \Auth::instance()
				and is_array($groups = $login->get_groups())
				and isset($groups[0][1]))
			{
				$group = $groups[0][1];
			}
		}

		// if it's a group id, find the corresponding object
		elseif (is_numeric($group) and isset(static::$_valid_groups[$group]))
		{
			$group = static::$_valid_groups[$group];
		}

		// if the group was found, return the roles
		if ($group instanceOf Model\Auth_Group)
		{
			return $group->roles;
		}
		else
		{
			// no group found, so no roles either
			return array();
		}
	}
137430
def get_roles(username):
    '''
    
    '''
    info = sendline('show user-account {0}'.format(username))
    roles = re.search(r'^\s*roles:(.*)$', info, re.MULTILINE)
    if roles:
        roles = roles.group(1).strip().split(' ')
    else:
        roles = []
    return roles
373819
public function getRoles()
    {
        $roles = $this->roles;

        foreach ($this->getGroups() as $group) {
            /** @noinspection SlowArrayOperationsInLoopInspection */
            $roles = array_merge($roles, $group->getRoles());
        }

        // we need to make sure to have at least one role
        $roles[] = static::ROLE_DEFAULT;

        return array_unique($roles);
    }
252468
def get_default_group(user):
    '''
    
    '''
    return grp.getgrgid(pwd.getpwnam(user).pw_gid).gr_name \
        if HAS_GRP and HAS_PWD \
        else None
240979
@RunAsSystem
  public Group getGroup(String groupName) {
    Fetch roleFetch = new Fetch().field(RoleMetadata.NAME).field(RoleMetadata.LABEL);
    Fetch fetch =
        new Fetch()
            .field(GroupMetadata.ROLES, roleFetch)
            .field(GroupMetadata.NAME)
            .field(GroupMetadata.LABEL)
            .field(GroupMetadata.DESCRIPTION)
            .field(GroupMetadata.ID)
            .field(GroupMetadata.PUBLIC)
            .field(GroupMetadata.ROOT_PACKAGE);

    Group group =
        dataService
            .query(GroupMetadata.GROUP, Group.class)
            .eq(GroupMetadata.NAME, groupName)
            .fetch(fetch)
            .findOne();
    if (group == null) {
      throw new UnknownEntityException(
          groupMetadata, groupMetadata.getAttribute(GroupMetadata.NAME), groupName);
    }
    return group;
  }
987611
def get_roles(server_context, container_path=None):
    
    url = server_context.build_url(security_controller, 'getRoles.api', container_path=container_path)
    return server_context.make_request(url, None)
1215485
public CmsPermissionSetCustom getPermissions(CmsUser user, List<CmsGroup> groups, List<CmsRole> roles) {

        CmsPermissionSetCustom sum = new CmsPermissionSetCustom();
        boolean hasPermissions = false;
        CmsPermissionSet p = m_permissions.get(user.getId());
        if (p != null) {
            sum.addPermissions(p);
            hasPermissions = true;
        }
        if (groups != null) {
            int size = groups.size();
            for (int i = 0; i < size; i++) {
                I_CmsPrincipal principal = groups.get(i);
                p = m_permissions.get(principal.getId());
                if (p != null) {
                    sum.addPermissions(p);
                    hasPermissions = true;
                }
            }
        }
        if (roles != null) {
            int size = roles.size();
            for (int i = 0; i < size; i++) {
                CmsRole role = roles.get(i);
                p = m_permissions.get(role.getId());
                if (p != null) {
                    sum.addPermissions(p);
                    hasPermissions = true;
                }
            }
        }
        if (!hasPermissions) {
            // if no applicable entry is found check the 'all others' entry
            p = m_permissions.get(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID);
            if (p != null) {
                sum.addPermissions(p);
            }
        }
        return sum;
    }
735991
public function getGroupsRoles(array $userGroups = []): array
    {
        $key = implode('.', $userGroups);

        if (!empty($this->_groupsRoles[$key])) {
            return $this->_groupsRoles[$key];
        }

        $result = [];

        if (!empty($userGroups)) {
            $query = $this->Roles->find('list', [
                'keyField' => 'id',
                'valueField' => 'name'
            ]);
            $query->matching('Groups', function ($q) use ($userGroups) {
                return $q->where(['Groups.id IN' => array_keys($userGroups)])->applyOptions(['accessCheck' => false]);
            });
            $result = $query->toArray();
        }

        $this->_groupsRoles[$key] = $result;

        return $this->_groupsRoles[$key];
    }
273755
public function getRole()
	{
		if ($this->_user === NULL) {
			$this->_initUser();
		}

		if ($this->_user->getRole()) {
			return $this->_user->getRole();
		}

		return Acl::DEFAULT_ROLE;
	}
843861
public function findUsersByRolesIncludingGroups(
        array $roles,
        $executeQuery = true
    )
    {
        $dql = "
            SELECT u, r1, g, r2, ws
            From Claroline\CoreBundle\Entity\User u
            LEFT JOIN u.roles r1
            LEFT JOIN u.personalWorkspace ws
            LEFT JOIN u.groups g
            LEFT JOIN g.roles r2
            WHERE (r1 in (:roles)
            OR r2 in (:roles))
            AND u.isEnabled = true
            ORDER BY u.lastName, u.firstName ASC";

        $query = $this->_em->createQuery($dql);
        $query->setParameter('roles', $roles);

        return ($executeQuery) ? $query->getResult() : $query;
    }
1181594
function(session) {
        if (session && session.user) {
            if (session.user.roles)
                return { roles: session.user.roles };
            return { roles: "user" };
        }
        return { roles: "public" };
    }
142940
def default_roles(*role_list):
    """"""
    def selectively_attach(func):
        """Only decorate if nothing specified on command line"""
        # pylint: disable=W0142
        if not env.roles and not env.hosts:
            return roles(*role_list)(func)
        else:
            if env.hosts:
                func = hosts(*env.hosts)(func)
            if env.roles:
                func = roles(*env.roles)(func)
            return func
    return selectively_attach
630973
function getAllRoles($force = false)
    {
        if ($force == false and ! is_null($this->_cache_perms)) {
            return $this->_cache_perms;
        }
        $this->_cache_perms = array();
        if ($this->isAnonymous()) {
            return $this->_cache_perms;
        }
        // load user permissions
        $this->_cache_perms = (array) $this->get_roles_list();

        // Load groups
        $groups = $this->get_groups_list();
        $ids = array();
        foreach ($groups as $group) {
            $ids[] = $group->id;
        }
        // load groups permisson
        if (count($ids) > 0) {
            $this->loadGroupRoles($ids);
        }
        return $this->_cache_perms;
    }
1292534
public function unassignRoleFromUserGroup($groupPath, $roleId)
    {
        $groupLocationParts = explode('/', $groupPath);
        $groupLocation = $this->locationService->loadLocation(array_pop($groupLocationParts));
        $userGroup = $this->userService->loadUserGroup($groupLocation->contentId);

        $role = $this->roleService->loadRole($roleId);
        $this->roleService->unassignRoleFromUserGroup($role, $userGroup);

        $roleAssignments = $this->roleService->getRoleAssignmentsForUserGroup($userGroup);

        return new Values\RoleAssignmentList($roleAssignments, $groupPath, true);
    }
1144814
def is_group_manager(user, group=None):
    """"""
    roles = get_user_roles(user)
    return any(x[1] == TenantRole.ROLE_GROUP_MANAGER and (not group or x[0] == group) for x in roles)
783588
def groups_roles(self, room_id=None, room_name=None, **kwargs):
        """"""
        if room_id:
            return self.__call_api_get('groups.roles', roomId=room_id, kwargs=kwargs)
        elif room_name:
            return self.__call_api_get('groups.roles', roomName=room_name, kwargs=kwargs)
        else:
            raise RocketMissingParamException('roomId or room_name required')
1354215
protected function getUserRoles()
    {
        if (!$this->auth->guest()) {
            return $this->auth->roles();
        }


        return $this->roles->has('guest') ? ['guest'] : [];
    }