jay.pepper
jay.pepper

Reputation: 17

Creation of roles in fosUserBundle

I currently have ROLE_ADMIN: ROLE_USER and ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH] and I wanted to add a new role with permissions between normal user and admin. I'm completely new to symfony in general and I read some documentation about it, but I just can't understand the process of creating a new role. First things first: should I do

ROLE_ADMIN: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH, ROLE_NEW_ROLE]

or

ROLE_ADMIN: ROLE_USER
ROLE_NEW_ROLE: ROLE_USER
ROLE_SUPER_ADMIN: [ROLE_ADMIN, ROLE_ALLOWED_TO_SWITCH]

And second: Besides this change in security.yml, in what files do I need to change something in order to just complete the creation of a role (not talking about give specific permissions to this new role yet).

I don't know if this is a stupid question, but I'm fairly lost.

Upvotes: 0

Views: 394

Answers (1)

Le Menach Florian
Le Menach Florian

Reputation: 462

Welcome to the Symfony community!

To put it simply, the definition of roles and the hierarchy are totally different.

You can define different roles for your users without specifying them in your project. With the promote / demote command, for example:

php app/console fos:user:promote
php app/console fos:user:demote

On the other hand, if you want to create a hierarchy between User and Admin, you can assign the user member privileges:

role_hierarchy:
    ROLE_NEW_ROLE: ROLE_USER
    ROLE_ADMIN: ROLE_NEW_ROLE

That's all !

Upvotes: 2

Related Questions