How to filter the instances of an entity that a user can see in Sonata Admin

1.9k views Asked by At

I have an entity "Vehicles" which has ManyToOne connection with another entity - "Department". I could set "department" property to a user. I would like this user (who has ROLE_DEPARTMENT_MANAGER role), to be able to see (list, create, delete, etc.) only the vehicles from his own department.

When using Roles I could restrict access to specific actions. I think I should use ACL, but I am not sure how to do it and how Sonata Admin will behave.

I found similar question here, but nobody had answer it: Sonata Admin Bundle filter show entity from role user

Would you tell me how to do it in Sonata Admin Bundle.

1

There are 1 answers

0
Ioana Hazsda On

You can customize the query used to generate the list in your VehicleAdmin class:

http://sonata-project.org/bundles/admin/master/doc/reference/action_list.html#customizing-the-query-used-to-generate-the-list