Problem/Motivation
The Menu Per Role module currently lacks the necessary granularity to control who can assign roles for menu item visibility. The module provides a general permission (administer menu_per_role), which allows access to the configuration of the module but does not distinguish between users who should only manage the settings and those who should have the ability to assign visibility roles to menu links.
Additionally, the naming and description of the administer menu_per_role permission are misleading. This permission implies general module administration, but its real function is more limited. It needs to be renamed and clarified to reflect its actual usage.
Steps to reproduce
- Install the Menu Per Role module on a Drupal 10.x site.
- Assign the
administer menu_per_rolepermission to a user role. - Edit a menu item and observe that there is no specific permission to control who can assign roles to determine the visibility of the menu link.
- Any user with the
administer menu_per_rolepermission can both access the module settings and assign visibility roles to menu links, without separate permissions to control these actions.
Proposed resolution
- Rename and clarify the existing permission:
- Change the name of
administer menu_per_roletoadminister menu_per_role settings. - Update the title and description of the permission to reflect that it is specifically for accessing the module’s settings.
- Name:
administer menu_per_role settings - Title: "Administer Menu Per Role settings"
- Description: "Permission to configure Menu Per Role settings."
Proposed new title and description:
- Change the name of
- Create a new permission to control role assignments for menu item visibility:
- Name:
assign menu role visibility - Title: "Assign roles for menu link visibility"
- Description: "Allows users to assign which roles can view specific menu links."
- Name:
- Modify the module’s form logic (in
menu_per_role_form_menu_link_content_form_alter) to check for the newassign menu role visibilitypermission. Only users with this permission should be able to assign visibility roles to menu links, while the general module settings should remain restricted to users withadminister menu_per_role settings.
With this proposed change, the module will provide better control over who can manage its settings and who can assign role-based visibility to menu items.
Issue fork menu_per_role-3476411
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 #3
angel ruiz commentedComment #5
grask0 commentedHey,
Seems like ok for me. Thanks for such update!
Comment #6
grask0 commentedComment #7
grimreaperHi,
Thanks for your work on this issue.
Changing status to needs work as the change is missing a hook_update_N.
Also tests needs to be updated.
It may be better to wait for #3456786: Remove user 1 special behavior to avoid user 1 side effects.
Comment #8
grimreaperComment #10
anton4uk commentedComment #11
grimreaperHi,
Thanks for your work, I made some review comments.
I have not tested, and am surprised that tests do not need to be updated.
Comment #12
anton4uk commentedComment #14
grimreaper