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

Apply rule defaults and aliases more thoroughly? #79

Closed
jfouse opened this issue Sep 10, 2019 · 1 comment
Closed

Apply rule defaults and aliases more thoroughly? #79

jfouse opened this issue Sep 10, 2019 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@jfouse
Copy link

jfouse commented Sep 10, 2019

I'm wondering if there's a reason not to have Core#__apply__ call resolve_rule before public_send, like this:

def __apply__(rule)
  rule = resolve_rule(rule)
  public_send(rule)
end

This would support default rules and rule aliases across the board instead of just for controller actions, including calling check?/allowed_to? from within policies, policy.apply from anywhere, and supporting 3rd party gems (like ActiveAdmin) that may use their own mechanisms to authorize controller actions.

@palkan palkan added the discussion Let's talk label Sep 11, 2019
@palkan
Copy link
Owner

palkan commented Sep 11, 2019

Yep, there is a reason: to make direct policy usage explicit thus simplifying the policy classes themselves; we try to keep policy classes as PORO as possible and avoid any automagic inference/resolution.
And that's why we have a concept of behaviour: it acts as an adapter between the authorization context and the policy.

policy.apply from anywhere, and supporting 3rd party gems (like ActiveAdmin)

Ideally, you shouldn't call policy.apply directly, you should always use Behavior.

including calling check?/allowed_to? from within policies

That probably makes sense. Especially in the context of the failure reasons.

@palkan palkan added enhancement New feature or request and removed discussion Let's talk labels Jul 24, 2020
@palkan palkan added this to the 0.5.0 milestone Jul 24, 2020
@palkan palkan closed this as completed in 8a45ae2 Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants