-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
[8.x] Adds on-demand gate authorization #39789
[8.x] Adds on-demand gate authorization #39789
Conversation
Help pls Docker decided to die. |
Can someone help me re-run the jobs? |
@DarkGhostHunter done |
Tx |
Renamed to I have a concern with the behavior of the callback in regards to the currently authenticated user. Currently, it functions differently than typical gates. Typically, a gate will automatically throw an authorization exception if no user is authenticated unless the given gate or policy method has a nullable type hint on the user. However, this PR will just pass IMO it should function exactly like a typical gate if you pass a callback to the |
Converting to draft while you potentially address this. Please mark as ready for review when you would like me to look at this PR again. |
I reworked the method to always throw an exception if the callback requires the authenticated user and there is none. I thought a This will return an // No user authenticated
Gate::allowIf(function (Authenticatable $user) {
return true;
}, 'Do not');
// AuthorizationException: "Do not". |
I find passing an |
Can I just create a “onDemand” protected method and use allowIf and denyIf as the fronts?
Not a fan of copy pasting anything.
Italo Baeza C.
… El 02-12-2021, a la(s) 11:00, Taylor Otwell ***@***.***> escribió:
I find passing an $allow flag as the last parameter of allowIf utterly confusing. Please remove that and just duplicate some code if you have to between the two methods. It makes them both much easier to read.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Thanks for contributing to Laravel! ❤️ |
You rock dude. If I wasn’t for you, I would probably be stealing on the streets.
Italo Baeza C.
… El 02-12-2021, a la(s) 18:22, Taylor Otwell ***@***.***> escribió:
Thanks for contributing to Laravel! ❤️
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
What?
Allows the gate to permit or forbid a procedure by a condition, instead of using the gate to register a one-time ability or using verbose checks. Rework of #39778.
Before
After
Why?
Because you can bypass registering an action in the Gate, without abandoning the Gate powers. For example, you can also issue callbacks to retrieve the currently authenticated user and even set a message...
... or hijack the callback with a
Response
instance anytime.BC?
Nope, only additive.