Module: CurrentScope::StorableKeys

Extended by:
ActiveSupport::Concern
Included in:
RoleAssignment, ScopedRoleAssignment
Defined in:
app/models/concerns/current_scope/storable_keys.rb

Overview

One definition of the #151 key policy, shared by both assignment models.

Since the ids are string columns, an integer key and a UUID both store whole. What remains unstorable is a key that is not ONE value: a composite key is an array, and a model with no primary key names no record. A grant on either would identify the wrong row or none, so it is refused.

Instance Method Summary collapse

Instance Method Details

#current_scope_resolved_record(side) ⇒ Object

Associations cast their stored id through the target model's key type. For a legacy collapsed row that can turn a UUID-shaped string into integer record 7. Every engine path that labels or audits an existing grant uses this checked reader so an inert grant never names an unrelated live record.



22
23
24
25
26
27
28
29
30
# File 'app/models/concerns/current_scope/storable_keys.rb', line 22

def current_scope_resolved_record(side)
  klass = CurrentScope.polymorphic_class(public_send("#{side}_type"), owner: self.class)
  return if klass.nil?
  return unless CurrentScope.canonical_key?(klass, public_send("#{side}_id"))

  public_send(side)
rescue ActiveRecord::RecordNotFound, NameError
  nil
end