Closed (fixed)
Project:
Auto Assign Role
Version:
6.x-1.0-beta1
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
19 Nov 2007 at 13:16 UTC
Updated:
14 Jul 2012 at 19:28 UTC
Jump to comment: Most recent file
Comments
Comment #1
cyberswat commentedebeyrent: could you check to see if this issue has been resolved by http://drupal.org/cvs?commit=98222 ... I believe it has been. If not, could you identify the module you are using so I can test?
Comment #2
ebeyrent commentedI don't see where in this patch you are updating the reference to the user object. If you fail to modify the user object, the other modules with hook_user that get executed after your module will not be able to make decisions based on the auto-assigned role.
Case in point - you want your new users to be automatically assigned a badge for a specific role. So, when the new account is created, you auto-assign a role of 'Newbie', but when the User Badges module fires its hook_user, it's looking at $user->roles and the auto-assigned role is not there, because you did not modify the $user reference in your hook. Therefore, the badge for that role cannot be assigned to the user.
Does this make sense?
Comment #3
cyberswat commented"I believe it has been. If not, could you identify the module you are using so I can test?"
Comment #4
ebeyrent commentedDid you miss the part where I talked about the User Badges module??
To test:
1. Create new role "newbie"
2. Configure Auto Assign role to assign newbie to all new users
3. Configure User Badges module to assign badge to newbie role
4. Register a new user
The result I am seeing is that the new user does not get the badge.
Comment #5
cyberswat commentedI didn't miss anything .. I'm busy and do this as I can ... Please evaluate http://ftp.drupal.org/files/projects/autoassignrole-5.x-1.x-dev.tar.gz ... the original module has some very bad code in it that is no longer there. If this is still a problem I'll fix it but I don't have the time to approach this unless it is still an issue and I don't have the time resources to determine that myself ... so your help and understanding is appreciated considering I just took this project over to clean it up and provide you a solution that works.
Comment #6
cyberswat commentedAssuming this is closed.
Comment #7
ebeyrent commentedThis is not solved. You are still not modifying the $user object. You are updating the role in the database, which is great, but you also have to update $user.
After each role is inserted into the database, you have to:
// Add the auto-assigned role to the user object so that it can be accessed by other hooks
$user->roles[$role->rid] = $role->name;
You do this so that any other module that implements hook_user will have the updated user object without reloading it from the database.
To be more explicit, here is some code from user_badges.module:
This code executes at some point after your hook_user call on insert. If you dump the $user->roles array, you will not see the auto-assigned role. The reason you don't see the auto-assigned roles is because your code never updates the $user object that's in memory.
Does this make sense?
To fix the problem, I have attached a patch based off the code you instructed me to download.
Comment #8
introfini commentedHi,
There's something wrong with the $user object, because theme_username($user) isn't working when the user has just registered.
http://api.drupal.org/api/function/theme_username/5
Your patch didn't fix that issue, but I think you are on the right track…
introfini
Comment #9
lauscherli commentedI'm having the same problem; badges don't apply for roles created by the auto assign role module.
I just came across a similar discussion here http://drupal.org/node/161825.
There the badges didn't show up when a user was promoted to a new role by a userpoint module promote mechanism (don't know that module), and they seem to have found a fix. I don't know if these promoting-mechanism work similar, but maybe...
Would be nice to have the badges working together with auto assign module, anyway :-)
Comment #10
ebeyrent commentedlauscherli - that was my patch, and I can verify that it works as it's supposed to. My patch on this thread works as well. Feel free to try it and let me know if there are any issues...
Comment #11
lauscherli commentedJust tried it - but it didn't help the badges... But maybe it was my fault, as i'm not experienced in applying patches yet. I will give it a second try tomorrow :-) I'll let you know.
There's several patches around that i tried, they fix the automatic role assignment, but don't help the batches...
UPDATE: I tried out your patch a second time: The roles are getting assigned, but still the badges are not being assigned to the roles; in order that they show up i first need to resave the badget-roles... Just to inform you: I am NOT using LoginToboggan. I mention this, because others guess that it's a problem related to that module.
Comment #12
cyberswat commentedhttp://drupal.org/cvs?commit=135899
Comment #13
cyberswat commentedMake sure this is in place for D6
Comment #14
cyberswat commentedchanging status to active for D6
Comment #15
cyberswat commentedhttp://drupal.org/cvs?commit=137753
Comment #16
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.