Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Allow getReachableRoles() to accept string array #23153

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
wants to merge 1 commit into from
Closed

Allow getReachableRoles() to accept string array #23153

wants to merge 1 commit into from

Conversation

pdugas
Copy link

@pdugas pdugas commented Jun 12, 2017

Q A
Branch? 3.4 or master / 2.7, 2.8, 3.2 or 3.3
Bug fix? yes/no
New feature? yes/no
BC breaks? yes/no
Deprecations? yes/no
Tests pass? yes/no
Fixed tickets #...
License MIT
Doc PR symfony/symfony-docs#...

@pdugas
Copy link
Author

pdugas commented Jun 12, 2017

My use case... I have traditional User entities with $roles array property. I have Project entities and a number of subordinate entities that "belong" to projects; i.e. Doc, Event, Note, etc. I have a ProjectUser entity that maps Projects and assigned Users. I have another $roles property in the ProjectUser entity that I use to grant additional per-Project roles to Users.

I have a Voter that accepts a Project entity. It's mimicking the stock role-hierarcy voter.

        $projUser = $this->em->getRepository('AppBundle:ProjectUser')
            ->findOneBy(['user'=>$user, 'project'=>$project]);
        if ($projUser) {
            $roles = array_merge(
                $user->getRoles(),
                $this->roleHierarchy->getReachableRoles($projUser->getRoles())
            );
        }

Without a change like the one proposed, I have to convert the array of strings returned by the ProjectUser.getRoles() method into an array of Role objects. Not the end of the world to do so but I think I've seen other places where one can pass a string or a Role object.

@xabbuh
Copy link
Member

xabbuh commented Jun 12, 2017

FYI, there is an attempt to completely get rid of the Role class (see #22048). And doing this change would involve the role hierarchy too.

@pdugas
Copy link
Author

pdugas commented Jun 12, 2017

Is the idea to just eliminate the Role class itself but still support the RoleHierarchy concept using just strings instead? Hope so. I find the hierarchy quite elegant.

@xabbuh
Copy link
Member

xabbuh commented Jun 12, 2017

Yes, there's no plan in dropping the role hierarchy concept. But we must of course adapt it if we were to remove the Role class.

@pdugas
Copy link
Author

pdugas commented Jun 12, 2017

Roger that. Thanks for the head's up. Do with this pull-request as you see fit. :)

@xabbuh
Copy link
Member

xabbuh commented Jun 14, 2017

Let's close here then. We can reconsider the decision if #22048 won't be merged.

By the way, please properly answer all the questions in the PR description when doing your next pull request. :) These values are used to automatically publish the labels here.

@xabbuh xabbuh closed this Jun 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants