rails declarative authorization, permit all actions for controller?
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
精彩评论