4

I'm using Symfony2 with Sonata.
I have a list of sections on my application to which I'd like to give access to my users.

Example:

  • John should have access to section1 and section3
  • Bob should have access to section2 and section3

So I created 3 roles, that I can attach to users/groups (through sonata)

  • ROLE_SECTION1
  • ROLE_SECTION2
  • ROLE_SECTION3

But as I create new sections, I'd like to have the related roles automatically listed in the admin
(without having to declare them each time in my security.yml)

I saw sonata-admin-user does that when using the role security handler,
but I don't know how to do the same.

Finally the question is simple and is the following:

How can I add some dynamic selectable roles into my Sonata user admin bundle editor list ?

Pierre de LESPINAY
  • 44,700
  • 57
  • 210
  • 307

1 Answers1

0

First you can load user and groups from your database. See Symfony2 cookbook Load user from database. Then in the controller of every section:

if ($this->securityContext->isGranted('Role_section1') === false) {
    echo 'forbidden';
}
Ry-
  • 218,210
  • 55
  • 464
  • 476
hahamy
  • 81
  • 3