Postponed on #2809177: Introduce entity permission providers
Problem/Motivation
Content moderation is not all about nodes since it is quite easy creating a custom content entity and make sure content moderation works on that. The module also introduces a "Latest version" local task on moderated entities, but in the related \Drupal\content_moderation\Access\LatestRevisionCheck access checker only validates if the current user has view (any/own) unpublished content permission, which only applies to nodes...
Proposed solution
Check the type of the entity object and only apply view (any/own) unpublished content when the type of the object is NodeInterface, otherwise use the view (any/own) unpublished [entity_type] permission, which may or may not exists.
Update: assumption: it should also respect the "administer [entity_type]" permission.
Related issues
There is a currently open patch in the Entity API module that would introduce a view any unpublished [entity_type] permission, view own is already supported. Add: "View any unpublished [entity_type]" permission [#3023527]
There are several open content moderation issues related to this problem as of today:
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | interdiff_3_6.txt | 2.82 KB | mxr576 |
| #6 | content_moderation-support-view-any-unpublished-entity-type-permission-3160748-6.patch | 2.08 KB | mxr576 |
Comments
Comment #2
mxr576Comment #3
mxr576Just realised that the access control should also respect the "Administer [entity_type]" permission as well, should not it?
This patch breaks tests for sure.
Comment #4
mxr576It seems the
Administer [entity_type]permission is not respected by edit forms either, so having it does not mean "bypass content moderation". Besides this permission, the user must have at least one[entity_type] moderation workflow: Use [transition] transition.permisison to have access (again) to the edit form. Is it by design?Comment #5
sam152 commentedBefore adding tags read the issue tag guidelines.
I can see what you mean, 'view any unpublished content' is implied to be a generic permission for all entity types, since it's defined in content_moderation, but 'view own unpublished content' is defined in node and you'd be forgiven for assuming this would apply to nodes only.
Two issues:
Comment #6
mxr576I tried to provide some sane defaults that works better for most of the case compared with the current one. These patterns are based on permissions provided by the Entity API module. Anybody who is building a custom entity without the Entity API module, for sure, it needs a custom moderation handler.
I also had a conversation with Berdir on Slack and based on that, probably it would be better to check if the user has edit access to the entity, which should cover any custom logic, including administer/edit any(own) permissions, etc.
Comment #7
mxr576So a few mocks needs to be adjusted, but otherwise it is looking promising...
(Plus we probably need an extended test coverage because the above described issue was not discovered by the current test coverage.)
Comment #14
pameeela commented@mxr576 is this something you are still interested in? I think the issue summary needs to be updated based on your most recent comments, but it also sounds like this might be a task or two rather than a bug?
Either way if you could provide some more information this is more likely to progress.
Comment #15
anybodyI think this should be postponed on #2809177: Introduce entity permission providers for now.