Module: Eaco::Controller::ClassMethods
- Defined in:
- lib/eaco/controller.rb
Overview
Controller authorization DSL.
Instance Method Summary collapse
-
#authorization_permissions ⇒ Hash
protected
Permission requirements configured on this controller, keyed by permission symbol and with role symbols as values.
-
#authorize(*actions) ⇒ Object
Defines the ability required to access a given controller action.
-
#permission_for(action) ⇒ Symbol
Gets the permission required to access the given
action, falling back on the default:allaction, ornilif no permission is defined.
Instance Method Details
#authorization_permissions ⇒ Hash (protected)
Permission requirements configured on this controller, keyed by permission symbol and with role symbols as values.
85 86 87 |
# File 'lib/eaco/controller.rb', line 85 def @_authorization_permissions ||= {} end |
#authorize(*actions) ⇒ Object
Defines the ability required to access a given controller action.
Example:
class DocumentsController < ApplicationController
:index, [:folder, :index]
:show, [:folder, :read]
:create, :update, [:folder, :write]
end
Here @folder is expected to be an authorized Resource, and for the index action the current_user is checked to can?(:index, @folder) while for show, can?(:read, @folder) and for create and update checks that it can?(:write, @folder).
The special :all action name requires the given ability on the given Resource for all actions.
If an action has no authorization defined, access is granted.
Adds Eaco::Controller#confront_eaco as a before_filter.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/eaco/controller.rb', line 51 def (*actions) target = actions.pop actions.each {|action| .update(action => target)} @_eaco_filter_installed ||= begin before_filter :confront_eaco true end end |
#permission_for(action) ⇒ Symbol
Gets the permission required to access the given action, falling back on the default :all action, or nil if no permission is defined.
72 73 74 |
# File 'lib/eaco/controller.rb', line 72 def (action) [action] || [:all] end |