开发者

rails declarative authorization, permit all actions for controller?

开发者 https://www.devze.com 2023-02-01 01:23 出处:网络
using the delcarative_authorization gem for rails, is there a shortcut to allow a role access to all controller actions?

using the delcarative_authorization gem for rails, is there a shortcut to allow a role access to all controller actions?

privileges do
  # default privi开发者_如何学Golege hierarchies to facilitate RESTful Rails apps
  privilege :manage, :includes => [:create, :read, :update, :delete]
end

isn't sufficient, because I have more controlling methods than just CRUD in my controllers.

Something like:

  role :foo do
    has_permission_on :bar, :to =>[:all]
  end

would be perfect, but I'm not finding it in the docs.


I don't think an easy way exists. This thread discusses one possible approach: to check for the "master" role and bypass filtering altogether.


I use something like this:

privileges do
  # default privilege hierarchies to facilitate RESTful Rails apps
  privilege :manage, :includes => [:create, :read, :update, :delete]
  method_names =  Bar.action_methods.to_a
  meths = method_names - %w{create read update delete}
  privilege :all_others, :includes => meths.map{|m| m.to_sym}
end

role :foo do
  has_permission_on :bar, :to =>[:manage,:all_others]
end

although something like:

privileges do
  # default privilege hierarchies to facilitate RESTful Rails apps
  privilege :manage, :includes => [:create, :read, :update, :delete]
  privilege :all, :includes => Bar.action_methods
end

role :foo do
  has_permission_on :bar, :to =>[:all]
end

might suit your requirements better

0

精彩评论

暂无评论...
验证码 换一张
取 消