Problem/Motivation
This is part of the #2028027: [META] Missing access control for base fields meta issue. Please read the meta issue for the reasoning.
Proposed resolution
FIrst, the patch adds a simplified logic that allows entity access control handlers to provide default access logic for their base fields, instead of having to provide a custom class for each specific case and use that as a list class.
Adds base field access logic for node base fields. Specifically, status, promote, sticky, created, uid and revision_log can only be changed by users with the administer nodes permission, and changed, revision_uid and revision_timestamp can not be changed by any user as they are automatically managed by the system.
Remaining tasks
User interface changes
API changes
No changes, only adds a new method that access control handlers can optionally implement.
Original report by @fago
This issue is for implementing default access for all base fields of a node. We need to go through them and look for existing access restrictions and make sure they are covered as part of the default Access of their field's item classes.
Example: We've got a permission for editing user names, that needs to be covered.
What to do: For each field that has a default access being not TRUE, we
- have to add a custom FieldItem class extending the field type's one
- implement defaultAccess() for it
- write a unit test case to prove it works as it should
Comments
Comment #1
fagoComment #2
fagoComment #3
guedressel commentedComment #4
guedressel commentedFor now I built a defaultAccess check for the status field. The status field might be the most important one..
To accomplish this check I also introduced two new permissions to the node module:
* "change status of own %type content"
* "change status of any %type content"
..hope you like that.
It would be nice if I could get a review of my current patch. Even if there are more fields which needs to be covered and even if the UnitTest is not covering 100% of the cases.
It's my first patch for D8 and I made some comments in the code where I wasn't sure if I'm applying D8 stuff correctly...
And by the way:
Thanks for the drupalcon in prague!
I enjoyed to see (at least some of) you guys in person.
Comment #5
guedressel commented...just set it back to "needs work" when you put your experienced and valuable 2 cents to my patch ;-)
Comment #7
guedressel commentedOkay.
I see.
The Create Resource Test from REST gave me answers to some questions ;-)
I need to refactor the permission checks.
Comment #8
guedressel commentedAfter working on this issue at drupalcon in prague I'm sitting now at the Schnitzelcamp (DrupalCamp Vienna).
Great time again with you guys :-)
I'm submitting a new - refactored - patch to let drupal.org run it's tests on it.
It should fit better than the last one.
I also removed to custom permissions I mentioned above and will propose them in an extra issue.
Comment #9
guedressel commentedComment #10
guedressel commentedComment #11
guedressel commentedAfter discussing with klausi and fago I have to admit, that I was wrong - in a couple things:
Operations in the defaultAccess method may only be "view" or "edit".
I don't need to check the entity for type "node" in the access method.
The permissions "edit [any|own] content" is not applicable for the status field. Only "bypass access control" and "administer nodes" are of interest.
And my test case was unnecessarily expensive by using WebTestBase class.
Thank you two guys for helping me on this.
Comment #12
guedressel commentedComment #13
klausisuperflous whitespace
inheritdoc missing.
longer than 80 characters.
document that chuck norris is almighty.
white space
no white space before and after "!"
should be tested for all users
@todo
unrelated change, should be removed.
Comment #14
klausifurther fields:
administrative edit permission: uid, status, promote, created, updated, sticky
revision_timestamp, revision_uid, log: revision permissions?
Comment #16
guedressel commentedComment #17
guedressel commentedNow all administrative fields are handled through the NodeAdministrativeField (which restricts editing withoud administrative permissions).
Comment #18
jibranTest this please.
Comment #21
berdirHere is a new patch based on the approach in #2029855: Missing access control for user base fields, with the tests from this issue. I think this issue has a better chance at getting in and getting the API in. We can implement the other entity types any time, but we need to have the API in asap.
Added revision_log to the administrative list.
revision_uid and revision_timestamp and changed are managed automatically, no user should have access to edit them, so updated accordingly. changed could possibly even do that by default.
Cleaned up and updated the test, but conceptually still the same + tests for the new rules.
Comment #22
catchShould be critical no?
Comment #23
klausiwhy don't we also check for "bypass node access" here? Please add a comment.
Status field? I think it applies to more than that?
And why do we need this administrative field class? Please add a comment.
And where is this class used? Shouldn't the NodeAccessController cover this already?
Comment #24
berdir1. Because NodeForm is not doing that either.
2. That class is dead, accidently ended up in the patch again.
Comment #25
klausiThen the test case is flawed, because it claims that $chuck_norris is all mighty having only the "bypass node access" permission.
Comment #26
berdirYep, it is. The uid 1 problem again.
Comment #28
berdirI will update the change record at https://www.drupal.org/node/2101719 to mention the new easier way for base field access, no need to add a new one IMHO.
Comment #29
effulgentsia commentedI like the approach in #26. Patch looks great to me, but the issue summary is now out of date.
Comment #30
effulgentsia commentedWould it make sense to convert NodeForm::form() to use this as part of this patch, or is there a reason for that to be done separately?
Comment #31
klausiNot really useful to call the parent here, just return TRUE? And this should have a comment like "Per default all node fields can be viewed."
This should be removed.
Content types have the "Display author and date information" config option. Shouldn't we deny view access to the node author and the created date if this option is set? Might be a consideration for a followup issue.
Comment #32
berdir#2226493: Apply formatters and widgets to Node base fields should take care of removing the manual access checks I think.
I don't think we should restrict access based on that setting. That is about visiblity of that default output, not access. It's perfectly valid to disable that and show that information in a different way.
Comment #33
berdir#31.1: Can't imagine why now, but would not be the first time we'd later on add something to the base class, so I'd prefer calling it.
#32.2, Ups, debug left-over, removed.
Updated the issue summary.
Comment #35
berdirAccessController is now AccessControlHandler.
Re-roll proudly presented by git rebase.
Comment #36
effulgentsia commented:)
Comment #37
xjmComment #38
xjmComment #39
fagoThanks berdir, patch looks great - I second the RTBC.
Comment #40
alexpottCommitted 8d61447 and pushed to 8.0.x. Thanks!
Comment #42
andypostI was wondered by "readonly" because there's setReadOnly(TRUE) for some base fields but seems that have different meaning