Module: Authority::Controller::ClassMethods

Defined in:
lib/authority/controller.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) add_actions(action_map)

Adds the passed in actions to the current action map.

with the existing action map



87
88
89
# File 'lib/authority/controller.rb', line 87

def add_actions(action_map)
  authority_action_map.merge!(action_map)
end

- (Object) authority_action(action_map)



60
61
62
63
64
65
66
# File 'lib/authority/controller.rb', line 60

def authority_action(action_map)
  Authority.logger.warn "Authority's `authority_action` method has been renamed \
  to `authority_actions` (plural) to reflect the fact that you can \
  set multiple actions in one shot. Please update your controllers \
  accordingly. (called from #{caller.first})".squeeze(' ')
  authority_actions(action_map)
end

- (Hash) authority_action_map

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



79
80
81
# File 'lib/authority/controller.rb', line 79

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

- (Object) authority_actions(action_map)

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



54
55
56
57
58
# File 'lib/authority/controller.rb', line 54

def authority_actions(action_map)
  forced_action = action_map.delete(:all_actions)
  add_actions(action_map)
  force_action(forced_action) if forced_action
end

- (Object) authorize_actions_for(resource_or_finder, options = {})

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

should be consulted, or instance method on the controller which will determine that class when the request is made be merged with existing ones and any other options applicable to a before_filter



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

def authorize_actions_for(resource_or_finder, options = {})
  self.authority_resource = resource_or_finder
  add_actions(options.fetch(:actions, {}))
  force_action(options[:all_actions]) if options[:all_actions]
  before_filter :run_authorization_check, options
end

- (Object) ensure_authorization_performed(options = {})

Convenience wrapper for instance method



69
70
71
72
73
# File 'lib/authority/controller.rb', line 69

def ensure_authorization_performed(options = {})
  after_filter(options.slice(:only, :except)) do |controller_instance|
    controller_instance.ensure_authorization_performed(options)
  end
end

- (Object) force_action(forced_action)

Updates the current action map to use the forced action for all of it's actions.

for all Rails actions in the action map



96
97
98
99
100
# File 'lib/authority/controller.rb', line 96

def force_action(forced_action)
  add_actions(
    Hash[authority_action_map.map {|key, _| [key, forced_action] }]
  )
end