Closed (fixed)
Project:
FileField Sources
Version:
8.x-1.x-dev
Component:
Source: Auto-complete
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
4 Jan 2017 at 08:55 UTC
Updated:
7 Jun 2021 at 17:59 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
urodriguezpombaHi, I confirm this issue. Can anyone help with this? No other user than admin can reference a file.
Thanks for anyone can help.
Comment #3
euk commentedHi!
I confirm the issue too.
Looking at the code - why would file reference be tied to field edit permissions??
Checking the core's entity reference route - it has _access = 'TRUE', which if applied to the issue at hands - solves the issue.
I wonder what would be the concerns regarding this?
Patch attached...
Comment #4
gnugetI spent one hour today reading the code to know why this check is done.
Basically this is a problem introduced in the port from D7.
In D7 we have:
and the code of
_filefield_sources_field_accessis:Which seems to be similar to what the code is doing in D8 but... nop, I checked the
field_accessfunction and I found this:So what the
field_accessfunction do is check if the user has permissions to edit the VALUE of the field in an specific entity (node), not if the user has permissions to edit the CONFIGURATION of the field. 🙂So, great work euk, thank you for pointing me in the right direction.
So... I would say that we need to fix that check and add code to make sure that the user has permissions to edit the value of the field.
Comment #5
gnugetOk, I think the entity should be passed to
Drupal\filefield_sources\Access\FieldAccessCheck\accessand useEntityAccessControlHandlerInterface::fieldAccessto evaluate if the user has permission.I will try to work on this on the weekend but if someone else wants to take a stab at it is more than welcome :-)
Comment #6
euk commentedI have it on my plate, so could check the solution today.
If no patch by the end of the day - then it is your turn =)
Comment #7
euk commentedComment #8
euk commentedDid a bit of coding, and this is the patch I came up with.
My immediate issue is that no user other than an admin can reference a file. This patch solves it with the help of
EntityAccessControlHandlerInterface::fieldAccessas suggested above by #2840934-5: Autocomplete reference search access denied by @gnuget.However, I have no idea of possible use cases where the field might have restrictions, and thus how to test it thoroughly.
This needs peer review.
Comment #9
euk commentedSame patch but for @alpha4 version
Comment #10
gnugetI worked on this today, basically, if the user hasn't permission to edit the value of a specific field then it shouldn't be allowed to user the route that return the results of the autocomplete either.
So, if no permission is granted for the field then
https://test.com/file/reference/node/article/field_test?q=testshould return forbidden.I used this code in a custom module to test that behavior:
I made a few changes to #8, basically I injected the service instead to use the global namespace, I did this so I can write a small test to make sure that the access check only pass if the user is allowed to edit the field.
Patch attached.
Thanks!
Comment #12
gnugetThanks for all the help with this one :-)
I just pushed the changes.
David.