Problem/Motivation
Masquerade module uses role IDs to identify and store administrator roles. These admin roles are stored in variable masquerade_admin_roles. (The masquerade user roles are configured under Administer > Configuration > People > Masquerade.) The problem occurs when masquerade admin roles are exported to a feature and then enabled on another site. Role IDs may differ between different sites. Therefore, adding masquerade admin roles to a feature and deploying this feature on another site does not result in the same administrator roles settings.
Example:
SITE 1 has administer role settings:
[x] Manager (Role id =1)
[x] webmaster (Role id = 2)
[] editor (Role id = 3)
In this case 'masquerade_admin_roles' will be
Array( 1 => 1 , 2 => 2, 3 => 0 )
On SITE 2, which does not have the same role IDs. Applying the feature will give the following administer role settings:
[x] Director (Role id =1)
[x] Manager (Role id =2)
[] editor (Role id = 3)
[] webmaster (Role id = 4)
Proposed solution
This can be fixed by storing the role names instead of role IDs. So masquerade_admin_roles will be:
Array(0 => 'Manager', 1 => 'webmaster')
To reproduce:
- Create a new role with name 'test role'
- Set masquerade administrators
- Simulate a site where roles are different
- go back to masquerade admin interface admin/config/people/masquerade'
- go to admin/people/permissions/roles to create the new role
- go to admin/config/people/masquerade
- select role 'test role' and click 'Save configuration'
- go back to admin/people/permissions/roles to change roles
- edit role 'test role', rename it to 'test role (renamed)'
- create a new role called 'test role'
- you should be able to see the issue: 'test role (renamed)' is selected instead of 'test role', the role which was initially configured as masquerade administrator
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | masquerade-admin-role-names-2784103-9-D7.patch | 8.38 KB | karolinam |
Comments
Comment #2
karolinamHere is a patch which implements the proposed solution.
Comment #3
fengtanSuccessfully tested the patch.
Featurizing role names instead of role ID's would be really useful.
Comment #4
lambic commentedThis patch wasn't working quite right, here is a fixed version.
Comment #5
karolinamThanks for the fix. Reviewed and tested the patch. Works well.
I am adding a test to cover the case where it was failing.
Comment #6
andypostLooks mostly ready, the only worry here is a role names could be changed (renamed, translated) but there's no hooks to react on rolename change in the patch
if ($missing_ids) should be enough
are sure that values here are not translated?
++ here
this is unneded here, please remove
Comment #7
karolinamThank you for your feedback. I will make these changes.
Side note: Your comment #1 and 4 are debatable but I'll make these changes if you prefer.
Comment #8
andypostThey just need hooks to react on role changes, and I just remember core issue where role name could be translatable
Comment #9
karolinamHere is the patch with a hook for role changes and modification for translations.
Comment #10
izmeez commentedAdding patch in #9 to #3010095: Masquerade 7.x-1.0 stable release plan
Comment #11
ciss commentedI'd strongly advise against using role names as identifiers. Role names are supposed to be descriptive and can be changed at any given point. Additionally other modules (e.g. views) also rely on role IDs.
If you want to securely export anything role related, I highly recommend integrating the Role Export module into your setup, as it will use numerical hashes as role IDs.
It also seems that this patch would break existing features. At a minimum the change should be hidden behind a flag.
Comment #12
ciss commentedComment #13
ressaThanks for the suggestion. In an attempt to help the maintainers, I am going through some of the Drupal 7 issues, and closing them, since Drupal 7 is EOL.
Maintainers should grant credit for the great work to the relevant users, even if the patch did not get committed: https://www.drupal.org/docs/develop/issues/issue-procedures-and-etiquett....
Since Drupal 7 is EOL, we can probably close this issue, but feel free to re-open if this is still relevant, and we should consider looking at this for the Drupal 11 version?