Define permission dependencies

Created on 25 January 2024, 10 months ago
Updated 20 February 2024, 9 months ago

Problem/Motivation

When a module defines dynamic permissions, it should define their dependencies. See the change record Permissions can define dependencies β†’ .

In some cases, the missing dependencies lead to problems, like πŸ› "Adding non-existent permissions to a role is not allowed." exception is thrown for profile installations Needs work .

Proposed resolution

Define the dependencies as described in the change record.

Remaining tasks

User interface changes

None

API changes

None

Data model changes

None

πŸ“Œ Task
Status

Fixed

Version

1.0

Component

General code

Created by

πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

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

Merge Requests

Comments & Activities

  • Issue created by @benjifisher
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & sqlite-3.27
    last update 10 months ago
    34 pass
  • Issue was unassigned.
  • Status changed to Needs review 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    The MR uses the node module as a model.

    Testing steps:

    1. Install Drupal 10.2.x with the Standard profile.
    2. Enable search_api_autocomplete and search_api_db_defaults (and dependencies).
    3. Enable "Search content" on Default content index > Autocomplete (/admin/config/search/search-api/index/default_index/autocomplete).
    4. Assign the "Use autocomplete for the Search content search" permission to the Content editor role on /admin/people/permissions/module/search_api_autocomplete.
    5. Go to /admin/config/development/configuration/single/export and export the config for the Content editor role.

    In the last step, I see the following dependencies:

    dependencies:
      config:
        - node.type.article
        - node.type.page
        - search_api_autocomplete.search.search_content
        - taxonomy.vocabulary.tags
      module:
        - comment
        - contextual
        - file
        - node
        - path
        - search_api_autocomplete
        - system
        - taxonomy
        - toolbar
    

    That is, the role correctly depends on the search_api_autocomplete.search.search_content configuration.

  • Pipeline finished with Failed
    10 months ago
    #82183
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    To complete the test,

    1. Switch to the 8.x-1.x branch.
    2. Remove the permission from the Content editor role.
    3. Clear caches.
    4. Restore the permission.
    5. Export the role config.

    Now I see these dependencies:

    dependencies:
      config:
        - node.type.article
        - node.type.page
        - taxonomy.vocabulary.tags
      module:
        - comment
        - contextual
        - file
        - node
        - path
        - search_api_autocomplete
        - system
        - taxonomy
        - toolbar
    

    The module is listed but not the search config.

  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    @drunkenmonkey:

    Please consider giving issue credit to those who commented on πŸ› "Adding non-existent permissions to a role is not allowed." exception is thrown for profile installations Needs work : @codebymikey and @smustgrave.

  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    drunken monkey β†’ made their first commit to this issue’s fork.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & sqlite-3.27
    last update 10 months ago
    34 pass
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    Thanks a lot for reporting this problem and already providing the correct fix!
    Seems this has been available for ages (since Drupal 9.3), so should be no problem increasing our version requirement to that. Anyone still on 9.2 is hardly gonna keep this module up to date.
    I’ve also added a one-line test to make sure this works correctly.

    Please test/review and I can merge.

  • Status changed to RTBC 10 months ago
  • πŸ‡ΊπŸ‡ΈUnited States benjifisher Boston area

    @drunken monkey:

    Thanks for catching the version requirement. BTW, Drupal 9.3 also introduced the module-specific permissions form that I mentioned in Step 4 of my testing instructions (Comment #3).

    I reviewed the changes, and they look good. To keep myself honest, I checked the test to see where the magic string "muh" is introduced.

    I repeated the test from Comment #3 and got the same result.

    The other issue brought this bug to my attention. Reporting a bug is an important step in getting it fixed, even though the initial analysis was incomplete. I reviewed the issue that introduced permission dependencies, and I wrote the change record, so I did not need much help in figuring it out.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & sqlite-3.27
    last update 10 months ago
    34 pass
  • Pipeline finished with Skipped
    10 months ago
    #88940
  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 9.5.x + Environment: PHP 8.1 & sqlite-3.27
    last update 10 months ago
    34 pass
  • Status changed to Fixed 10 months ago
  • πŸ‡¦πŸ‡ΉAustria drunken monkey Vienna, Austria

    Good to hear, thanks for reporting back!
    Merged. Thanks again!

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024