Problem/Motivation

For each feed type there are specific permissions available, like permissions to create feeds of that type or perform an import for feeds of that type.

When deleting a feed type, permissions configured for that feed type are not cleaned up. On Drupal 10 this causes a RuntimeException when trying to edit and then save that role.

Steps to reproduce

  1. Create a feed type, for example called "foo".
  2. For a role, enable some of the feed type specific permissions, for example "create foo feeds".
  3. Delete the feed type.
  4. Go the role edit page and try to save the role.

This will result into the following error:

RuntimeException: Adding non-existent permissions to a role is not allowed. The incorrect permissions are "create foo feeds". in Drupal\user\Entity\Role->calculateDependencies() (line 206 of core/modules/user/src/Entity/Role.php).

Proposed resolution

Make sure that the permissions have a dependency on the feed type. We can see how the node module solved that issue.

The feed type permissions are defined in feeds/src/FeedsPermissions.php.

For the node module, node type permissions are defined in node/src/NodePermissions.php. In there I see that there is trait called "Drupal\Core\Entity\BundlePermissionHandlerTrait" being used. Maybe that is all that is needed.

This also needs a functional test to ensure that the bug is resolved.

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Issue fork feeds-3327572

Command icon 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

MegaChriz created an issue. See original summary.

megachriz’s picture

See also this change record: https://www.drupal.org/node/3193348

abyss’s picture

Assigned: Unassigned » abyss

Hi @MegaChriz, if you don't mind, I will undertake this task.

megachriz’s picture

@Abyss
That's fine! Thank you in advance.

abyss’s picture

I've added a fix for the permissions clearance issue, and I've also added a test to test this functionality. Now, after deleting a Feed Type, the role that had permissions associated with it clears them when deleting this type.

abyss’s picture

Assigned: abyss » Unassigned
Status: Active » Needs review

megachriz’s picture

Thanks for the fix and the test! I moved the test to a new test class. The test class "FeedTest" is for testing things happening in the class \Drupal\feeds\Entity\Feed specifically.

Also nice that this case could also be covered with a Kernel test. That makes the test a lot simpler.

  • MegaChriz committed 6632fcdf on 8.x-3.x authored by Abyss
    Issue #3327572 by MegaChriz, Abyss: Fixed clean up permissions when...
megachriz’s picture

Status: Needs review » Fixed

I merged the code! Thanks for your contribution, @Abyss!

Status: Fixed » Closed (fixed)

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