[英]Declarative_Authorization nested rules
My models are setup as 我的模型设置为
Film :has_many :sections
Section :belongs_to :film
within my authorization_rules.rb I have 在我的authorization_rules.rb中
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. 在编辑影片时效果很好,因为它们是影片中的user_id字段。
Can I nest rules for :sections within the has-permission-on do block? 我可以在has-permission-on内嵌套:sections的规则吗? 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. 部分中没有user_id,因此我不愿添加一个,因为如果该部分属于一部已经拥有一部的电影,这似乎是多余的。
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.