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
- Create a feed type, for example called "foo".
- For a role, enable some of the feed type specific permissions, for example "create foo feeds".
- Delete the feed type.
- 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
- Write a test that follows the steps to reproduce the issue.
- Fix the issue.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork feeds-3327572
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 #2
megachrizSee also this change record: https://www.drupal.org/node/3193348
Comment #3
abyss commentedHi @MegaChriz, if you don't mind, I will undertake this task.
Comment #4
megachriz@Abyss
That's fine! Thank you in advance.
Comment #6
abyss commentedI'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.
Comment #7
abyss commentedComment #9
megachrizThanks 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\Feedspecifically.Also nice that this case could also be covered with a Kernel test. That makes the test a lot simpler.
Comment #11
megachrizI merged the code! Thanks for your contribution, @Abyss!