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

hasRole for comparison against multiple roles #1209

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Notanotherdotcom
Copy link

I always get caught out by hasRole not being able to support multiple roles, so this should add support for a PageArray or a pipe-delimited string of role names or IDs.

Not thoroughly tested, but should work.

I always get caught out by hasRole not being able to support multiple roles, so this should add support for a PageArray or a pip-delimited string of role names or IDs.
@LostKobrakai
Copy link

Currently it's just checking for a single available role per multi value. I don't think that's intended. Shouldn't all given roles match before the function does return true?

Also I think the core functionality of your additions should be added deeper down the hierarchy at PageArray::has , which does also only accept single values by now. This way the api would stay more consistent as both functions get the new multi value feature at the same time. Maybe WireArray::has should get that, too, but I think that's not as popular as PageArray::has.

@Notanotherdotcom
Copy link
Author

I think you're right, but it should be all (hasRole, PageArray::has and WireArray::has) or none in my opinion for the sake of consistency.

@Notanotherdotcom
Copy link
Author

And no, ANY one role should match for it to return true (at least in the case of | piped values which was my main requirement). So if ($this->user->hasRole('superuser|admin|something') { should return true if any match.

@LostKobrakai
Copy link

But I think this would be confusing, because for the PageArray case I'd expect it to match all of them.

For the OR variant this is more obvious: $user->roles->has("name=admin|superuser")

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

Successfully merging this pull request may close these issues.

2 participants