Wildcard permissions are very confusing. #1756
martinsnajdr
started this conversation in
General
Replies: 2 comments 3 replies
-
Old post but I agree. ANY seems like a much more useful and common use case than ALL. Checking permissions for a multi level nav for example. At the moment this is arduous. Also seems odd to me that there is @hasanyrole blade directives but not for permissions when best practices states:
|
Beta Was this translation helpful? Give feedback.
2 replies
-
Read wildcard tests for examples, also you could overwrite and customize wildcard logic for doing it "less confusing" |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I find working with Wildcard permissions quite confusing to be honest.
Let's say I have an example app that has a navigation that display different types of "resources" as links. What I need is to display the links based on user permissions – if the user has any permission to somehow interact with the resource, I need to display the link.
So naturally I would use the Wildcard permission like this (for simple Create / Read / Update / Delete):
And then I would use can directive to display the menu item in blade (I know it's not working like that right now, but I think it should be considered):
This would the translate to – if the user has any permissions starting with 'resource', the user has the permission. I understand that the current functionality of Wildcard permissions is not random and that there are surely some reasons why it works like it works, but I found the documentation of Wildcard permissions very misleading.
Instead I have to do this (because the view permission is a "dependency" to other permissions, I can check just the view to display the menu item):
Let's say I have more complex example – where some roles can manage only their own resources. So I have few extra permissions:
Then I have to check it like this
Which works, but it doesn't use the simplicity of the Wildcards. Also what I find quite confusing is using permissions like this (example from docs):
What I have read in different github issue, I have to specifically create permission that has the same "name". I would expect it would work like this:
Like some kind of shorter version to give permissions to a role. Because then I could add different permission stack to different role using the same permissions.
And then use can directive like this
I don't say I'm right, but from my point of view, this is what I would expect the wildcards to work – to be really useful. Right now I can't really see how to write the whole
@canany(['resource.view', 'resource.own.view'])
more effectively using wildcards. Any tips?Beta Was this translation helpful? Give feedback.
All reactions