diff options
Diffstat (limited to 'app/models/node.rb')
| -rw-r--r-- | app/models/node.rb | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/app/models/node.rb b/app/models/node.rb index a5a40d3..7a93e79 100644 --- a/app/models/node.rb +++ b/app/models/node.rb | |||
| @@ -4,7 +4,14 @@ class Node < ApplicationRecord | |||
| 4 | 4 | ||
| 5 | # Associations | 5 | # Associations |
| 6 | has_many :pages, -> { order("revision ASC") }, :dependent => :destroy | 6 | has_many :pages, -> { order("revision ASC") }, :dependent => :destroy |
| 7 | |||
| 8 | # Entries where this node is the primary subject (fast-path column). | ||
| 9 | # For a *complete* history -- including subtree trash/destroy entries | ||
| 10 | # recorded at an ancestor -- use participated_actions instead. | ||
| 7 | has_many :node_actions, :dependent => :nullify | 11 | has_many :node_actions, :dependent => :nullify |
| 12 | has_many :action_participations, :class_name => "ActionParticipant", :as => :subject | ||
| 13 | has_many :participated_actions, :through => :action_participations, :source => :node_action | ||
| 14 | |||
| 8 | belongs_to :head, :class_name => "Page", :foreign_key => :head_id, optional: true | 15 | belongs_to :head, :class_name => "Page", :foreign_key => :head_id, optional: true |
| 9 | belongs_to :draft, :class_name => "Page", :foreign_key => :draft_id, optional: true | 16 | belongs_to :draft, :class_name => "Page", :foreign_key => :draft_id, optional: true |
| 10 | # Autosave pages carry no node_id, so has_many :pages does not cover | 17 | # Autosave pages carry no node_id, so has_many :pages does not cover |
| @@ -312,14 +319,14 @@ class Node < ApplicationRecord | |||
| 312 | was_published = head_id.present? | 319 | was_published = head_id.present? |
| 313 | final_published_at = head&.published_at | 320 | final_published_at = head&.published_at |
| 314 | 321 | ||
| 315 | demoted = 0 | 322 | subtree = [self] + descendants.to_a |
| 316 | ([self] + descendants.to_a).each do |node| | 323 | demoted_nodes = subtree.select do |node| |
| 317 | next unless node.head_id | 324 | next false unless node.head_id |
| 318 | former = node.head | 325 | former = node.head |
| 319 | node.head = nil | 326 | node.head = nil |
| 320 | node.draft_id = former.id if node.draft_id.nil? | 327 | node.draft_id = former.id if node.draft_id.nil? |
| 321 | node.save! | 328 | node.save! |
| 322 | demoted += 1 | 329 | true |
| 323 | end | 330 | end |
| 324 | 331 | ||
| 325 | self.reload | 332 | self.reload |
| @@ -332,9 +339,10 @@ class Node < ApplicationRecord | |||
| 332 | metadata = { :path => { "from" => path_before, "to" => unique_name } } | 339 | metadata = { :path => { "from" => path_before, "to" => unique_name } } |
| 333 | metadata[:was_published] = true if was_published | 340 | metadata[:was_published] = true if was_published |
| 334 | metadata[:final_published_at] = final_published_at.iso8601 if final_published_at | 341 | metadata[:final_published_at] = final_published_at.iso8601 if final_published_at |
| 335 | metadata[:demoted_heads] = demoted if demoted > 0 | 342 | metadata[:demoted_heads] = demoted_nodes.size if demoted_nodes.any? |
| 336 | 343 | ||
| 337 | NodeAction.record!(:node => self, :user => current_user, :action => "trash", **metadata) | 344 | NodeAction.record!(:participants => subtree, :user => current_user, |
| 345 | :action => "trash", **metadata) | ||
| 338 | self | 346 | self |
| 339 | end | 347 | end |
| 340 | end | 348 | end |
| @@ -382,7 +390,8 @@ class Node < ApplicationRecord | |||
| 382 | metadata = { :path => unique_name } | 390 | metadata = { :path => unique_name } |
| 383 | metadata[:destroyed_descendants] = doomed.size - 1 if doomed.size > 1 | 391 | metadata[:destroyed_descendants] = doomed.size - 1 if doomed.size > 1 |
| 384 | 392 | ||
| 385 | NodeAction.record!(:node => self, :user => current_user, :action => "destroy", **metadata) | 393 | NodeAction.record!(:participants => doomed, :user => current_user, |
| 394 | :action => "destroy", **metadata) | ||
| 386 | doomed.each(&:destroy!) | 395 | doomed.each(&:destroy!) |
| 387 | end | 396 | end |
| 388 | end | 397 | end |
