Not sure if this is a bug - but...
I have 3 roles:
anonymous
authenticated
staff
Some of the users are members of the 'Staff' role, but also get the authenticated role as standard.
I've then assigned weights to the roles:
anonymous 0
authenticated -1
staff -5
So based on the usual way weights work - when I call $role = module_invoke('role', 'weights_get_highest', $user->roles); I should get back array(2) { ["rid"]=> int(3) ["name"]=> string(5) "staff" }
However I'm getting back array(2) { ["rid"]=> int(2) ["name"]=> string(18) "authenticated user" } - as if the weights are being treated the opposite way around to the rest of the Drupal system (lower weights float to the top of the list) ?
The problem (if it is a problem) is probably down to the way the highest role is found, "// run through $roles, returning FIRST role matched" - maybe the array needs to be ordered correctly so that negative weights are first?
I wish to use the module with path_access but this is causing a bit of a problem - unless I've mixed something up!
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | role_weights_reverse3.patch | 3.39 KB | pfaocle |
| #5 | role_weights_reverse2.patch | 1.65 KB | pfaocle |
| #4 | role_weights_reverse1.patch | 1.67 KB | pfaocle |
Comments
Comment #1
buddaA call to
array_reverse()might be the cure:Comment #2
pfaocleHmm - I think the behaviour is correct based on my original use for the module - the higher the weight, the more 'important' the role is. In your example, I would have set the weights something like:
anonymous 0
authenticated 1
staff 5
However, its a good point about weights elsewhere in Drupal: we should be consistent. Please feel free to comment further.
I've just got back from a week away so should get around to looking at the module's issue queue soon.
Comment #3
buddaYeah I can see where you were originally coming from with the weight setting, but keeping the site admin interface consistent with the user interface is important.
Comment #4
pfaocleOK, I think we should reverse them to be more in line with other Drupal weights. I'll roll a couple of patches for both the 4.7 and 5.x branches, then release a 1.1 version of each with this in.
Note that as well as a quick array_reverse() call, the patch now includes a different initial weight for the authenticated role and an update to essentially reverse any existing role weights stored, so the user doesn't have to re-shuffle them all around.
Test0r, plox.
Comment #5
pfaocleSilly me. arsort() -> asort() and lose the array_reverse call.
Comment #6
buddaNearly a year on from the original issue :)
Just patched role_weights.module but am still having the same issue.
Here's some test code:
And the output is:
Role id 5 "member" has a weight of -5, whilse role id 2 "authenticated user" has a weight of -1.
This confusion with the weights issue renders the module pretty useless at present, and breaks Path_Access from working fully too. Hopefully we can get to the bottom of this soon. Cheers.
Comment #7
buddaUpdate: it appears the patch words- however the database update messed up my existing role weights.
It changed my "member" role from weight -5 to +5, yet the "authenticated user" role stayed at -1
Either way - the patch works and is good to go IMO.
Comment #8
pfaocleThanks for testing. I tried to re-create your update problem and couldn't, I'm afraid: the simple update seemed to work fine. I'll be adding in a note to the project page/README.txt anyway regarding changing the 'highest' weight, so hopefully this'll reduce any confusion.
Before I commit this, i think the word 'highest' in the function name is the only ambiguous thing left - we're actually (in numerical terms) now returning the lowest weight, but what we're saying we're returning is the 'best', or 'most overriding' weight for a user's set of roles. Any suggestions for changing the function name? I really think 'highest' doesn't really make sense any more.
Comment #9
pfaocleOops, messed up that comment, Should've read:
"Before I commit this, i think the word 'highest' in the function name is the only ambiguous thing left - we're actually (in numerical terms) now returning the lowest weight, but what we're saying we're returning is the 'best', or 'most overriding' weight for a user's set of roles. Any suggestions for changing the function name? I really think 'highest' doesn't really make sense any more."
Comment #10
pfaocleFinally. Please update to 5.x-1.1!
Comment #11
pfaocleAnd the patch I committed.
Comment #12
(not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.