Module: NexusCqrs::Auth::Ownable
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/nexus_cqrs/auth/ownable.rb
Overview
Concern used to integrate models to the permissions system. Including this module to a model will assume the model can be “owned” by a user. When the model is created, permissions will automatically be assigned to the user and permissions can be validated and “repaired” retroactively.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
Instance Method Details
#assign_permissions ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/nexus_cqrs/auth/ownable.rb', line 29 def # As we are doing this on before_create, we must "build" this association, as opposed to creating it. This # ensures validation is passed before saving this parent Collection. .each do |p| unless .where(permission: p, entity_id: id, user_id: owner_id).exists? .build(user_id: owner_id, permission: p) end end end |
#owner_id ⇒ Object
39 40 41 |
# File 'lib/nexus_cqrs/auth/ownable.rb', line 39 def owner_id send(owner_column) end |
#permissions ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/nexus_cqrs/auth/ownable.rb', line 43 def if respond_to?() return send() end raise OwnableRelationshipNotSet, "Permissions relation not set. Set it on your model with `self.permissions_relation = :xxx_permissions`, and ensure relationship has been created" end |