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

Suggestion: Boolean logical operators #10

Open
fnoquiq opened this issue Jun 16, 2020 · 2 comments
Open

Suggestion: Boolean logical operators #10

fnoquiq opened this issue Jun 16, 2020 · 2 comments

Comments

@fnoquiq
Copy link
Contributor

fnoquiq commented Jun 16, 2020

Can I use boolean operators in the guard's middleware?

In the example below, when I separe resources with commas, that means an and operator.

Route
  .post('register', 'UserController.register')
  .middleware(['auth', 'guard: user.create, user.read'])

What could I do to trigger them using another operators, like or or not.

Something like this:

guard: user.create || user.read && post.create
@un-versed
Copy link
Member

Why you want to do this?

Can you give an example of case you want to do this?

@fnoquiq
Copy link
Contributor Author

fnoquiq commented Jun 22, 2020

This is usually a pattern that I see in another permissions packs.


For example, when I want to check if he has access to some of these two resources.

guard: user.create || post.create

In this case (above), you only need to have access to one of the resources to be allowed.


However, this (below) would need to have access to both resources to be allowed.

guard: user.create && post.create
guard: user.create, post.create

Another operator would be NOT. It would only give permission if the value of user.create was false instead of true.

guard: !(user.create)

Really, this one I don't think would be very useful. However, separating the logic of AND and OR would help a lot.

@fnoquiq fnoquiq changed the title Boolean logical operators Suggestion: Boolean logical operators Jun 25, 2020
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

2 participants