summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2026-07-23 03:28:55 +0200
committererdgeist <erdgeist@erdgeist.org>2026-07-23 03:28:55 +0200
commitd9e95bdb6436768c738539df74a164c885887174 (patch)
tree47b0c461194f3cc9a3194b570f4e077eeccba011 /app
parentdd40bce5ff080885e017709325fb49e9ccd55655 (diff)
Add action_participants, recording every node a trash/destroy touches
Diffstat (limited to 'app')
-rw-r--r--app/models/node.rb16
-rw-r--r--app/models/node_action.rb19
2 files changed, 23 insertions, 12 deletions
diff --git a/app/models/node.rb b/app/models/node.rb
index a5a40d30..e92fa1ea 100644
--- a/app/models/node.rb
+++ b/app/models/node.rb
@@ -312,14 +312,14 @@ class Node < ApplicationRecord
312 was_published = head_id.present? 312 was_published = head_id.present?
313 final_published_at = head&.published_at 313 final_published_at = head&.published_at
314 314
315 demoted = 0 315 subtree = [self] + descendants.to_a
316 ([self] + descendants.to_a).each do |node| 316 demoted_nodes = subtree.select do |node|
317 next unless node.head_id 317 next false unless node.head_id
318 former = node.head 318 former = node.head
319 node.head = nil 319 node.head = nil
320 node.draft_id = former.id if node.draft_id.nil? 320 node.draft_id = former.id if node.draft_id.nil?
321 node.save! 321 node.save!
322 demoted += 1 322 true
323 end 323 end
324 324
325 self.reload 325 self.reload
@@ -332,9 +332,10 @@ class Node < ApplicationRecord
332 metadata = { :path => { "from" => path_before, "to" => unique_name } } 332 metadata = { :path => { "from" => path_before, "to" => unique_name } }
333 metadata[:was_published] = true if was_published 333 metadata[:was_published] = true if was_published
334 metadata[:final_published_at] = final_published_at.iso8601 if final_published_at 334 metadata[:final_published_at] = final_published_at.iso8601 if final_published_at
335 metadata[:demoted_heads] = demoted if demoted > 0 335 metadata[:demoted_heads] = demoted_nodes.size if demoted_nodes.any?
336 336
337 NodeAction.record!(:node => self, :user => current_user, :action => "trash", **metadata) 337 NodeAction.record!(:participants => subtree, :user => current_user,
338 :action => "trash", **metadata)
338 self 339 self
339 end 340 end
340 end 341 end
@@ -382,7 +383,8 @@ class Node < ApplicationRecord
382 metadata = { :path => unique_name } 383 metadata = { :path => unique_name }
383 metadata[:destroyed_descendants] = doomed.size - 1 if doomed.size > 1 384 metadata[:destroyed_descendants] = doomed.size - 1 if doomed.size > 1
384 385
385 NodeAction.record!(:node => self, :user => current_user, :action => "destroy", **metadata) 386 NodeAction.record!(:participants => doomed, :user => current_user,
387 :action => "destroy", **metadata)
386 doomed.each(&:destroy!) 388 doomed.each(&:destroy!)
387 end 389 end
388 end 390 end
diff --git a/app/models/node_action.rb b/app/models/node_action.rb
index 63a99ae8..8a3dd8b7 100644
--- a/app/models/node_action.rb
+++ b/app/models/node_action.rb
@@ -3,6 +3,8 @@ class NodeAction < ApplicationRecord
3 belongs_to :page, optional: true 3 belongs_to :page, optional: true
4 belongs_to :user, optional: true 4 belongs_to :user, optional: true
5 5
6 has_many :action_participants, :dependent => :destroy
7
6 validates :action, presence: true 8 validates :action, presence: true
7 validates :occurred_at, presence: true 9 validates :occurred_at, presence: true
8 10
@@ -81,10 +83,15 @@ class NodeAction < ApplicationRecord
81 # This log records; it does not undo. No IP, session, or user 83 # This log records; it does not undo. No IP, session, or user
82 # agent, ever. Success only. 84 # agent, ever. Success only.
83 85
84 def self.record!(node:, action:, user: nil, page: nil, locale: nil, 86 def self.record!(node: nil, participants: [], action:, user: nil, page: nil,
85 occurred_at: nil, inferred_from: nil, **extra) 87 locale: nil, occurred_at: nil, inferred_from: nil, **extra)
88 participants = participants.presence || [node].compact
89 raise ArgumentError, "NodeAction.record! needs at least one participant" if participants.empty?
90
91 primary_node = node || (participants.first if participants.first.is_a?(Node))
92
86 create!( 93 create!(
87 :node => node, 94 :node => primary_node,
88 :page => page, 95 :page => page,
89 :user => user, 96 :user => user,
90 :action => action, 97 :action => action,
@@ -94,10 +101,12 @@ class NodeAction < ApplicationRecord
94 :metadata => { 101 :metadata => {
95 "username" => user&.login, 102 "username" => user&.login,
96 "human_readable_node_name" => Globalize.with_locale(I18n.default_locale) { 103 "human_readable_node_name" => Globalize.with_locale(I18n.default_locale) {
97 node&.head&.title || node&.draft&.title 104 primary_node&.head&.title || primary_node&.draft&.title
98 }, 105 },
99 }.merge(extra.stringify_keys) 106 }.merge(extra.stringify_keys)
100 ) 107 ).tap do |na|
108 participants.each { |subject| na.action_participants.create!(:subject => subject) }
109 end
101 end 110 end
102 111
103 # Computes the publish-entry diff between an outgoing head and the 112 # Computes the publish-entry diff between an outgoing head and the