Problem/Motivation
Messages warning users that permissions may need to be rebuilt can be shown to users who cannot access the permission rebuild page. This may cause confusion and frustrations to users.
Steps to reproduce
- Create a "User admin" role
- Give the User admin the "administer users" permission
- As a user with the role of "User admin", update any user's roles
- After saving the user you should see the "Your changes have been saved. You may have to rebuild permissions for your changes to take effect." message
- Clicking on the link to rebuild permissions gives you a 403 error
Proposed resolution
Check a user's permissions before adding the message.
Remaining tasks
Add permission check
User interface changes
Message will be hidden for users who cannot rebuild permissions.
API changes
None
Data model changes
None
Issue fork content_access-3464095
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
averagejoe3000Comment #4
steven jones commented@averagejoe3000 thanks for the work here.
I suppose that we should add a test to ensure that we don't show the message to someone who can edit the settings, but not rebuild the access permissions.
Comment #5
joao.ramos.costa commentedHi !
IMO the availability of this messages — considering that in my experience, access to these forms is usually granted to users with elevated permissions — could be something configurable within the module itself, WDYT ?
Thank you!
Comment #7
quadrexdevAdded test coverage and used ->access($current_user) to check access, instead of a permission check.
Please review.
Comment #8
alt36 commentedI think a better approach for both this issue and the underlying original issue #3357181: Does not react to role changes is to just call node_access_needs_rebuild(TRUE) rather than showing a message via content_access_user_update().
Taking this approach would also mean the test cases added in MR !14 should just check e.g.
$this->assertTrue(\Drupal::state()->get('node.node_access_needs_rebuild'), 'Node access permissions need to be rebuilt');(following NodeAccessRebuildNodeGrantsTest.php in the core node module)Comment #9
quadrexdevComment #10
quadrexdevComment #11
quadrexdev@alt36 I agree, it makes more sense, and this way we're relying on the core behavior without re-inventing the same thing in our module.
Merged in 2.1.x
Comment #14
steven jones commentedI'm suggested that we revert the changes introduced in this issue over here:
#3574984-14: 2.1.0-rc2 keeps asking to rebuild permissions
Because these changes call
node_access_needs_rebuild(TRUE);a lot of the time when they don't need to.I'm going to raise a new issue about how to do the content auth grant realm properly, and then that'll mean that we can safely remove the messaging that this ticket was originally about.
Comment #15
steven jones commentedComment #17
steven jones commentedOver in #3579507: Re-work the author grant realms I've got a different implementation that doesn't need to recompute the node access records any time a user's roles change.
It should be considered experimental I think, but if anyone wanted to test that out on a dev site and let me know if it works for them that would be much appreciated. I've added tests for the functionality that's changing, but you never know eh?
Comment #18
steven jones commentedI'm going to go ahead and mark this issue as 'won't fix' since the proper fix is coming in 3.x / #3579507: Re-work the author grant realms. We're just going to go around in circles trying to do something a bit silly if we try to resolve this message being shown incorrectly etc. The correct way forward is to get the records/grants done right, so that we don't need a message at all, because the system works.
Thanks for your help on this issue everyone, and feel free to pitch in on #3579507: Re-work the author grant realms.