query assigned roles
555473
def roles
      Roles.new(self, self.class.valid_roles.reject { |r| ((self.send(self.class.roles_attribute_name) || 0) & 2**self.class.valid_roles.index(r)).zero? })
    end
163175
def role_list(profile=None, **connection_args):
    '''
    
    '''
    kstone = auth(profile, **connection_args)
    ret = {}
    for role in kstone.roles.list():
        ret[role.name] = dict((value, getattr(role, value)) for value in dir(role)
                              if not value.startswith('_') and
                              isinstance(getattr(role, value), (six.string_types, dict, bool)))
    return ret
1086975
public function constrainWhereIsAll($query, $role)
    {
        $roles = array_slice(func_get_args(), 1);

        return $query->whereHas('roles', function ($query) use ($roles) {
            $query->whereIn('name', $roles);
        }, '=', count($roles));
    }
1211335
function (roles) {
              return Role.count({
                where: {
                  code: {
                    $in: roles
                  },
                  ownerId: req[options.auth.model].id
                }
              }).then(function (data) {
                return data == roles.length
              }).catch(function (err) {
                res.database(err)
              });
            }
1136043
def get_role_members(self, role):
        """"""
        targetRoleDb = AuthGroup.objects(creator=self.client, role=role)
        members = AuthMembership.objects(groups__in=targetRoleDb).only('user')
        return json.loads(members.to_json())
100781
def get_queryset(self):
        ""
        qs = super().get_queryset()

        qs = qs.select_related('publication__series') \
                .prefetch_related('publication__roles__creator')

        return qs
1349856
def role_show(self, role_id, **kwargs):
        ""
        api_path = "/api/v2/roles/{role_id}"
        api_path = api_path.format(role_id=role_id)
        return self.call(api_path, **kwargs)
1272725
function roles($Permission, $OnlyIDs = true)
	{
		if (!is_numeric($Permission))
			$Permission = $this->returnId($Permission);

		if ($OnlyIDs)
		{
			$Res = Jf::sql ( "SELECT RoleID AS `ID` FROM
				{$this->tablePrefix()}rolepermissions WHERE PermissionID=? ORDER BY RoleID", $Permission );

			if (is_array ( $Res ))
			{
				$out = array ();
				foreach ( $Res as $R )
					$out [] = $R ['ID'];
				return $out;
			}
			else
				return null;
		} else {
		    return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}roles AS `TP`
    		    LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.RoleID=`TP`.ID)
    		    WHERE PermissionID=? ORDER BY TP.ID", $Permission );
		}
	}
865490
public function find_users($search) {
        global $DB;

        // Get list of allowed roles.
        $context = context_course::instance($this->courseid);
        if ($validroleids = groups_get_possible_roles($context)) {
            list($roleids, $roleparams) = $DB->get_in_or_equal($validroleids, SQL_PARAMS_NAMED, 'r');
        } else {
            $roleids = " = -1";
            $roleparams = array();
        }

        // We want to query both the current context and parent contexts.
        list($relatedctxsql, $relatedctxparams) =
            $DB->get_in_or_equal($context->get_parent_context_ids(true), SQL_PARAMS_NAMED, 'relatedctx');

        // Get the search condition.
        list($searchcondition, $searchparams) = $this->search_sql($search, 'u');

        // Build the SQL.
        list($enrolsql, $enrolparams) = get_enrolled_sql($context);
        $fields = "SELECT r.id AS roleid, u.id AS userid,
                          " . $this->required_fields_sql('u') . ",
                          (SELECT count(igm.groupid)
                             FROM {groups_members} igm
                             JOIN {groups} ig ON igm.groupid = ig.id
                            WHERE igm.userid = u.id AND ig.courseid = :courseid) AS numgroups";
        $sql = "   FROM {user} u
                   JOIN ($enrolsql) e ON e.id = u.id
              LEFT JOIN {role_assignments} ra ON (ra.userid = u.id AND ra.contextid $relatedctxsql AND ra.roleid $roleids)
              LEFT JOIN {role} r ON r.id = ra.roleid
              LEFT JOIN {groups_members} gm ON (gm.userid = u.id AND gm.groupid = :groupid)
                  WHERE u.deleted = 0
                        AND gm.id IS NULL
                        AND $searchcondition";

        list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext);
        $orderby = ' ORDER BY ' . $sort;

        $params = array_merge($searchparams, $roleparams, $enrolparams, $relatedctxparams);
        $params['courseid'] = $this->courseid;
        $params['groupid']  = $this->groupid;

        if (!$this->is_validating()) {
            $potentialmemberscount = $DB->count_records_sql("SELECT COUNT(DISTINCT u.id) $sql", $params);
            if ($potentialmemberscount > $this->maxusersperpage) {
                return $this->too_many_results($search, $potentialmemberscount);
            }
        }

        $rs = $DB->get_recordset_sql("$fields $sql $orderby", array_merge($params, $sortparams));
        $roles = groups_calculate_role_people($rs, $context);

        // Don't hold onto user IDs if we're doing validation.
        if (empty($this->validatinguserids) ) {
            if ($roles) {
                foreach ($roles as $k => $v) {
                    if ($v) {
                        foreach ($v->users as $uid => $userobject) {
                            $this->potentialmembersids[] = $uid;
                        }
                    }
                }
            }
        }

        return $this->convert_array_format($roles, $search);
    }
539078
def define_dynamic_queries(roles)
      dynamic_module = Module.new do
        roles.each do |role|
          ["#{role}?".to_sym, "is_#{role}?".to_sym].each do |method|
            define_method(method) { is? role }
          end
        end
      end
      include dynamic_module
    end
1184991
function getRoles (session) {
    // return roles from session or default
    return session && Array.isArray(session.roles)
        ? session.roles
        // default roles
        : ['all', (session && session.accountId ? 'authenticated' : 'anonymous')]
}
1051004
def for_role(*roles)
      sql = with_role_sql(roles) || ''
      sql += ' OR ' if sql.present?
      sql += "(#{self.table_name}.roles_mask = 0) OR (#{self.table_name}.roles_mask IS NULL)"
      where(sql)
    end
819078
def role_list(auth=None, **kwargs):
    '''
    
    '''
    cloud = get_operator_cloud(auth)
    kwargs = _clean_kwargs(**kwargs)
    return cloud.list_roles(**kwargs)
853287
function getRole(user) {
      user = user || getCurrentUser();
      return _.find(userRoles, {role: user.role});
    }
221898
def get_roles(self):
        '''
        
        '''
        roles = {}
        paths = self.get_roles_paths()

        for path in paths:
            for entry in os.listdir(path):
                rolepath = os.path.join(path, entry)
                if os.path.isdir(rolepath):
                    roles[entry] = rolepath

        return roles
412745
function findRoles(identifiers) {
  return loadRoles()
  .then((roles) => {
    return _.filter(roles, (role) => { return identifiers.indexOf(role.name) !== -1; });
  });
}
784195
def get(method, hmc, uri, uri_parms, logon_required):
        """"""
        query_str = uri_parms[0]
        try:
            console = hmc.consoles.lookup_by_oid(None)
        except KeyError:
            raise InvalidResourceError(method, uri)
        result_user_roles = []
        filter_args = parse_query_parms(method, uri, query_str)
        for user_role in console.user_roles.list(filter_args):
            result_user_role = {}
            for prop in user_role.properties:
                if prop in ('object-uri', 'name', 'type'):
                    result_user_role[prop] = user_role.properties[prop]
            result_user_roles.append(result_user_role)
        return {'user-roles': result_user_roles}