Problem/Motivation
In the core File module, access to view and download file entities is only granted by default to the public:// stream wrapper. If file entities are created that are configured to use the Rokka stream wrapper, then users don't have access. This prevents editors from working with entities that reference Rokka files.
Steps to reproduce
A quick way to reproduce this is to add a file field to a node type. If the file field is configured to use the public stream wrapper, then editors (and other users with the 'access content' permission) can attach a file and then save / update the node without errors. When the file field is reconfigured to use the Rokka stream wrapper, then when a file is attached the following error occurs when saving / updating the node:
You do not have access to the referenced entity (file: 9835110).
Proposed resolution
We can use the same logic as used in the file module for public files: all users get access to the download operation, but only users with the access content permission get view access on the file entities (ref. \Drupal\file\FileAccessControlHandler::checkAccess()).
API changes
All users will get access to the download operation on file entities. Users with access content permission will get access to the view operation on file entities.
Data model changes
None.
Issue fork rokka-3264149
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:
Comments
Comment #2
pfrenssenComment #4
pfrenssenThe failures are seemingly due to #3259744: PHPUnit 9.5.12 (released 2022-01-21) throws unhandled deprecation notice on "Drupal\Tests\Listeners\DrupalListener" which is recently fixed, but the test ran against Drupal 9.3.0 which does not include the fix. Trying again with the latest version of 9.3.x.
Comment #5
pfrenssenTest green, ready for review!
Comment #6
pfrenssenComment #7
pfrenssenIf this is accepted, please credit @didebru who created the initial version of the bugfix.
Comment #8
tcrawford commentedThis works. We are using this in the same project that both @pfrenssen and @didebru contribute(d) to.
Comment #10
ayalon commentedThanks for the feature and the test. Will be merged in the next version.
Comment #12
ayalon commentedComment #13
ayalon commented