Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When previewing a comment as an anonymous user, the comment body doesn't show up. Given the user does not have the skip approval permissions
Steps to reproduced:
1. Fill in the fields to create a comment as an anonymous user
2. Click the preview button
3. No body field shows up in the preview.
The problem is that CommentAccessControlHandler checks entity access for the entity on every single field. And the comment is unpublished and the fields therefore not visible.
Proposed resolution
Clean up that logic, remove all entity-level access logic.
Remaining tasks
User interface changes
API changes
Data model changes
Comment | File | Size | Author |
---|---|---|---|
#26 | 2574597-26.patch | 9.1 KB | Upchuk |
#26 | interdiff-26.txt | 5.13 KB | Upchuk |
#23 | 2574597-23.patch | 9.35 KB | Upchuk |
#13 | interdiff-13.txt | 1.64 KB | Upchuk |
#8 | 2574597-08-TEST-ONLY.patch | 2.38 KB | jhedstrom |
Comments
Comment #2
Upchuk CreditAttribution: Upchuk at Wunder commentedComment #3
jhedstromComment #4
BerdirThe problem here is that comment field access is wrong. It checks entity access, but that's not the place to do that. Field access by definition assumes that you have access to the entity, so all that published and so on checking (which is what broke this) is unneeded and can be simplified a lot.
Comment #6
Upchuk CreditAttribution: Upchuk at Wunder commentedMade a few changes:
* Using
allowedIfHasPermission
in the fieldAccess to ensure caching.* Removed the view related logic from the fieldAccess test and replaced with simple checks access the the hostname field (nobody should have access to that).
* Since there are no longer checks again unpublished comments, removing the two unpublished comments from the permutations.
Comment #7
Upchuk CreditAttribution: Upchuk at Wunder commentedMinor fix
Comment #8
jhedstromThis adds tests for anonymous comment previewing which we didn't have any before.
Comment #9
alexpottthis was dicovered during #2571909: CommentForm selects using the user formatted name
Comment #13
Upchuk CreditAttribution: Upchuk at Wunder commentedFixing also the
CommentFieldNameTest
which for some reason also checks field access on the commentComment #17
klausiI think we should not modify the test cases like that. We should always test all fields for access, even if it is quite clear that view access to almost all of them is allowed. This is important for regression testing, when somebody tries to change comment field access logic later.
Comment #19
Upchuk CreditAttribution: Upchuk at Wunder commentedAlright,
* Adding back the 2 comment entities in the test.
* Keeping the field access checks but asserting that the user has access to view all of them except for the hostname and mail fields which have special checks at the bottom.
Comment #20
klausihm, can we keep the nice message from above? Makes it easier to see what is going on when looking at the test results.
same here. And I think we should have an else{} here that checks the hostname field right here instead of farther down.
and here
Comment #23
Upchuk CreditAttribution: Upchuk at Wunder commentedYou're right.
Here we go.
Comment #24
jhedstromComment #25
klausiCan we move the comment about mail down to the other if?
skip grant permission? You mean skip comment approval permission?
Please, please no more randomness in tests :-( See #2571183: Deprecate random() usage in tests to avoid random test failures
Let's replace this with hard coded example strings.
we should use assertTrue()
Can we just have this long assert once and only set a $view_access variable to TRUE/FALSE within the if()?
asserTrue()
Comment #26
Upchuk CreditAttribution: Upchuk at Wunder commentedHey @klausi,
I addressed all the issues from #25 (hopefully :) )
Comment #29
BerdirUpdated issue summary a bit.
Comment #30
yched CreditAttribution: yched commentedThe fix looks reasonable, I'll let @klausi approve the recent changes.
Comment #31
larowlanLooks good to me - thanks all
Comment #32
webchickLooks like @klausi's feedback has been addressed, and subsystem maintainer signed off.
Committed and pushed to 8.0.x. Thanks!