Class: Collavre::CreativeShare

Inherits:
ApplicationRecord show all
Defined in:
app/models/collavre/creative_share.rb

Constant Summary collapse

PERMISSION_INVALIDATING_ATTRIBUTES =

Single declarative registry mirroring Creative::Permissible: which persisted CreativeShare attributes affect the permission cache, and how. Every create and update re-propagates the share unconditionally (see dispatch_share_cache_invalidation) — a fail-closed refresh that matches the prior propagate_cache and survives a multi-save transaction clobbering an earlier permission change out of the final saved_changes. This map governs the extra cleanup a move or reassignment needs on top of that base refresh, so a new share-mutation path still can't silently skip it:

:relocate    -> creative_id moved: purge this share's rows and rebuild
              the vacated (old creative, old user) subtree
:reassign    -> user_id changed: purge this share's rows and rebuild the
              old user's subtree at the current creative
:repropagate -> permission changed: covered by the unconditional
              re-propagate above (listed to document the invariant)
{
  "creative_id" => :relocate,
  "user_id"     => :reassign,
  "permission"  => :repropagate
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.closest_parent_share(ancestor_ids, ancestor_shares) ⇒ Object

Given ancestor_ids and ancestor_shares, returns the closest CreativeShare in the ancestors. If there is no ancestor share, returns nil.



55
56
57
# File 'app/models/collavre/creative_share.rb', line 55

def self.closest_parent_share(ancestor_ids, ancestor_shares)
  ancestor_shares.to_a.min_by { |s| ancestor_ids.index(s.creative_id) || Float::INFINITY }
end

Instance Method Details

#sharer_idObject



59
60
61
# File 'app/models/collavre/creative_share.rb', line 59

def sharer_id
  shared_by_id || creative.user_id
end