Module: Consent::Authorizable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/consent/authorizable.rb
Instance Method Summary collapse
-
#grant(subject:, action:, view:) ⇒ Object
Grants a permission to a role, replacing any existing permission for the same subject/action pair:.
-
#grant_all(permissions, replace: false) ⇒ Object
Grants all permissions in o permissions hash formatted as:.
-
#grant_all!(*args, **kwargs) { ... } ⇒ Object
Destructive form of #grant_all.
Instance Method Details
#grant(subject:, action:, view:) ⇒ Object
Grants a permission to a role, replacing any existing permission for the same subject/action pair:
‘grant` only grants valid permissions:
‘grant` also does not persist the given permissions, so the caller must #save! the role
76 77 78 |
# File 'app/models/concerns/consent/authorizable.rb', line 76 def grant(subject:, action:, view:) ::Consent::Permission.new(subject: subject, action: action, view: view) end |
#grant_all(permissions, replace: false) ⇒ Object
Grants all permissions in o permissions hash formatted as:
‘{ <subject> => { <action> => <view> } }`
When ‘replace: true`, it mark all existing permisions for destruction
‘grant_all` will only keep valid permissions, this excludes any permisison that grants nothing (:no_access)
33 34 35 36 37 38 |
# File 'app/models/concerns/consent/authorizable.rb', line 33 def grant_all(, replace: false) changed = self. .from_hash() .map { || () } (self. - changed).each(&:mark_for_destruction) if replace end |
#grant_all!(*args, **kwargs) { ... } ⇒ Object
Destructive form of #grant_all. This methods grants all the given permissions and persists it to the database atomically
46 47 48 49 50 51 52 53 |
# File 'app/models/concerns/consent/authorizable.rb', line 46 def grant_all!(*args, **kwargs) transaction do grant_all(*args, **kwargs) tap(&:save!) touch yield if block_given? end end |