Module: Collavre::Creatives::EffectiveCreativeResolution
- Defined in:
- app/services/collavre/creatives/effective_creative_resolution.rb
Overview
Single source of truth for "which creative's cache/ownership actually governs permission for this creative?".
A linked creative (origin_id present) borrows its origin's permission: it has no cache entries of its own and its ownership is the origin's ownership. PermissionChecker (single-item) and PermissionFilter (batch) MUST resolve the effective creative through this module so a single check and a batch filter can never diverge for the same user + linked creative.
Class Method Summary collapse
-
.effective_creative(creative) ⇒ Object
For a single loaded creative: returns the creative whose cache/ownership governs permission.
-
.effective_creative_ids(ids) ⇒ Object
For a batch of creative ids: returns { original_id => effective_id }.
Class Method Details
.effective_creative(creative) ⇒ Object
For a single loaded creative: returns the creative whose cache/ownership governs permission. Non-linked creatives resolve to themselves.
16 17 18 |
# File 'app/services/collavre/creatives/effective_creative_resolution.rb', line 16 def effective_creative(creative) creative.origin_id.nil? ? creative : creative.origin end |
.effective_creative_ids(ids) ⇒ Object
For a batch of creative ids: returns { original_id => effective_id }.
Linked creatives map to their origin_id; every other id (including ids
not found in the table) maps to itself. This mirrors
effective_creative so the batch reader resolves origin identically.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/services/collavre/creatives/effective_creative_resolution.rb', line 24 def effective_creative_ids(ids) # Coerce to Integer: origin_by_id is keyed by integer ids from pluck, so a # string id (e.g. sourced from request params) would miss origin lookup # and later miss the integer-keyed readable Set. Non-numeric ids can't # identify a Creative, so drop them. ids = ids.to_a.filter_map { |id| Integer(id, exception: false) }.uniq return {} if ids.empty? origin_by_id = Creative.where(id: ids).pluck(:id, :origin_id).to_h ids.index_with { |id| origin_by_id[id] || id } end |