Module: Authoreyes::Helpers::InController
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/authoreyes/helpers/in_controller.rb
Overview
This module handles authorization at the Controller level. It allows various actions within the controller to be configured to work with Authoreyes, only permitting access to that action if certain conditions are met, according to the defined Authorization Rules.
Instance Method Summary collapse
-
#filter_resource_access(options = {}) ⇒ Object
TODO: Implement this!.
-
#permitted_to!(privelege, object_or_symbol = nil, options = {}) ⇒ Object
Works similar to the permitted_to? method, but throws the authorization exceptions, just like Engine#permit!
privelegeis the symbol name of the privele checkedobject_or_symbolis the object the privelege is checked on. -
#permitted_to?(privelege, object_or_symbol = nil, options = {}) ⇒ Boolean
If the current user meets the given privilege, permitted_to? returns true and yields to the optional block.
- #redirect_if_unauthorized ⇒ Object
- #set_unauthorized_status_code ⇒ Object
Instance Method Details
#filter_resource_access(options = {}) ⇒ Object
TODO: Implement this!
16 17 18 |
# File 'lib/authoreyes/helpers/in_controller.rb', line 16 def filter_resource_access( = {}) end |
#permitted_to!(privelege, object_or_symbol = nil, options = {}) ⇒ Object
Works similar to the permitted_to? method, but throws the authorization exceptions, just like Engine#permit! privelege is the symbol name of the privele checked object_or_symbol is the object the privelege is checked on
63 64 65 66 67 |
# File 'lib/authoreyes/helpers/in_controller.rb', line 63 def permitted_to!(privelege, object_or_symbol = nil, = {}) Authoreyes::ENGINE.permit!( privelege, (object_or_symbol, , true) ) end |
#permitted_to?(privelege, object_or_symbol = nil, options = {}) ⇒ Boolean
If the current user meets the given privilege, permitted_to? returns true and yields to the optional block. The attribute checks that are defined in the authorization rules are only evaluated if an object is given for context.
See examples for Authorization::AuthorizationHelper #permitted_to?
If no object or context is specified, the controller_name is used as context. TODO: Use permit? instead of permit! privelege is the symbol name of the privele checked object_or_symbol is the object the privelege is checked on
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/authoreyes/helpers/in_controller.rb', line 48 def permitted_to?(privelege, object_or_symbol = nil, = {}) if Authoreyes::ENGINE.permit!( privelege, (object_or_symbol, , false) ) yield if block_given? true else false end end |
#redirect_if_unauthorized ⇒ Object
20 21 22 23 24 25 26 27 |
# File 'lib/authoreyes/helpers/in_controller.rb', line 20 def unless permitted_to? action_name session[:request_unauthorized] = true redirect_back fallback_location: root_path, status: :found, alert: 'You are not allowed to do that.' end end |
#set_unauthorized_status_code ⇒ Object
29 30 31 32 33 34 |
# File 'lib/authoreyes/helpers/in_controller.rb', line 29 def if session[:request_unauthorized] == true session.delete :request_unauthorized response.status = :forbidden end end |