Module: Opro::Controllers::Concerns::Permissions
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationControllerHelper
- Defined in:
- lib/opro/controllers/concerns/permissions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #add_oauth_required_permission(permission) ⇒ Object
-
#global_oauth_required_permissions ⇒ Object
By default :write permission is required if included in Opro.request_permissions returns Array.
-
#oauth_client_can_write? ⇒ Boolean
Returns boolean if client has been granted write permissions or request is a ‘GET’ returns true.
- #oauth_client_has_permission?(permission) ⇒ Boolean
-
#oauth_client_has_permissions? ⇒ Boolean
Checks to make sure client has given permission permission checks can be extended by creating methods oauth_client_can_:method? so to over-write a default check for :write permission, you would need to define oauth_client_can_write?.
-
#oauth_required_permissions ⇒ Object
returns Array of permissions required for controller action.
- #skip_oauth_required_permission(permission) ⇒ Object
- #skip_oauth_required_permissions ⇒ Object
Instance Method Details
#add_oauth_required_permission(permission) ⇒ Object
24 25 26 27 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 24 def () @oauth_required_permissions ||= @oauth_required_permissions << end |
#global_oauth_required_permissions ⇒ Object
By default :write permission is required if included in Opro.request_permissions returns Array
6 7 8 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 6 def [:write] & Opro. end |
#oauth_client_can_write? ⇒ Boolean
Returns boolean if client has been granted write permissions or request is a ‘GET’ returns true
56 57 58 59 60 61 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 56 def oauth_client_can_write? return false unless oauth_access_grant.present? return true if env['REQUEST_METHOD'] == 'GET' return true if oauth_access_grant.can?(:write) false end |
#oauth_client_has_permission?(permission) ⇒ Boolean
44 45 46 47 48 49 50 51 52 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 44 def () = "oauth_client_can_#{}?".to_sym if respond_to?() = method().call else = oauth_access_grant.can?(.to_sym) end end |
#oauth_client_has_permissions? ⇒ Boolean
Checks to make sure client has given permission permission checks can be extended by creating methods oauth_client_can_:method? so to over-write a default check for :write permission, you would need to define oauth_client_can_write?
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 33 def return false unless oauth_access_grant.present? = [] .each do || << () end return true unless .include?(false) false end |
#oauth_required_permissions ⇒ Object
returns Array of permissions required for controller action
11 12 13 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 11 def (@oauth_required_permissions || ) - end |
#skip_oauth_required_permission(permission) ⇒ Object
19 20 21 22 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 19 def () @skip_oauth_required_permissions << @skip_oauth_required_permissions end |
#skip_oauth_required_permissions ⇒ Object
15 16 17 |
# File 'lib/opro/controllers/concerns/permissions.rb', line 15 def @skip_oauth_required_permissions ||= [] end |