Module: Eaco::Controller::ClassMethods
- Defined in:
- lib/eaco/controller.rb
Overview
Controller authorization DSL.
Instance Method Summary collapse
-
#authorization_permissions ⇒ Object
protected
Permission requirements configured on this controller.
-
#authorize(*actions) ⇒ Object
Defines the ability required to access a given controller action.
-
#permission_for(action) ⇒ Symbol
The permission required to access the given action.
Instance Method Details
#authorization_permissions ⇒ Object (protected)
Permission requirements configured on this controller.
67 68 69 |
# File 'lib/eaco/controller.rb', line 67 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.
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/eaco/controller.rb', line 45 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
Returns the permission required to access the given action.
59 60 61 |
# File 'lib/eaco/controller.rb', line 59 def (action) [action] || [:all] end |