Module: Authority::Controller::ClassMethods
- Defined in:
- lib/authority/controller.rb
Instance Method Summary collapse
- #authority_action(action_map) ⇒ Object
-
#authority_action_map ⇒ Hash
The controller action to authority action map used for determining which Rails actions map to which authority actions (ex: index to read).
-
#authority_actions(action_map) ⇒ Object
Allows defining and overriding a controller’s map of its actions to the model’s authorizer methods.
-
#authorize_actions_for(resource_or_finder, options = {}) ⇒ Object
Sets up before_filter to ensure user is allowed to perform a given controller action.
-
#ensure_authorization_performed(options = {}) ⇒ Object
Convenience wrapper for instance method.
Instance Method Details
#authority_action(action_map) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/authority/controller.rb', line 57 def (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(' ') (action_map) end |
#authority_action_map ⇒ Hash
The controller action to authority action map used for determining which Rails actions map to which authority actions (ex: index to read)
76 77 78 |
# File 'lib/authority/controller.rb', line 76 def ||= Authority.configuration.controller_action_map.dup end |
#authority_actions(action_map) ⇒ Object
Allows defining and overriding a controller’s map of its actions to the model’s authorizer methods
53 54 55 |
# File 'lib/authority/controller.rb', line 53 def (action_map) .merge!(action_map.symbolize_keys) end |
#authorize_actions_for(resource_or_finder, options = {}) ⇒ Object
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 |
# File 'lib/authority/controller.rb', line 44 def (resource_or_finder, = {}) self. = resource_or_finder ([:actions] || {}) before_filter :run_authorization_check, end |
#ensure_authorization_performed(options = {}) ⇒ Object
Convenience wrapper for instance method
66 67 68 69 70 |
# File 'lib/authority/controller.rb', line 66 def ( = {}) after_filter(.slice(:only, :except)) do |controller_instance| controller_instance.() end end |