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

Problem with method check? in the policy #113

Closed
delavaler opened this issue Apr 24, 2020 · 4 comments
Closed

Problem with method check? in the policy #113

delavaler opened this issue Apr 24, 2020 · 4 comments

Comments

@delavaler
Copy link

delavaler commented Apr 24, 2020

Tell us about your environment

Ruby Version: 2.7.1p83

Framework Version (Rails, whatever): Rails 6.0.2.2

Action Policy Version: action_policy (0.4.3)

Reproduction Script: https://github.com/delavaler/script/blob/master/check_bug.rb

What did you do?

@palkan Hi
I want to check in the policy the rule from another policy, using this instruction https://actionpolicy.evilmartians.io/#/writing_policies?id=calling-other-policies

When check? should return true it works fine

When check? should return false I get error <NoMethodError: undefined method reasons' for nil:NilClass>`

in the 192 line gems/ruby-2.7.1/gems/action_policy-0.4.3/lib/action_policy/policy/reasons.rb:189 ActionPolicy::Policy::Reasons#allowed_to?:

@palkan
Copy link
Owner

palkan commented Apr 27, 2020

Thanks for the reproduction! I'll take a look and come back with a fix.

@palkan palkan added bug Something isn't working and removed bug Something isn't working labels Apr 27, 2020
@palkan
Copy link
Owner

palkan commented Apr 27, 2020

Fixed in master.

Just a reminder, that this is not a designed way of calling policy rules. You should use apply(rule_name) instead of calling method directly unless you know what are you doing)

@palkan palkan closed this as completed Apr 27, 2020
@delavaler
Copy link
Author

Thank you!

@austenmadden
Copy link

@palkan 😕 what if you want to account for alias_rule? apply does not factor in the aliases while authorize! and allowed_to? (and check?) do. This has come up when writing tests for policies.

To get around this issue without the fix in master I've been writing my_policy.apply my_policy.resolve_rule(:my_rule?). However, that feels dirtier than using allowed_to? directly.

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

3 participants