diff options
Diffstat (limited to 'app/models')
| -rw-r--r-- | app/models/asset.rb | 30 | ||||
| -rw-r--r-- | app/models/node_action.rb | 9 |
2 files changed, 39 insertions, 0 deletions
diff --git a/app/models/asset.rb b/app/models/asset.rb index 73970e21..8cec4371 100644 --- a/app/models/asset.rb +++ b/app/models/asset.rb | |||
| @@ -40,4 +40,34 @@ class Asset < ApplicationRecord | |||
| 40 | Node.where("head_id IN (:ids) OR draft_id IN (:ids) OR autosave_id IN (:ids)", | 40 | Node.where("head_id IN (:ids) OR draft_id IN (:ids) OR autosave_id IN (:ids)", |
| 41 | :ids => page_ids).distinct | 41 | :ids => page_ids).distinct |
| 42 | end | 42 | end |
| 43 | |||
| 44 | # Witnessed destruction. Destroying an asset is a public-facing act | ||
| 45 | # even when unattached. The original and its variants are publicly | ||
| 46 | # reachable under /system/uploads, so an entry is always written, | ||
| 47 | # before the row and its files die. Every currently-attached node | ||
| 48 | # participates so its zoomed history shows the loss; the asset itself | ||
| 49 | # participates as the first non-Node subject (its participant row | ||
| 50 | # dangles after destroy, by design, the name lives on in metadata). | ||
| 51 | def destroy_witnessed! user: | ||
| 52 | ActiveRecord::Base.transaction do | ||
| 53 | affected = attached_nodes.to_a | ||
| 54 | headline_losses = affected.select do |node| | ||
| 55 | [node.head, node.draft, node.autosave].compact.any? do |row| | ||
| 56 | row.related_assets.exists?(:asset_id => id, :headline => true) | ||
| 57 | end | ||
| 58 | end | ||
| 59 | |||
| 60 | metadata = { | ||
| 61 | :asset_name => name, | ||
| 62 | :content_type => upload_content_type, | ||
| 63 | :path => upload.url.sub(/\?\d+$/, ""), | ||
| 64 | } | ||
| 65 | metadata[:detached_from] = affected.map(&:unique_name) if affected.any? | ||
| 66 | metadata[:headline_removed_from] = headline_losses.map(&:unique_name) if headline_losses.any? | ||
| 67 | |||
| 68 | NodeAction.record!(:participants => [self] + affected, :user => user, | ||
| 69 | :action => "asset_destroy", **metadata) | ||
| 70 | destroy! | ||
| 71 | end | ||
| 72 | end | ||
| 43 | end | 73 | end |
diff --git a/app/models/node_action.rb b/app/models/node_action.rb index 8a3dd8b7..9ed0b628 100644 --- a/app/models/node_action.rb +++ b/app/models/node_action.rb | |||
| @@ -69,6 +69,15 @@ class NodeAction < ApplicationRecord | |||
| 69 | # "path" -- final path, flat string (create-symmetric) | 69 | # "path" -- final path, flat string (create-symmetric) |
| 70 | # "destroyed_descendants" -- integer, only when positive; one entry | 70 | # "destroyed_descendants" -- integer, only when positive; one entry |
| 71 | # at the root, per the subtree rule. | 71 | # at the root, per the subtree rule. |
| 72 | # "asset_destroy" (witnessed asset deletion; always written, even for | ||
| 73 | # unattached assets -- the files were publicly reachable; node column | ||
| 74 | # nil, subjects via participants: the asset plus every then-attached | ||
| 75 | # node): | ||
| 76 | # "asset_name" -- flat string | ||
| 77 | # "content_type" -- flat string | ||
| 78 | # "path" -- public original path, flat string | ||
| 79 | # "detached_from" -- array of unique_names, only when any | ||
| 80 | # "headline_removed_from" -- array of unique_names, only when any | ||
| 72 | # | 81 | # |
| 73 | # Reserved: "demote" (via "trash" | "depublish") for an explicit | 82 | # Reserved: "demote" (via "trash" | "depublish") for an explicit |
| 74 | # depublish workflow, if ever built. | 83 | # depublish workflow, if ever built. |
