-
-
Notifications
You must be signed in to change notification settings - Fork 90
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
Rule aliases in an inheriting policy don't override aliases in parent policies #18
Comments
Aliases should be overridable (see this test: https://github.com/palkan/action_policy/blob/master/test/action_policy/policy/aliases_test.rb#L52). Could you, please, provide the output for: |
irb(main):012:0> GroupPolicy.new(user: User.new).resolve_rule(:new?)
=> :index?
irb(main):013:0> GroupPolicy.new(user: User.new).resolve_rule(:create?)
=> :create? This is with defaults included in the ApplicationPolicy and this GroupPolicy: class GroupPolicy < ApplicationPolicy
def index?
true
end
alias_rule :new?, :create?, :edit?, :update?, to: :index?
end |
I tried the other routes for fun: irb(main):014:0> GroupPolicy.new(user: User.new).resolve_rule(:index?)
=> :index?
irb(main):015:0> GroupPolicy.new(user: User.new).resolve_rule(:edit?)
=> :index?
irb(main):016:0> GroupPolicy.new(user: User.new).resolve_rule(:update?)
=> :index?
irb(main):017:0> GroupPolicy.new(user: User.new).resolve_rule(:destroy?)
=> :default_rule
irb(main):018:0> GroupPolicy.new(user: User.new).resolve_rule(:show?)
=> :default_rule
|
If I remove defaults from irb(main):025:0> GroupPolicy.new(user: User.new).resolve_rule(:create?)
=> :index? |
I've hit this too. It seems the idea is that if a hard rule has been defined in a superclass, an |
Thanks for your work, guys. This is super helpful and I wouldn't have known where to start 😊 |
You're most welcome :) Now I know a lot about |
Tell us about your environment
Ruby Version:
2.4.3 (in Docker)
Framework Version (Rails, whatever):
Rails 5.2.0.rc2
Action Policy Version:
0.2.0
What did you do?
What did you expect to happen?
For
GroupPolicy#create?
to be aliased toGroupPolicy#new?
What actually happened?
GroupPolicy#create?
was actually still aliased toActionPolicy::Base#new?
(because of thealias_rule :create, to: :new?
inActionPolicy::Policy::Defaults
, I think) and so always returned false. The solution was to define anothercreate?
method that callednew?
explicitly.(Sorry, I accidentally submitted this before I'd finished it)
The text was updated successfully, but these errors were encountered: