Index: modules/devel/devel.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/devel/devel.module,v retrieving revision 1.106.4.48 diff -u -p -r1.106.4.48 devel.module --- modules/devel/devel.module 1 May 2007 15:47:43 -0000 1.106.4.48 +++ modules/devel/devel.module 16 May 2007 23:35:21 -0000 @@ -262,13 +262,38 @@ function devel_block($op = 'list', $delt case 0: $block['subject'] = t('switch user'); if (user_access('switch users')) { - $users = db_query_range('SELECT uid, name FROM {users} WHERE uid > 0 ORDER BY access DESC', 0, 10); - while ($account = db_fetch_object($users)) { - $dest = drupal_get_destination(); - $links[] = l(check_plain($account->name), 'devel/switch/'. $account->name, array(), $dest); + $dest = drupal_get_destination(); + $roles = user_roles(1, 'switch users'); + global $user; + $current_uid = $user->uid; + $can_switch_uids = array(); + $links = array(); + if (count($roles)) { + // Figure out all the users that can switch. + $can_switch_uids[1] = 1; // superuser can do anything. + $users = db_query('SELECT uid FROM {users_roles} WHERE uid > 1 AND rid IN ('. implode(',', array_keys($roles)) .') ORDER BY uid'); + while ($uid = db_fetch_object($users)) { + $can_switch_uids[$uid->uid] = $uid->uid; + } + // We never want to present the current user as an option. + unset($can_switch_uids[$current_uid]); + // Initially populate our list with the users that can switch. + $users = db_query_range('SELECT uid, name FROM {users} WHERE uid IN ('. implode(',', $can_switch_uids) .') ORDER BY access DESC', 0, 10); + while ($obj = db_fetch_object($users)) { + $links[] = l($obj->name .'*', 'devel/switch/'. $obj->name, array(), $dest); + } + } + if (count($links) < 10) { + // If we don't have enough, add distinct uids until we hit 10. + $users = db_query_range('SELECT uid, name FROM {users} WHERE uid != %d ORDER BY access DESC', $current_uid, 0, 10); + while (($obj = db_fetch_object($users)) && count($links) < 10) { + if (!in_array($obj->uid, $can_switch_uids)) { + $links[] = l($obj->name, 'devel/switch/'. $obj->name, array(), $dest); + } + } } } - if ($links) { + if (!empty($links)) { $block['content'] = theme('item_list', $links); $block['content'] .= drupal_get_form('devel_switch_user_form'); }