Problem/Motivation
ContentEntityForm::addRevisionableFormFields contains access checks that do nothing.
Both the details element and revision checks contain #access entries that check ->access('update') which is not a valid field access operation (it should be edit)
Since the operation is invalid, this access check always returns TRUE.
The details element also checked $new_revision_default, but we cannot keep that as it would hide the revision information if Create new revision was unchecked.
Proposed resolution
Remove the access checks entirely.
See #12 and #14 for reasoning.
MediaTypeForm descriptions will be fixed in #3364973: Make Add content/media default publishing option descriptions consistent
Remaining tasks
Do it.
Original report
Problem/Motivation
Node Type form says "Users with sufficient access rights will be able to override these options." and Media Type form says "Users with the "Administer media" permission will be able to override this option.". If I create a user that can edit media and nodes without the administer permissions, the option remains overridable. 🤔 I'm not sure what would be required to not have "sufficient access rights" for the Node use case, but at least the Media use case is clearly not working the way the UI makes you believe.
Steps to reproduce
- Install Standard
- Enable Media module
- Confirm on
/admin/structure/media/manage/imagethat "Create new revision" is checked - Give the "Content Editor" role following permissions: "Image: Create new media", "Image: Edit any media", "Access media overview", "View all media revisions", "View media", "View own unpublished media"
- Log in as a content editor
- Go to
/media/add/imageto create new image media entity - After creating the media entity, confirm that "Create new revision" is visible, can be unchecked, and content can be saved without creating new revision
| Comment | File | Size | Author |
|---|
Issue fork drupal-3384520
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:
- 11.x
compare
- 3384520-remove-access
changes, plain diff MR !12035
- 3384520-create-new-revision
changes, plain diff MR !4764
Comments
Comment #2
lauriiiThis might be a duplicate to #3364973: Make Add content/media default publishing option descriptions consistent.
Comment #3
lauriiiComment #4
lauriiiComment #5
lauriiiComment #9
wim leersThis JSON:API test coverage was written without my involvement, see #2943899: Moderation state field cannot be updated via REST, because special handling in ModerationStateFieldItemList.
The failing assertion:
That is now a 403 response instead of a 422.
3 observations:
NodeAccessControlHandler, where access to modifyingvidis being denied, to follow the trace to how this gets mapped to a 422 response? If you did, I can’t find it in this issue.vidbeing validated, and that causes the 403?Comment #10
omkar.podey commentedComment #11
hooroomooRemoving tag, reviewed and tested
Comment #12
berdirAdded a few comments.
Also, that the media type settings basically has the same info as node type, with the administer media permission, but media isn't fixed yet here.
One last thing, to make this issue even more fun. I'm not even 100% sure that fixing access to do what the permission says is even the right thing to do at this point. It's likely been like this for a very long time, and sites probably rely on it, because while they might to allow users to decide if a new revision should be created or not, but not things like changing the author or sticky/promoted flags and whatever else these administer permissions allow.
which I now realize is exactly what #3364973: Make Add content/media default publishing option descriptions consistent is about, it's updating the description to match how it actually works, which is IMHO fine. There's still things to fix and improve here, like the invalid field access operations, but we wouldn't actually change NodeAccessControlHandler here.
Comment #13
omkar.podey commentedComment #14
berdirAdded some new comments.
To be clear, as I said in #12, I'm not convinced that this is the right thing to do. I think the referenced issue that just fixes the docs is the better direction. If someone wants to alter access they can do so, but this is going to be a behavior change for many sites that currently rely on this being visible.
I would suggest that we extract the few unrelatd bits that make sense, like the JS fix, and then instead get the other issue in and close this as won't fix?
Comment #15
smustgrave commentedTo keep this from stalling, unless anyone has a counter argument for #14 going to move to NW for #14
Comment #16
acbramley commentedComment #19
acbramley commentedRescoped based on #12 and #14
We can just remove these access() calls entirely.
Comment #20
acbramley commentedRefining IS with more detail.
Comment #21
smustgrave commentedPossible to add test coverage though? Not sure if anything can be pulled from the original MR?
Comment #22
acbramley commentedNo, this is just removing invalid code.
Comment #23
smustgrave commentedIf it’s causing a bug then shouldn’t we have test coverage.
Comment #24
acbramley commentedWhat bug is it causing?
Comment #25
smustgrave commentedWas filed as a bug, assuming it was a bad access check. So would say test coverage should be added. But I’ll leave for others to review
Comment #26
acbramley commentedThe bug is that the access checks are invalid and functionally don't do anything, the issue summary is up to date with this information and the original bug report is there as well.
Comment #27
berdirCode changes look fine. I guess since this does not fix an actual bug, it could be reclassified as a task, but doesn't matter too much.
Comment #29
catchHad to read through this a couple of times, but overall agreed this is just dead code that should be removed, we have the issue open to make whether this stuff shows configurable which would be good to land.
Committed/pushed to 11.x, thanks!