Module: Authority::Controller::ClassMethods

Defined in:
lib/authority/controller.rb

Instance Method Summary collapse

Instance Method Details

#authority_action(action_map) ⇒ Object

Allows defining and overriding a controller’s map of its actions to the model’s authorizer methods

Parameters:

  • action_map (Hash)
    • controller actions and methods, to be merged with existing action_map



37
38
39
# File 'lib/authority/controller.rb', line 37

def authority_action(action_map)
  authority_action_map.merge!(action_map.symbolize_keys)
end

#authority_action_mapHash

The controller action to authority action map used for determining which Rails actions map to which authority actions (ex: index to read)

Returns:

  • (Hash)

    A duplicated copy of the configured controller_action_map



45
46
47
# File 'lib/authority/controller.rb', line 45

def authority_action_map
  @authority_action_map ||= Authority.configuration.controller_action_map.dup
end

#authorize_actions_for(model_class, options = {}) ⇒ Object

Sets up before_filter to ensure user is allowed to perform a given controller action

ones and any other options applicable to a before_filter

Parameters:

  • model_class (Class)
    • class whose authorizer should be consulted

  • options (Hash) (defaults to: {})
    • can contain :actions to be merged with existing



28
29
30
31
32
# File 'lib/authority/controller.rb', line 28

def authorize_actions_for(model_class, options = {})
  self.authority_resource = model_class
  authority_action(options[:actions] || {})
  before_filter :run_authorization_check, options
end