Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
If you put a user in a group and assign some roles to them, then remove the user from the group. Now add the user back into the group and they will regain all the roles previously assigned. Obviously the role assignments are not being cleared when a user is removed from a group.
Comment | File | Size | Author |
---|---|---|---|
#13 | og_revokeroles.patch | 3.53 KB | sunwukong |
#11 | og_revokeroles.patch | 3.85 KB | sunwukong |
#9 | og_revokeroles.patch | 3.88 KB | sunwukong |
#7 | og.patch | 1.01 KB | sunwukong |
#5 | og-membership_delete_roles.patch | 930 bytes | sunwukong |
Comments
Comment #1
amitaibuCan you provide a patch + test?
Comment #2
sunwukong CreditAttribution: sunwukong commentedjzornig and I have developed this patch to remove roles when a user is removed from a group or deleted.
Comment #3
sunwukong CreditAttribution: sunwukong commentedComment #5
sunwukong CreditAttribution: sunwukong commentedtry again
Comment #7
sunwukong CreditAttribution: sunwukong commentedtry again
Comment #8
amitaibuStart with capital letter, and with dot.
Remove space.
Any chance for a test ? :)
Comment #9
sunwukong CreditAttribution: sunwukong commentedpatch + test
the original code causes 2 fails in testing, while the modified code pasts
Comment #10
amitaibuThanks.
Space missing after //
Why do we need this IF?
In the comments lets reference them as user1 and user2 (i.e. remove the $ prefix)
Please remove.
Since we have 2 roles, instead of foreach with IF, just write the 2 lines.
Instead of "so return value is..." maybe "role was removed"
Comment #11
sunwukong CreditAttribution: sunwukong commentedspace removed.
If some codes unset or empty these variables before og_og_membership_delete, we won't access database.
Changed.
Removed.
Because 'og_role_save' does not reture $rid, I have to call 'og_roles' to get all roles which include not only 'role1', 'role2', but also 'non-member', 'member', and 'administrator'. Do you know any better way to get $rid of role1 and role2?
Changed.
Anymore suggestions, just let me know. Thanks.
Comment #12
amitaibu> If some codes unset or empty these variables before og_og_membership_delete, we won't access database.
I can't think of such a behavior. I think we can remove that IF.
> Because 'og_role_save' does not reture $rid,
$role is an object passed by reference, so you actually have the RID inside $role1 and $role2 (you can debug($role1) to see it.
Comment #13
sunwukong CreditAttribution: sunwukong commented> If some codes unset or empty these variables before og_og_membership_delete, we won't access database.
I can't think of such a behavior. I think we can remove that IF.
------------------------------------
IF is already removed. But because og_og_membership_delete is a hook, I still think the case maybe happens because we can not foresee other modules' codes.
> Because 'og_role_save' does not reture $rid,
$role is an object passed by reference, so you actually have the RID inside $role1 and $role2 (you can debug($role1) to see it.
-------------------------------------
Yes, thank you. og role grant is changed to be two lines.
Comment #14
amitaibuThanks, I've cleaned code a bit and committed.
Comment #15
holtzermann17 CreditAttribution: holtzermann17 commentedI have the reverse problem: