summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/node.rb8
-rw-r--r--app/models/node_action.rb34
2 files changed, 37 insertions, 5 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index 0a9cd2d1..274b2f94 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -249,7 +249,9 @@ class Node < ApplicationRecord
249 self.head.save! 249 self.head.save!
250 self.draft = nil 250 self.draft = nil
251 251
252 NodeAction.record!(:node => self, :page => self.head, :user => current_user, 252 NodeAction.record!(:node => self,
253 :participants => [self] + NodeAction.changed_assets(outgoing_head, self.head),
254 :page => self.head, :user => current_user,
253 :action => "publish", :via => "draft", 255 :action => "publish", :via => "draft",
254 **NodeAction.head_diff(outgoing_head, self.head)) 256 **NodeAction.head_diff(outgoing_head, self.head))
255 end 257 end
@@ -296,7 +298,9 @@ class Node < ApplicationRecord
296 self.head = page 298 self.head = page
297 self.save! 299 self.save!
298 300
299 NodeAction.record!(:node => self, :page => page, :user => current_user, 301 NodeAction.record!(:node => self,
302 :participants => [self] + NodeAction.changed_assets(outgoing_head, page),
303 :page => page, :user => current_user,
300 :action => "publish", :via => "revision", 304 :action => "publish", :via => "revision",
301 **NodeAction.head_diff(outgoing_head, page)) 305 **NodeAction.head_diff(outgoing_head, page))
302 self 306 self
diff --git a/app/models/node_action.rb b/app/models/node_action.rb
index aa52f489..afa2195c 100644
--- a/app/models/node_action.rb
+++ b/app/models/node_action.rb
@@ -35,8 +35,16 @@ class NodeAction < ApplicationRecord
35 # "title" -- pair, always; "from" null on first publish 35 # "title" -- pair, always; "from" null on first publish
36 # "author" -- pair, when the byline changed (incl. first publish) 36 # "author" -- pair, when the byline changed (incl. first publish)
37 # "tags" -- pair of arrays, when changed 37 # "tags" -- pair of arrays, when changed
38 # "assets_changed", "template_changed", 38 # "assets" -- {"added" => [asset names], "removed" => [asset names]},
39 # "abstract_changed", "body_changed" 39 # keys only when any; a delta, not a pair. The event IS
40 # the delta, full sets would bloat every entry. Changed
41 # assets are participants of the entry. Replaces the
42 # legacy "assets_changed" boolean, which witnessed
43 # pre-contract entries still carry and the renderer keeps
44 # understanding. Assets destroyed since leave no trace in
45 # regenerated deltas, their joins died with them.
46 # "assets_reordered" -- boolean, set unchanged but gallery order not
47 # "template_changed", "abstract_changed", "body_changed"
40 # -- the last two for the default locale; page_id links 48 # -- the last two for the default locale; page_id links
41 # to the revision for the real diff (never stored) 49 # to the revision for the real diff (never stored)
42 # "translation_diff" -- only when a non-default locale differs: 50 # "translation_diff" -- only when a non-default locale differs:
@@ -155,7 +163,17 @@ class NodeAction < ApplicationRecord
155 diff[:tags] = { "from" => old_tags, "to" => new_tags } if old_tags != new_tags 163 diff[:tags] = { "from" => old_tags, "to" => new_tags } if old_tags != new_tags
156 164
157 diff[:template_changed] = true if old_page.template_name != new_page.template_name 165 diff[:template_changed] = true if old_page.template_name != new_page.template_name
158 diff[:assets_changed] = true if old_page.assets.map(&:id) != new_page.assets.map(&:id) 166
167 old_assets, new_assets = old_page.assets.to_a, new_page.assets.to_a
168 added, removed = new_assets - old_assets, old_assets - new_assets
169 if added.any? || removed.any?
170 assets = {}
171 assets["added"] = added.map { |a| a.name.presence || a.upload_file_name } if added.any?
172 assets["removed"] = removed.map { |a| a.name.presence || a.upload_file_name } if removed.any?
173 diff[:assets] = assets
174 elsif old_assets.map(&:id) != new_assets.map(&:id)
175 diff[:assets_reordered] = true
176 end
159 177
160 old_t = old_page.translations.find_by(:locale => default) 178 old_t = old_page.translations.find_by(:locale => default)
161 new_t = new_page.translations.find_by(:locale => default) 179 new_t = new_page.translations.find_by(:locale => default)
@@ -188,6 +206,16 @@ class NodeAction < ApplicationRecord
188 diff 206 diff
189 end 207 end
190 208
209 # The asset records added or removed between an outgoing head and its
210 # replacement -- the participant complement to head_diff's "assets"
211 # names. Empty on first publish, mirroring head_diff, which records
212 # no asset delta when everything is new.
213 def self.changed_assets old_page, new_page
214 return [] unless old_page
215 old_a, new_a = old_page.assets.to_a, new_page.assets.to_a
216 (new_a - old_a) | (old_a - new_a)
217 end
218
191 def actor_name 219 def actor_name
192 metadata["username"] || "unknown" 220 metadata["username"] || "unknown"
193 end 221 end