Changing permission label drops permission settings

Created on 28 April 2019, over 5 years ago
Updated 29 October 2024, 23 days ago

Problem/Motivation

I learnt (the hard way) that changing a permission label changes the generated permission id. This is strongly unexpected so setting major.

Also if someone translates the custom-permission, things will go havoc.

Proposed resolution

* Use the machine name of the custom-permissions config entity for the permission ID
* Expose machine_name as form field
* Provide an upgrade path that fixes the user permissions table
* Add a release note

πŸ› Bug report
Status

Active

Version

2.0

Component

Code

Created by

πŸ‡©πŸ‡ͺGermany geek-merlin Freiburg, Germany

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States audioroger Bristol, VT

    I had a similar experience when renaming, disabling or deleting a custom permission. Any of these actions leads to an exception when saving the permissions from /admin/people/permissions.

    RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "[permission-name]". in Drupal\user\Entity\Role->calculateDependencies() (line 207 of core/modules/user/src/Entity/Role.php).
    

    The workaround I found was to first disable the custom permission for all user roles and save. Then rename, disable or delete the custom permission. In the case that you are renaming, you would then go back to the permissions page and re-enable the permission for the roles you removed it from.

    Note: I have no idea how this works with translations.

    More explicitly

    Steps to reproduce

    1. Login as an Administrator
    2. Go to: /admin/people/custom-permissions/list
    3. Add a permission and save
    4. Open a new tab and go to: /admin/people/permissions
    5. Search for the custom permission added in step 3
    6. Enable it for any role below Administrator and save permissions
    7. Go back to: /admin/people/custom-permissions/list
    8. Rename, disable or delete the permission added in step 3 and save
    9. Go back to: /admin/people/permissions
    10. With no changes: Scroll down and click "Save permissions"

    Behavior

    Exception shown above

    Expected Behavior

    Permissions save without exception

    Workaround

    1. Login as an Administrator
    2. Go to: /admin/people/custom-permissions/list
    3. Add a permission and save
    4. Open a new tab and go to: /admin/people/permissions
    5. Search for the permission from step 3
    6. Disable it for ALL ROLES below Administrator and save permissions
    7. Go back to: /admin/people/custom-permissions/list
    8. Disable, rename or delete the permission(s) from step 3 and save
    9. Go back to: /admin/people/permissions
    10. With no changes: Scroll down and click "Save permissions"

    In the case of renaming the permission, re-enable it for all roles in step 9/10

    Behavior

    Permissions save without exception

    Environment

    Drupal core: 10.2.8
    config_perms: 2.1.0

Production build 0.71.5 2024