Class: Authz::Role
- Inherits:
-
Authz.selfself::ApplicationRecord
- Object
- Authz.selfself::ApplicationRecord
- Authz::Role
- Defined in:
- app/models/authz/role.rb
Overview
Represents a role within the application
Instance Method Summary collapse
-
#cached_granted_keyword_for(scopable) ⇒ String
Cached version of #granted_keyword_for.
-
#cached_has_permission?(controller_name, action_name) ⇒ Boolean
Cached version of has_permission?.
-
#granted_keyword_for(scopable) ⇒ String
The applicable keywords according to the role’s scoping rule for the given scopable.
-
#has_permission?(controller_name, action_name) ⇒ Boolean
True if the role has access to the given controller action.
Instance Method Details
#cached_granted_keyword_for(scopable) ⇒ String
Cached version of #granted_keyword_for
70 71 72 73 74 |
# File 'app/models/authz/role.rb', line 70 def cached_granted_keyword_for(scopable) Authz.cache.fetch([cache_key, scopable.to_s]) do granted_keyword_for(scopable) end end |
#cached_has_permission?(controller_name, action_name) ⇒ Boolean
Cached version of has_permission?
49 50 51 52 53 |
# File 'app/models/authz/role.rb', line 49 def (controller_name, action_name) Authz.cache.fetch([cache_key, controller_name, action_name]) do (controller_name, action_name) end end |
#granted_keyword_for(scopable) ⇒ String
Returns the applicable keywords according to the role’s scoping rule for the given scopable.
61 62 63 |
# File 'app/models/authz/role.rb', line 61 def granted_keyword_for(scopable) scoping_rules.find_by!(scopable: scopable.to_s).keyword end |
#has_permission?(controller_name, action_name) ⇒ Boolean
Returns true if the role has access to the given controller action.
42 43 44 |
# File 'app/models/authz/role.rb', line 42 def (controller_name, action_name) controller_actions.exists?(controller: controller_name, action: action_name) end |