I ran into problems with using RulesAction "Fetch entity by property" for file entities: my component didn't appear among available VBO operations. The reason was failing access check which returned FALSE
for $op = 'view'
and $entity_type = 'file'
.
The function entity_metadata_file_access($op, $file = NULL, $account = NULL, $entity_type)
responsible for this does so because no $file object is given.
Steps to reproduce:
1. Create an Action Set component with a parameter of type Entity = say "Node", then add action "Fetch entity by property", set Entity Type = "File" and property say filename = anything.
2. Now enable this component in VBO field of a view which lists Nodes.
3. Visit view page - the operation added doesn't appear in the operations list.
Comment | File | Size | Author |
---|---|---|---|
#9 | entity-file_entity_access-1831578-9.patch | 741 bytes | ParisLiakos |
#1 | entity-1831578-1.patch | 1.07 KB | OnkelTem |
Comments
Comment #1
OnkelTem CreditAttribution: OnkelTem commentedIn this patch file access check is delivered to File Entity's
file_entity_access()
callback.Comment #1.0
OnkelTem CreditAttribution: OnkelTem commentedasd
Comment #2
OnkelTem CreditAttribution: OnkelTem commentedBUMP
Comment #3
fagoWhat does file entity's callback do? Is this function compliant as access callback? How does it handle the case when no entity is given?
Comment #4
keesje CreditAttribution: keesje commentedThis patch is working for me.
I doubt that this is the most sane "solution" though.
Insights:
entity_metadata_file_access validates only "view" as TRUE for $op. VBO can ask permissions for ops:
see _views_bulk_operations_entity_access().
So, if access is checked for any other $op than "view" for entity type "file", validation will allways return "false" since "entity_metadata_file_access" is triggered. And we know entity_metadata_file_access only accepts "view" as a valid $op.
Bottomline is that an entity type can only have 1 "access callback". And entity.module and file_entity.module both try set it. So, it comes down to the order of module execution. Which can be altered by changing the module weight in the system table.
Setting weight on file_entity.module to 1 solved this problem for me. In my case and opinion this is a cleaner solution than the patch in #1.
Comment #5
rooby CreditAttribution: rooby commented@fago:
I'm not really sure what makes a compliant access callback but here is some information on what file_entity_access does (in order):
Comment #6
rooby CreditAttribution: rooby commentedOops, I though I already posted this but these are my findings on the current solutions:
The patch in #1 fixed my problem of user 1 getting insufficient permissions errors when updating/deleting file entities with views bulk operations.
I also agree that the solution in #1 seems hacky though.
The solution in #4 (setting the weight of the file_entity module to 1) did not fix it.
Also, changing the weight of a module that other modules build on top of (like file_entity) has the potential to cause other issues with other contrib modules.
Comment #7
rooby CreditAttribution: rooby commentedMarked #1897272: Insufficient permissions when using user 1 as a duplicate of this issue.
Comment #8
gmclelland CreditAttribution: gmclelland commentedFYI.. The patch in #1 fixed my problem here #1892582: Permission error using VBO to manipulate Files (bulk modifying fields)
Comment #9
ParisLiakos CreditAttribution: ParisLiakos commentedI think this is a better way.no need to go through
entity_metadata_file_access
if file_entity_access existsComment #10
gmclelland CreditAttribution: gmclelland commentedPatch in #9 fixed my problem here #1892582: Permission error using VBO to manipulate Files (bulk modifying fields)
Comment #11
populist CreditAttribution: populist commentedI also ran into this problem and see that it is quite common. I checked out the patches here and #9 worked for me.
Marking #9 RTBC because it looks to be the most elegant of the approaches and this issue seems to be a blocker for a few folks. #1 is quite similar in approach, but directly calling functions in file_entity.module seems not as great as simply understanding that if file_entity.module is available then it has its own access function which, as per #5, seems to do what it is suppose to do.
Comment #12
fago#9 is reasonable. Thanks, committed.
Comment #14
firfin CreditAttribution: firfin commentedMarked #1890552: Rules components are not listed in the VBO options combobox on a view. as a duplicate.
Comment #15
wodenx CreditAttribution: wodenx commentedReopening because the approach above breaks file entity access when Media 1.3 is installed (and this is still the recommended release).
The 'file_entity_access' callback was introduced in File Entiyt 2.x - and isn't present in the version bundled with Media 1.3.
See #2094833: Allow modules to insert alternative access callbacks for a proposed solution.
Comment #15.0
wodenx CreditAttribution: wodenx commentedUpdated issue summary.