How can I find list of users who belongs to certain role X?

I don't see any link for that in the admin page even though I enabled search module.

Thanks

Comments

pwolanin’s picture

I can't see anywhere that this functionaly is built in to the user module, though I agree it would be useful. I suggest filing a feature request (issue) against user.module.

One way to do this would be to add filtering by role to function user_admin_account() (creates the page at administer >> users), similar to the filtering by node type, status, etc. that one can do at administer >> content.

How many user roles do you have? For the moment, you could create custom pages with PHP for each user role.

---
Work: BioRAFT

venkat-rk’s picture

There is a userlists module that gives you tabs at admin>>users according to users by role. As far as i remember, it was cvs only, worked with 4.6 and has not been updated for 4.7

pwolanin’s picture

Here's a snippet that mostly reuses the code from function user_admin_account(). A quick check of it seems to work- paste into a page or story node with PHP input format. Let me know if it works for you.

<?php
//choose the role to list by value.  
// Note ID 1 = anonymous, ID 2 = authenticated user
// so valid values here are > 2.
$rid = 3;
?>

<h2>A list of all users with Role ID <?php print $rid?></h2>

<?php
$header = array(
  array('data' => t('Username'), 'field' => 'u.name'),
  array('data' => t('Status'), 'field' => 'u.status'),
  array('data' => t('Member for'), 'field' => 'u.created', 'sort' => 'desc'),
  array('data' => t('Last access'), 'field' => 'u.access'),
  t('Operations')
);
$sql = "SELECT u.uid, u.name, u.status, u.created, u.access FROM {users} u INNER JOIN {users_roles} ur ON u.uid=ur.uid WHERE ur.rid = $rid";
$sql .= tablesort_sql($header);
$result = pager_query($sql, 50);

$status = array(t('blocked'), t('active'));
while ($account = db_fetch_object($result)) {
  $rows[] = array(theme('username', $account),
		  $status[$account->status],
		  format_interval(time() - $account->created),
		  $account->access ? t('%time ago', array('%time' => format_interval(time() - $account->access))) : t('never'),
		  l(t('edit'), "user/$account->uid/edit", array()));
}

$output = theme('table', $header, $rows);
$output .= theme('pager', NULL, 50, 0);
print ($output);
?>

---
Work: BioRAFT

ksoonson’s picture

thanks very much. it works fine...