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

Overriding the inferred policy at controller level #35

Closed
brendon opened this issue Jul 27, 2018 · 2 comments · Fixed by #33
Closed

Overriding the inferred policy at controller level #35

brendon opened this issue Jul 27, 2018 · 2 comments · Fixed by #33

Comments

@brendon
Copy link
Contributor

brendon commented Jul 27, 2018

Currently the policy name is inferred from the controller class for authorize! and allowed_to? like so:

controller_name.classify.safe_constantize

There's no way to override this globally (per controller run) currently. Would you be open to adding this as a feature?

My use case is that I have a controller that is re-used in several contexts in the site. It is aware of its context, and depending on the context a different policy should be used. I can supply the context to authorise! easy enough with the :with option, but it's much harder to do so with the view helper allowed_to? because sometimes this method is called with helpers shared across wide areas of the application and rely on the inferred controller to function cleanly.

I thought about passing the context into the controllers inferred policy, then splitting out the policy check from there but didn't get too far.

@palkan
Copy link
Owner

palkan commented Jul 27, 2018

Would you be open to adding this as a feature?

This feature is already on its way as a part of scoping PR: https://github.com/palkan/action_policy/pull/33/files#diff-aa8298e81fa055d89f1eb689c5853fa9R79

@palkan palkan mentioned this issue Jul 27, 2018
6 tasks
@brendon
Copy link
Contributor Author

brendon commented Jul 27, 2018

Oh my goodness, talk about amnesia! I asked the same question twice! #32

Sorry! 😰

@brendon brendon closed this as completed Jul 27, 2018
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

Successfully merging a pull request may close this issue.

2 participants