Class: Fosm::RoleAssignment
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Fosm::RoleAssignment
- Defined in:
- app/models/fosm/role_assignment.rb
Overview
Persists an actor’s role on a FOSM resource.
Scopes:
resource_id: nil → type-level ("Alice is an :approver for ALL Fosm::Invoice records")
resource_id: "42" → record-level ("Alice is an :approver for Fosm::Invoice #42 only")
Role names must match those declared in the model’s lifecycle access block. This model does NOT validate role names against the lifecycle (it would create a hard coupling between DB state and code). Invalid role names simply have no effect at runtime because Fosm::Current.roles_for returns them but no permission grants will ever include them.
Instance Method Summary collapse
-
#actor ⇒ Object
Try to resolve the actor object (may return nil if class no longer exists).
-
#actor_label ⇒ Object
Human-readable display label for the actor.
- #record_level? ⇒ Boolean
- #scope_label ⇒ Object
- #type_level? ⇒ Boolean
Instance Method Details
#actor ⇒ Object
Try to resolve the actor object (may return nil if class no longer exists)
36 37 38 39 40 |
# File 'app/models/fosm/role_assignment.rb', line 36 def actor user_type.constantize.find_by(id: user_id) rescue NameError nil end |
#actor_label ⇒ Object
Human-readable display label for the actor
43 44 45 46 47 |
# File 'app/models/fosm/role_assignment.rb', line 43 def actor_label a = actor return "#{user_type}##{user_id}" unless a a.respond_to?(:email) ? a.email : a.to_s end |
#record_level? ⇒ Boolean
49 50 51 |
# File 'app/models/fosm/role_assignment.rb', line 49 def record_level? resource_id.present? end |
#scope_label ⇒ Object
57 58 59 |
# File 'app/models/fosm/role_assignment.rb', line 57 def scope_label record_level? ? "#{resource_type}##{resource_id}" : "all #{resource_type.demodulize.pluralize}" end |
#type_level? ⇒ Boolean
53 54 55 |
# File 'app/models/fosm/role_assignment.rb', line 53 def type_level? resource_id.nil? end |