8000 [Form] Add a new field type for managing Roles · Issue #10212 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
8000

[Form] Add a new field type for managing Roles #10212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jameshalsall opened this issue Feb 6, 2014 · 7 comments
Closed

[Form] Add a new field type for managing Roles #10212

jameshalsall opened this issue Feb 6, 2014 · 7 comments

Comments

@jameshalsall
Copy link
Contributor

Something that I think is lacking at the moment is an out-of-the-box "roles" form field type. This would provide the sole purpose of managing an array of roles. The role values could be either strings or \Symfony\Component\Security\Core\Role\RoleInterface instances (with this PR I opened a few days ago making comparisons between the two a little easier).

I would expect that this is a common problem that people have to tackle in their Symfony applications, and if we didn't want it as part of the core Form component we could provide it as part of the Symfony\Bridge.

As a set of high level requirements the field could:

  • Allow the granting / removal of roles (defined by a role hierarchy) to a user
  • Prevent users from granting / removing roles that they themselves do not have (optionally)
  • Extend the choice field type

Something has already been achieved in SonataUserBundle here and I implemented a similar solution in one of my own projects last week.

Is this something that would be of use in the Symfony standard distribution?

cc / @webmozart

@bigfoot90
Copy link

Add an option to select only roles reachable by current user using security.role_hierarchy service.

An admin should be able to create users,
and maybe other admin users if business logic permits it.
An admin should not be able to create users with super_admin role.

@Glideh
8000
Copy link
Glideh commented Sep 16, 2016

This would be useful.
I'm implemeting this same RoleType in all my projects.
Maybe it could be a small cookbook for example.

@jameshalsall
Copy link
Contributor Author

If you have any example implementations you can share that would be great, I'm planning on implementing this over the coming weeks.

@apfelbox
Copy link
Contributor

I guess the first thing that should be done is implementing a proper role system. Currently symfony itself doesn't know anything about the available roles, it just knows what roles a user has.

The role hierarchy isn't complete in this regard: roles outside the hierarchy aren't defined anywhere in symfony.

See #17892 for a related discussion, about RoleProviders. This would need to be added before we can add the form type.

@Glideh
Copy link
Glideh commented Sep 16, 2016

I'm personally using as convention to always list all roles in the hierarchy, even those with no child.
I'll paste my formType here depending on this convention.

8000
@jameshalsall
Copy link
Contributor Author

Symfony's security bundle would provide the hierarchy through the component... \Symfony\Component\Security\Core\Role\RoleHierarchyInterface. They would have to be part of the hierarchy for the field to be able to handle them, I agree with @Gildeh in this regard.

@xabbuh
Copy link
Member
xabbuh commented Sep 23, 2018

I am closing here as implementing such a form type requires a list of all possible roles which is not provided by the Security component.

@xabbuh xabbuh closed this as completed Sep 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants
0