0

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?

user3440145
  • 793
  • 10
  • 34
  • 1
    this is a very broad question with - so far - no observable effort (i.e. code) from your side, and will probably be closed. encapsulate file functions in a service, take care only that service accesses the data folder, the service can obviously request the user token per dependency injection in its constructor. for additional library tips etc., stackoverflow is the wrong site. – Jakumi Apr 08 '20 at 12:02

1 Answers1

0

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 a many to one relation between user and directory entity. This relation maps the directory with his owner

  • If each user have a directory, you can create it directly when the user is created.
  • If the user can have no directory, you can create the directory only when he decide to create one.
  • If a user can have multiple directories (many to many relation) you have to create the directory each time a user decide to create one.

In 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

  • I think this relation should be many to many because obviously in your case a user can access many directories and directories can be accessed by many users

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