Version:

Drupal 6.0 HEAD snapshot updated: June 5, 2007 - 17:03

Steps to reproduce:

  1. Apply 'Role A' and 'Role B' to a user
  2. Filter by 'Role A'
  3. Refine by 'Role B'

Result:

No users in the user list.

Expected Result:

The user with both 'Role A' and 'Role B' in the user list.

Fix?

I tried a few variations of the SQL statement causing the problem (user.module 2157), but I couldn't find a query that would grab both roles and return that user. Good luck :)

Comments

fwalch’s picture

Here's an example for a SQL statement that works:
SELECT DISTINCT u.uid, u.name, u.status, u.created, u.access FROM users u LEFT JOIN users_roles ur ON u.uid = ur.uid WHERE u.uid != 0 AND ur.rid = 4 AND ur.uid IN (SELECT uid FROM users_roles WHERE rid=5) ORDER BY u.created DESC LIMIT 0, 50
However, I'm not sure if this is really the easiest query possible.

chx’s picture

Status: Active » Needs review
StatusFileSize
new4.72 KB

Just multiply the ur table by itself as many times as it is needed.

chx’s picture

StatusFileSize
new1.43 KB

Debug...

jonathan_hunt’s picture

This issue occurs on 5.7 also

jonathan_hunt’s picture

The following code fixes it for me on 5.7

Index: modules/user/user.module
===================================================================
--- modules/user/user.module	(revision 8139)
+++ modules/user/user.module	(working copy)
@@ -2492,8 +2492,9 @@
   unset($roles[DRUPAL_AUTHENTICATED_RID]); // Don't list authorized role.
   if (count($roles)) {
     $filters['role'] = array('title' => t('role'),
-                         'where' => "ur.rid = %d",
+                         'where' => 'ur$index.rid = %d',
                          'options' => $roles,
+                         'join' => 'INNER JOIN {users_roles} ur$index ON ur$index.uid = u.uid',
                        );
   }
 
@@ -2529,7 +2530,7 @@
 
   // Build query
   $where = $args = $join = array();
-  foreach ($_SESSION['user_overview_filter'] as $filter) {
+  foreach ($_SESSION['user_overview_filter'] as $index => $filter) {
     list($key, $value) = $filter;
     // This checks to see if this permission filter is an enabled permission for the authenticated role.
     // If so, then all users would be listed, and we can skip adding it to the filter query.
@@ -2541,9 +2542,9 @@
         continue;
       }
     }
-    $where[] = $filters[$key]['where'];
+    $where[] = str_replace('$index', $index, $filters[$key]['where']);
     $args[] = $value;
-    $join[] = $filters[$key]['join'];
+    $join[] = str_replace('$index', $index, $filters[$key]['join']);
   }
   $where = count($where) ? 'AND '. implode(' AND ', $where) : '';
   $join = count($join) ? ' '. implode(' ', array_unique($join)) : '';

dpearcefl’s picture

Status: Needs review » Postponed (maintainer needs more info)

Does this issue exist in current D6?

dpearcefl’s picture

Status: Postponed (maintainer needs more info) » Needs work

We want your patch if it is still needed. Please resubmit it with a proper filename.

http://drupal.org/node/1054616
[description]-[issue-number]-[comment-number].patch

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.