Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
file.module
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
31 Aug 2013 at 14:46 UTC
Updated:
10 Aug 2016 at 14:34 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
xanoI have two questions:
Comment #2
larowlan1) no (see file entity project)
2) yes (see media project)
Comment #3
berdir1) Core handles file access for files attached to entities and makes it easier for entities to control access to their files using hook_file_download_access_alter(). Anything else can be done by implementing hook_file_download() yourself. This hook is currently based on the path. I guess this would be replaced with an hook_file_access() implementation that acts on the file entity if we move this into the
2) Yes. file_file_download() implements it so that access is granted if the user is able to view the file if any of those references grant access. The current implementation already checks the field access API, we just need to replace all the hook_file_download_access() with a single $entity->access('view'), as earlier patches of mine did in the referenced issue. If for whatever reason that assumption is *not* true, there's still the possibly to interfere by implementing hook_file_download($uri) (now) or hook_file_access($file) (if we replace it using an access controller), just requires a bit more code.
Fact is that most entities are *not* implementing this hook, which means that private files attached to them are *not* visible. This still includes terms in 7.x as the related issue has not yet been backported. The suggested default assumption is going to solve 99% of the use cases without additional code for entity types.
The main problem to move this into the access controller is the weird $field_type stuff, that limits all this logic to a single field type (defaults to file and then image calls this hook again using it's own field type). I'm not sure why we need this nor if is actually working, if you look at file_get_file_references(), you can see that there is a loop that overrides the $field_type argument.
Comment #4
dave reidComment #5
blueminds commentedHere is a patch that:
- Provides the FileAccessController
- Removes the hook_file_download_access
- Updates the comment access controller to consider the comment status and the access to the parent entity
Comment #8
blueminds commentedrerolled
Comment #11
blueminds commentedanother try
Comment #14
blueminds commentedhopefully this time...
Comment #17
blueminds commented- Fixed the private file test
- The fail without the comment controller update shows that the actual update of the controller fixes the issue introduced by removing the file_download_access hook and removing further access logic inside file_file_download.
Comment #18
slashrsm commentedPatch looks good to me. Agree with potential problems with different return behaviour of hook_file_download and access controller, but I'm not sure if this is something that should be addressed in this issue.
Comment #19
andypostSummary should be updated for current patch that looks great!
hook removal is api change and seems need approval
Comment #20
blueminds commentedAdded the download operation to check the access.
Comment #21
slashrsm commentedOK. Looks good and it seems that we pretty much agree on it. Let's see what committers have to say about it (API change, etc.).
Comment #22
alexpottYep this is much better then having to implement a hook. Nice work.
Committed 64387e5 and pushed to 8.x. Thanks!
Comment #25
gábor hojtsyFix media tag.