简体   繁体   中英

Declarative_Authorization nested rules

My models are setup as

Film :has_many :sections

Section :belongs_to :film

within my authorization_rules.rb I have

role :author do
    has_permission_on :films, :to => [:edit. :update] do
      if_attribute :user => is {user}
    end
end

Which works fine when editing the film as their is a user_id field within film.

Can I nest rules for :sections within the has-permission-on do block? There is no user_id within sections, and I'd rather not add one as it seems redundant if the section belongs_to a film that already has one.

Yes you can nest them,

has_permission_on [:films], :to => [ :edit, :update] do
  if_attribute :user => is {user}
  has_permission_on :sections, :to => [:update, :edit]
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM