summaryrefslogtreecommitdiff
path: root/app/models/node_action.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/node_action.rb')
-rw-r--r--app/models/node_action.rb19
1 files changed, 14 insertions, 5 deletions
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