I'm new to Symfony2, and for the needs of my company I'm using Sonata Admin and User bundles.
I would like to know if it is possible to hide or show items on the dashboard according to the role of a logged user.
For example, I have several entities which are managed by Sonata AdminBundle (user, company, mission, site, etc ... management) and I want to display the user management only to the super Admin, company and site management to another role (SITE_ADMIN for example) and missions to a third role.
Have you ever faced this situation ? Could you give me the solution or clues to go directly to the solution ?
Many thanks,
Enes
Use Role handler and enable User related rights only to, for example, Admins group (create it). Then assign admin users to Admins group. Sonata Admin will pick up restrictions and will only display dashboard items to Admins.
In addition you can hide and display blocks in the userboard this way:
# app/config/config.yml
sonata_admin:
dashboard:
groups:
acme.admin.group.content:
label: acme.admin.group.content
label_catalogue: AcmeDemoBundle
items:
- sonata.admin.post
acme.admin.group.blog:
items: ~
item_adds:
- sonata.admin.page
roles: [ ROLE_ONE, ROLE_TWO ]
acme.admin.group.misc: ~
As mentioned in the docs.
Please note that this only changes the visibility of a block, not the accessability. If there are no restrictions people could still open the link in the browser if they know it.
If you use the previous answer implementing the sonata.admin.security.handler.role the block should be automatically hidden if the user does not have the correct role.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With