-
-
Notifications
You must be signed in to change notification settings - Fork 92
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
Accessing a reason from a nested allowed_to?
#186
Comments
See: https://github.com/brendon/action_policy/tree/broken_reasons EDIT: Sorry, the test was wrong. This correctly shows that a |
That's a correct current behavior: Maybe, we can add an experimental option |
Hi @palkan, I understand your reasoning. I guess there's a tension here between being able to delegate allowance logic and the granular reporting of failure reasons. I had another case where I wanted to take action (redirect a user to a password entry screen when they tried to access something that was password protected (this can be indirectly by any of its ancestors so it's a check on another policy). I ended up with this
because the details do bubble up I was able to catch this at the exception layer and do a redirect to that passworded parent. I guess this is mildly inconsistent given the reason won't bubble. There's kind of two situations here. One is just a failure of a check (boolean) when say |
Yeah, probably; through details were added exactly to allow adding global metadata.
That would make One of the reasons for the current reasons behavior is the following use-case I had: using
Seems so.
What about adding one more helper (in addition to |
Thanks @palkan, that does sound like a good idea (a third helper). I think if it's documented carefully and named well then the confusion should hopefully be minimal. What the name should be? Hard to say. |
Yeah, that's tricky; now I think that adding an option was a better idea 🙂 Maybe, more explicit one, say, And I have one more idea: |
The option idea is probably better because it allows one to chose to delegate or not per call. To be able to return the hierarchy of reasons might also be handy but also a bit convoluted to find a specific reason arbitrarily nested within others. |
Hey @brendon! Please, take a look at the PR) |
Thanks @palkan. Would it be possible to do a new gem release so I can give this and the bug fix a whirl? :) |
Yes, I'm currently preparing the v0.6.0 |
Not sure if it was intentional, but this change obliterates details:
would only return I found a workaround was to call:
Unsure if this requires more looking into though? |
Yeah, looks confusing (or not 🙂, the whole |
Haha yea, now I have about 20 |
Yeah, I think we can add it, wouldn't hurt 🙂 |
Hi @palkan, as I've begun to use this more, and to catch the
Worse if I've passed up an object to take action upon from the
I think I'm making sure I have a All that is so say I'm wondering now whether it'd be cleaner for Of course I could just |
Just to follow this up, I've managed to simplify things with pattern matching:
|
Oh, the pattern matching example looks good 👍 ! Have you considered all_details? I think, it's much closer to the "raise" idea (though you need to figure out how to name possible reasons). |
Haha, I know right?! I always wondered what pattern matching would be good for and never really understood the hype, but I see the point now.
I think I'm pretty happy with the state of things now. The only other nice-to-have would be the option to |
Discussed in #185
Originally posted by brendon August 29, 2021
I have something like this:
When I call
authorize! my_instance, to: :view?, with: InstancePolicy
on a deletedcomponent_instance
and inspect the exception:exception.result.reasons
I get:What I really want is
:deleted
for the reason so that I can provide a nice error message.Is there a way to do this?
The text was updated successfully, but these errors were encountered: