hasRole for comparison against multiple roles#1209
hasRole for comparison against multiple roles#1209Notanotherdotcom wants to merge 1 commit intoryancramerdesign:masterfrom
Conversation
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.
|
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. |
|
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. |
|
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. |
|
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: |
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.