In a symfony 5.0 application I need to integrate a filemanager that provides basic file handling for users.
Each user is only allowed to manage files in his specific user folder which (obviously) is not in the public folder but at some path like
../data/images/[user_id]/
The filemanager of my choice needs this one path as a parameter to do it's magic.
How can I define access rules in symfony to define this behaviour to grant access to a specific but dynamic path which depends on the currently logged in user?
You have to deal with that problem in your controller or in the file manager. You have to create a database schema which register the access rights per user and per directory.
You can create a
many to many
or amany to one
relation betweenuser
anddirectory
entity. This relation maps the directory with his ownerIn order to deal with the access rights you have to create a second relation between user and directory. This relation maps the directory with his users who can access to it
In order to know if a user can access a resource, the file manager will get the access rights from the database then either provide the file or return an error