Skip to content
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

Problems with RestoreRolesTransformer #469

Closed
vstrizhenok opened this issue Sep 11, 2014 · 4 comments
Closed

Problems with RestoreRolesTransformer #469

vstrizhenok opened this issue Sep 11, 2014 · 4 comments

Comments

@vstrizhenok
Copy link

line 67 must contain this line
$hiddenRoles = array_diff($this->originalRoles, array_merge($availableRoles, array_keys($availableRoles)));

because in case when used hierarhical roles, the transformer works wrong. Admin user can't edit another users with some roles that he (admin) has throw hierarchy.
For example we need to add/remove role ROLE_COMPANY_PERSONAL_MODERATOR to the user Pete. Our admin has role ROLE_COMPANY_ADMIN that contains ROLE_COMPANY_PERSONAL_MODERATOR. So, when we try to do this we will fail because variable $availableRole contains line 'ROLE_COMPANY_ADMIN: ROLE_COMPANY_PERSONAL_MODERATOR' (it is wrong, because array must contains role NAME!). But the variable $this->originalRoles contains line 'ROLE_COMPANY_PERSONAL_MODERATOR' (it is right). So, in the result of the array_diff execution we have wrong result, that role 'ROLE_COMPANY_PERSONAL_MODERATOR' is hidden.

So I suggest to use array_key instead values (if this transformer used only for form type sonata_security_roles) or merge array_keys of the $avaliableRoles array with its values in another case.

@rande
Copy link
Member

rande commented Sep 11, 2014

Can you send a PR with a related unit test ?

@ElectricMaxxx
Copy link

this one isn't a bug in the hierarchie it is a question of the form creation:

https://github.com/sonata-project/SonataUserBundle/blob/master/Admin/Model/UserAdmin.php#L189

the editing of roles of other users does not depend on the own role, on the role of the subject instead.

But sound insane for me.

@vstrizhenok
Copy link
Author

Sorry, ElectricMaxxx. But this question does not touch the line 189 of the UserAdmin class, but sonata_security_roles form type instead. And as a result - RestoreRolesTransformer

vstrizhenok added a commit to vstrizhenok/SonataUserBundle that referenced this issue Sep 12, 2014
vstrizhenok added a commit to vstrizhenok/SonataUserBundle that referenced this issue Sep 13, 2014
@pamuche
Copy link

pamuche commented Jul 29, 2015

fixed & merged in master: #522

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants