usernode: create view, filter by Role displays no "authenticated user"

jillelaine - November 26, 2006 - 00:07
Project:Usernode
Version:4.7.x-1.x-dev
Component:User interface
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs work
Description

now that i have the usernode module installed, i would like to create a view (using the views.module) to display lists of users...with an exposed filter to filter users by role.

the view works correctly except when i filter by "authenticated user": this list shows no authenticated users athough there are many users with that role.

the usernode Role filter apparently uses the users_roles table to determine the role of the user. unfortunately, the users_roles table does not contain role listings for any authenticated users (which would be rid 2). apparently this is by design? see http://drupal.org/node/80707

as a workaround, with the exposed usernode Role filter, i can select 'Is none of' and then select all the other roles, so that the view will display only those users with no role assigned in the users_roles table.

drupal 4.7.4
mysql 4.0x

#1

fago - November 28, 2006 - 10:31

yep, this problem is a general views problem..
I tried to fix it however it got not committed yet. I'll reroll it as soon as I've the time.

#2

Darren Oh - March 28, 2007 - 19:31

This has been fixed in views, but usernode still has the problem.

#3

deekayen - February 5, 2008 - 16:50
Status:active» needs review

I'm guessing this is a major contributor or is the cause of this bug:

  $tables['usernode_role'] = array(
    'name' => 'role',
    'provider' => 'internal', // won't show up in external list.
    'join' => array(
      'left' => array(
        'table' => 'usernode_users_roles',
        'field' => 'rid'
      ),
      'right' => array(
        'field' => 'rid'
      ),
    ),
  );

I'm not really sure at this point what a good alternative or addition would be, so my solution was to actually make something for it to join on instead of adding programmatical logic. There is no authenticated user entry ever made in the users_roles table when a user is inserted, so the join fails on that role every time. In user.module, anonymous and authenticated are specifically not inserted into the users_roles table (line 192 in my 4.7.x version).

      if (!in_array($rid, array(DRUPAL_ANONYMOUS_RID, DRUPAL_AUTHENTICATED_RID))) {
        db_query('INSERT INTO {users_roles} (uid, rid) VALUES (%d, %d)', $array['uid'], $rid);
      }

As a workaround, I executed this at a SQL command line (no coding necessary, but see patch for an update function). While I know some subselects in MySQL weren't supported in MySQL 4.1, http://dev.mysql.com/doc/refman/4.1/en/insert-select.html says this one is (I tested in 5.1).:

INSERT INTO users_roles (uid, rid) SELECT uid, '2' FROM users;

Then for future new users, add:

db_query("REPLACE INTO {users_roles} (uid, rid) VALUES (%d, %d)", $user->uid, DRUPAL_AUTHENTICATED_RID);

It's not necessary to clean up authenticated inserts in usernode on user deletion, because user_confirm_delete_submit() broadly handles that for us. The only downside I can think of regarding this solution is a larger users_roles table.

AttachmentSize
usernode-diff-2008-02-05-11-49-09.patch 1.96 KB

#4

simonhearn - May 30, 2008 - 10:45
Priority:minor» normal

I'm having this problem too. I tried the patch file above but it seems to be applying to a different version as the patch process failed.
Seeing as though this prevents me from creating user lists - one of the key benefits of this module - I'm upgraping this to normal priority. Has anyone addressed this issue in newer versions of the module (5.x-1.3)?

Many thanks,

Simon

#5

fago - June 10, 2008 - 11:11
Status:needs review» won't fix

I won't suggest anyone who just installs usernode to fiddle around in the user roles table.

#6

deekayen - June 10, 2008 - 14:47
Status:won't fix» needs work

Fine, you don't like that solution, but won't fixing doesn't fix the problem.

#7

fago - June 11, 2008 - 09:43

right, sry.

 
 

Drupal is a registered trademark of Dries Buytaert.