Skip to content

NEW: KEY_MODULE-filed rights now group with their target module and sort next to it - #39736

Open
hregis wants to merge 3 commits into
Dolibarr:developfrom
hregis:new_dev_multicompany_user_rights
Open

NEW: KEY_MODULE-filed rights now group with their target module and sort next to it#39736
hregis wants to merge 3 commits into
Dolibarr:developfrom
hregis:new_dev_multicompany_user_rights

Conversation

@hregis

@hregis hregis commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

Rights declared by a module but filed into another module's section of the permission grid (DolibarrModules::KEY_MODULE) previously kept the declaring module's own family/module_position, opening a second, misplaced section instead of merging with the target module's native rights. User::loadRights() and UserGroup::loadRights() also indexed such rights under the display module column instead of module_origin, so hasRight() could never resolve them under the module that actually declared and controls them.

  • insert_permissions() now resolves family/module_position from the target module (getModuleInfoByRightsClass(), cached) when KEY_MODULE differs from the declaring module.
  • loadRights() (User and UserGroup) indexes $user->rights by module_origin when set, so hasRight() checks against the declaring module regardless of where the right is displayed.
  • New rights_def.sort_order column + DolibarrModules::KEY_SORT_ORDER let such a right sort right next to a specific native right of the target module (set to that right's id) instead of always trailing the whole section. module_position can't carry this: it's a per-module value that user/perms.php actively normalizes back to the module's own position on every page load.
  • user/perms.php, user/group/perms.php, admin/perms.php: sort by sort_order (falling back to id, unchanged for every existing right), tooltip and a small badge now show the actual declaring module for such rights.
Capture d’écran 2026-08-25 à 16 10 27

hregis added 2 commits August 25, 2026 16:18
…ort next to it

Rights declared by a module but filed into another module's section of the
permission grid (DolibarrModules::KEY_MODULE) previously kept the declaring
module's own family/module_position, opening a second, misplaced section
instead of merging with the target module's native rights. User::loadRights()
and UserGroup::loadRights() also indexed such rights under the display module
column instead of module_origin, so hasRight() could never resolve them under
the module that actually declared and controls them.

- insert_permissions() now resolves family/module_position from the target
  module (getModuleInfoByRightsClass(), cached) when KEY_MODULE differs from
  the declaring module.
- loadRights() (User and UserGroup) indexes $user->rights by module_origin
  when set, so hasRight() checks against the declaring module regardless of
  where the right is displayed.
- New rights_def.sort_order column + DolibarrModules::KEY_SORT_ORDER let such
  a right sort right next to a specific native right of the target module
  (set to that right's id) instead of always trailing the whole section.
  module_position can't carry this: it's a per-module value that user/perms.php
  actively normalizes back to the module's own position on every page load.
- user/perms.php, user/group/perms.php, admin/perms.php: sort by sort_order
  (falling back to id, unchanged for every existing right), tooltip and a
  small badge now show the actual declaring module for such rights.
getModulePosition() can return int|string, but the method's declared return
type is array{family:string,position:int}. Cast position to int at both
places the result array is built so the runtime type matches the declaration.
@hregis
hregis requested a review from eldy August 25, 2026 14:50
Add a 4th example permission to modMyModule.class.php showing how to file a
right into another module's section of the permission grid and sort it next
to a specific native right of that module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant