diff options
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 16 |
1 files changed, 9 insertions, 7 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 |
