Comments

Wim Leers created an issue. See original summary.

tstoeckler’s picture

Issue tags: +dcruhr18
owenbush’s picture

Looking at this at DrupalCon Nashville.

owenbush’s picture

StatusFileSize
new645 bytes

I have added a message to the forbidden AccessResult call which details that only file owners can update or delete file entities.

owenbush’s picture

Status: Active » Needs review

Needs review.

Status: Needs review » Needs work

The last submitted patch, 5: core-file_access_messsaging-2950127-5.patch, failed testing. View results

josephdpurcell’s picture

Status: Needs work » Active

Looking at the failed tests, this looks a similar state to https://www.drupal.org/project/drupal/issues/2950125#comment-12570703

The tests that are failing should be updated with the new error message you've set.

owenbush’s picture

StatusFileSize
new1.42 KB
new810 bytes

Thanks for that. I have updated the test case. I've provided a new patch and an interdiff.

owenbush’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 9: core-file_access_messsaging-2950127-9.patch, failed testing. View results

owenbush’s picture

StatusFileSize
new1.5 KB
new939 bytes

I guess in this instance it should be a DELETE type, so I added that to the test case. Attached is new patch and a new interdiff.

owenbush’s picture

Status: Needs work » Needs review
borisson_’s picture

Status: Needs review » Needs work
+++ b/core/modules/file/src/FileAccessControlHandler.php
@@ -68,7 +68,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
+      return AccessResult::forbidden('Only the file owner can delete and update the file entity.');

I'm not sure about and here.

I think update or delete the file entity is a better description, because you can't update and delete at the same time.

yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.5 KB
new1.51 KB

Agree with #14 comment it should be update or delete the file entity rather than update and delete the file entity so added updated patch with an interdiff.

Anonymous’s picture

Status: Needs review » Needs work
+++ b/core/modules/file/src/FileAccessControlHandler.php
@@ -68,7 +68,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
+      return AccessResult::forbidden('Only the file owner can delete or update the file entity.');

+++ b/core/modules/rest/tests/src/Functional/EntityResource/File/FileResourceTestBase.php
@@ -224,8 +224,8 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
+    if ($method === 'PATCH' || $method == 'DELETE') {
+      return 'Only the file owner can delete or update the file entity.';

One of the implicit, but important point of @borisson_ is:

update (first) or delete (second)

The title of issue also comply with this order.

The code check with this order (PATCH is 'update').
if ($method === 'PATCH' || $method == 'DELETE') {
Therefore it will be good if the message will also comply with this order.

Also we use strict compare, so:

-  $method == 'DELETE'
+  $method === 'DELETE'
yogeshmpawar’s picture

Assigned: Unassigned » yogeshmpawar
yogeshmpawar’s picture

Assigned: yogeshmpawar » Unassigned
Status: Needs work » Needs review
StatusFileSize
new1.8 KB
new1.58 KB

Agree with @vaplas, but currently adding only strict compare for "DELETE" method. Interdiff is also added.

msankhala’s picture

StatusFileSize
new1.8 KB
new1.8 KB

Here is updated patch as per code review suggestions.

Anonymous’s picture

Status: Needs review » Reviewed & tested by the community

Looks nice!

wim leers’s picture

😍👍 Perfect!

alexpott’s picture

+++ b/core/modules/file/src/FileAccessControlHandler.php
@@ -64,11 +64,11 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
-      // Only the file owner can delete and update the file entity.
+      // Only the file owner can update or delete the file entity.
       if ($account->id() == $file_uid[0]['target_id']) {
         return AccessResult::allowed();
       }
-      return AccessResult::forbidden();
+      return AccessResult::forbidden('Only the file owner can update or delete the file entity.');

I'm not sure the comment adds anything anymore because it's now part of the code too. But I guess this doesn't really matter.

Creditting @Wim Leers and @vaplas for reviews.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed ec8b4f8 and pushed to 8.6.x. Thanks!

  • alexpott committed ec8b4f8 on 8.6.x
    Issue #2950127 by owenbush, Yogesh Pawar, msankhala, Wim Leers, vaplas:...
wim leers’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.