Skip to content

A platform for community discussion. Free, open, simple.

DEV: Pass the acting user to workflow-relevant events (#44555)

Régis Hanol22630754ba93
diff --git a/.skills/discourse-workflow-nodes/SKILL.md b/.skills/discourse-workflow-nodes/SKILL.md
index 63b586f8f2c..0fce8d371c8 100644
--- a/.skills/discourse-workflow-nodes/SKILL.md
+++ b/.skills/discourse-workflow-nodes/SKILL.md
@@ -27,6 +27,23 @@ Shape entities only with `DiscourseWorkflows::EntitySerializers` (`lib/discourse
- Never use `BasicUserSerializer` or `TopicListItemSerializer` in node files; `node_entity_builders_spec` fails if you do.
- Groups: `BasicGroupSerializer` (`BASIC_GROUP_PROPERTIES`) or `WebHookGroupSerializer` (`GROUP_SCHEMA`).
+## `user` vs `actor`
+
+- `user` is the subject: the post/topic author, or the affected account.
+- `actor` is whoever performed the action, built with `serialize_user` and declared with `Schema::ACTOR_SCHEMA` (nullable).
+- Emit both, even when they are the same person (liker, voter, participant).
+- Output never uses `acting_user`; events never use `actor:`.
+
+## Events pass the acting user
+
+Fire events with the actor as a trailing `acting_user:` kwarg:
+
+```ruby
+DiscourseEvent.trigger(:topic_status_updated, topic, status, enabled, acting_user: user)
+```
+
+Trigger nodes receive it as a trailing hash: `def initialize(topic, status, enabled, payload = {})` and read `payload[:acting_user]`. Specs that assert exact event params must include `{ acting_user: ... }`.
+
## Output conventions
- URLs are absolute (`Discourse.base_url + ...`, `full_url`). Keep existing relative keys such as `post_url`.
diff --git a/app/models/reviewable.rb b/app/models/reviewable.rb
index 24454a938ba..cb1a9ef3d60 100644
--- a/app/models/reviewable.rb
+++ b/app/models/reviewable.rb
@@ -512,7 +512,12 @@ class Reviewable < ActiveRecord::Base
save!
log_history(:transitioned, performed_by)
- DiscourseEvent.trigger(:reviewable_transitioned_to, status_symbol, self)
+ DiscourseEvent.trigger(
+ :reviewable_transitioned_to,
+ status_symbol,
+ self,
+ acting_user: performed_by,
+ )
if score_status = ReviewableScore.score_transitions[status_symbol]
scores.update_all(
diff --git a/app/services/topic_status_updater.rb b/app/services/topic_status_updater.rb
index 086ae6f632b..f62cff4d54b 100644
--- a/app/services/topic_status_updater.rb
+++ b/app/services/topic_status_updater.rb
@@ -20,7 +20,13 @@ TopicStatusUpdater =
end
if changed
- DiscourseEvent.trigger(:topic_status_updated, topic, event_status, status.enabled?)
+ DiscourseEvent.trigger(
+ :topic_status_updated,
+ topic,
+ event_status,
+ status.enabled?,
+ acting_user: user,
+ )
end
updated
diff --git a/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb b/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb
index fe771fd9ce1..ac3d0240a9c 100644
--- a/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb
+++ b/plugins/chat/lib/discourse_workflows/nodes/chat_approval/v2.rb
@@ -30,6 +30,7 @@ if defined?(DiscourseWorkflows)
"type" => "object",
"properties" => DiscourseWorkflows::Schema::USER_PROPERTIES,
},
+ "actor" => DiscourseWorkflows::Schema.nullable_user("User who clicked the button"),
},
}.freeze
@@ -238,7 +239,12 @@ if defined?(DiscourseWorkflows)
[
DiscourseWorkflows::Item.wrap(
- { value: interaction.action["value"].to_s, channel: channel_data, user: user_data },
+ {
+ value: interaction.action["value"].to_s,
+ channel: channel_data,
+ user: user_data,
+ actor: user_data,
+ },
paired_item: 0,
),
]
diff --git a/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb b/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb
index bf39b7c9893..0846eb4bbf8 100644
--- a/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb
+++ b/plugins/chat/lib/discourse_workflows/nodes/chat_message_created/v1.rb
@@ -59,6 +59,8 @@ if defined?(DiscourseWorkflows)
"properties" => Chat::WorkflowChannelSerializer::PROPERTIES,
},
"user" => DiscourseWorkflows::Schema.nullable_user("Message author"),
+ "actor" =>
+ DiscourseWorkflows::Schema.nullable_user("User who sent the message"),
},
},
},
@@ -118,6 +120,8 @@ if defined?(DiscourseWorkflows)
end
def output
+ user = serialize_user(@user)
+
{
message: {
id: @message.id,
@@ -130,7 +134,8 @@ if defined?(DiscourseWorkflows)
url: @message.full_url,
},
channel: serialize_channel,
- user: serialize_user(@user),
+ user:,
+ actor: user,
}
end
diff --git a/plugins/chat/spec/integration/workflows_chat_approval_spec.rb b/plugins/chat/spec/integration/workflows_chat_approval_spec.rb
index c0fb5117315..7d612c6c611 100644
--- a/plugins/chat/spec/integration/workflows_chat_approval_spec.rb
+++ b/plugins/chat/spec/integration/workflows_chat_approval_spec.rb
@@ -162,7 +162,7 @@ RSpec.describe "Chat approval workflows end-to-end" do
final_output = execution.reload.execution_data.context_data.dig("Final", 0, "json")
expect(execution.status).to eq("success")
expect(final_output).to include("request_id" => 42, "completed" => true)
- expect(final_output.keys).not_to include("value", "channel", "user")
+ expect(final_output.keys).not_to include("value", "channel", "user", "actor")
end
it "fails a timed-out V2 workflow with the approval timeout error" do
diff --git a/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb b/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb
index 6107ecb9348..1cbfd32087d 100644
--- a/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb
+++ b/plugins/chat/spec/lib/discourse_workflows/nodes/chat_message_created_spec.rb
@@ -61,13 +61,15 @@ RSpec.describe DiscourseWorkflows::Nodes::ChatMessageCreated::V1 do
username: user.username,
avatar_template: user.avatar_template,
)
+ expect(output[:actor]).to include(id: user.id, username: user.username)
expect(output).to match_node_output_schema(described_class)
end
- it "returns a nil user when there is no user", :aggregate_failures do
+ it "returns nil user and actor when there is no user", :aggregate_failures do
output = described_class.new(message, channel, nil).output
expect(output[:user]).to be_nil
+ expect(output[:actor]).to be_nil
expect(output).to match_node_output_schema(described_class)
end
diff --git a/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb b/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb
index 8fb5a74d937..b06096e50e0 100644
--- a/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb
+++ b/plugins/chat/spec/services/chat/workflows/approval/resume_interaction_spec.rb
@@ -250,6 +250,7 @@ RSpec.describe Chat::Workflows::Approval::ResumeInteraction do
"value" => "needs:changes",
"channel" => expected_channel,
"user" => expected_user,
+ "actor" => expected_user,
},
"pairedItem" => {
"item" => 0,
diff --git a/plugins/discourse-assign/lib/assigner.rb b/plugins/discourse-assign/lib/assigner.rb
index a3c7d97cfeb..481ae682784 100644
--- a/plugins/discourse-assign/lib/assigner.rb
+++ b/plugins/discourse-assign/lib/assigner.rb
@@ -407,7 +407,7 @@ class ::Assigner
WebHook.enqueue_assign_hooks(assigned_to_type, payload.to_json)
end
- DiscourseEvent.trigger(:assigned, assignment)
+ DiscourseEvent.trigger(:assigned, assignment, acting_user: @assigned_by)
{ success: true }
end
@@ -472,7 +472,7 @@ class ::Assigner
WebHook.enqueue_assign_hooks(type, payload.to_json)
end
- DiscourseEvent.trigger(:unassigned, assignment)
+ DiscourseEvent.trigger(:unassigned, assignment, acting_user: @assigned_by)
if allowed_user_ids.present?
MessageBus.publish(
diff --git a/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rb b/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rb
index 7c41d791c42..727157625df 100644
--- a/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rb
+++ b/plugins/discourse-assign/lib/discourse_assign/workflows/assignment_trigger.rb
@@ -3,9 +3,10 @@
module DiscourseAssign
module Workflows
module AssignmentTrigger
- def initialize(assignment, *)
+ def initialize(assignment, payload = {})
super(parameters: {})
@assignment = assignment
+ @actor = payload[:acting_user]
end
def valid?
@@ -22,6 +23,7 @@ module DiscourseAssign
assignment: serialize_assignment,
post: serialize_post(post),
topic: serialize_topic_list_item(@assignment.topic),
+ actor: serialize_user(@actor),
}
end
diff --git a/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb b/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb
index 61fdde16f03..5fe4bf10b67 100644
--- a/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb
+++ b/plugins/discourse-assign/lib/discourse_assign/workflows/schema.rb
@@ -69,6 +69,7 @@ module DiscourseAssign
DiscourseWorkflows::Schema::POST_SCHEMA,
DiscourseWorkflows::Schema::TOPIC_LIST_ITEM_SCHEMA,
ASSIGNMENT_SCHEMA,
+ DiscourseWorkflows::Schema::ACTOR_SCHEMA,
).freeze
end
end
diff --git a/plugins/discourse-assign/spec/lib/discourse_workflows/nodes/unassigned/v1_spec.rb b/plugins/discourse-assign/spec/lib/discourse_workflows/nodes/unassigned/v1_spec.rb
index 9aa359c72a2..77244fb204d 100644
--- a/plugins/discourse-assign/spec/lib/discourse_workflows/nodes/unassigned/v1_spec.rb
+++ b/plugins/discourse-assign/spec/lib/discourse_workflows/nodes/unassigned/v1_spec.rb
@@ -4,6 +4,7 @@ RSpec.describe DiscourseWorkflows::Nodes::Unassigned::V1 do
fab!(:post)
fab!(:topic) { post.topic }
fab!(:assigned_by_user, :admin)
+ fab!(:unassigned_by_user, :admin)
fab!(:assignee, :moderator)
fab!(:group)
@@ -83,15 +84,14 @@ RSpec.describe DiscourseWorkflows::Nodes::Unassigned::V1 do
end
it "returns valid output for an assignment destroyed by unassign", :aggregate_failures do
- assigner = Assigner.new(topic, assigned_by_user)
- assigner.assign(assignee)
- assignment = topic.reload.assignment
+ Assigner.new(topic, assigned_by_user).assign(assignee)
- DiscourseEvent.track(:unassigned) { assigner.unassign }
+ event = DiscourseEvent.track(:unassigned) { Assigner.new(topic, unassigned_by_user).unassign }
- output = described_class.new(assignment).output
+ output = described_class.from_event(:unassigned, *event[:params]).output
expect(output[:assignment]).to include(target_type: "Topic", target_id: topic.id)
+ expect(output[:actor][:username]).to eq(unassigned_by_user.username)
expect(output[:topic][:id]).to eq(topic.id)
expect(output).to match_node_output_schema(described_class)
end
diff --git a/plugins/discourse-events/app/jobs/regular/discourse_post_event_bulk_invite.rb b/plugins/discourse-events/app/jobs/regular/discourse_post_event_bulk_invite.rb
index 1e0b4714c0f..4f24afa0abf 100644
--- a/plugins/discourse-events/app/jobs/regular/discourse_post_event_bulk_invite.rb
+++ b/plugins/discourse-events/app/jobs/regular/discourse_post_event_bulk_invite.rb
@@ -108,6 +108,7 @@ module Jobs
invitee.status = status
invitee.recurring = @recurring && invitee.going?
invitee.save!
+ invitee.publish_status_changed!(acting_user: @current_user) if invitee.saved_change_to_status?
end
def save_log(message)
diff --git a/plugins/discourse-events/app/models/discourse_events/events/invitee.rb b/plugins/discourse-events/app/models/discourse_events/events/invitee.rb
index 653b816ea9f..4998d44391f 100644
--- a/plugins/discourse-events/app/models/discourse_events/events/invitee.rb
+++ b/plugins/discourse-events/app/models/discourse_events/events/invitee.rb
@@ -33,7 +33,7 @@ module DiscourseEvents
@statuses ||= Enum.new(going: 0, interested: 1, not_going: 2)
end
- def self.create_attendance!(user_id, post_id, status, recurring: false)
+ def self.create_attendance!(user_id, post_id, status, recurring: false, acting_user: nil)
status = status.to_sym
event = Event.find(post_id)
@@ -42,14 +42,14 @@ module DiscourseEvents
end
invitee = create!(post_id:, user_id:, status: statuses[status], recurring:)
- invitee.publish_attendance_change!
+ invitee.publish_attendance_change!(acting_user:)
invitee
rescue ActiveRecord::RecordNotUnique
# multiple attendances may be created concurrently — return the winning row
find_by(post_id:, user_id:)
end
- def update_attendance!(status, recurring: false)
+ def update_attendance!(status, recurring: false, acting_user: nil)
status = status&.to_sym
if status == :going && event.at_capacity? && !going?
@@ -57,7 +57,7 @@ module DiscourseEvents
end
update!(status: self.class.statuses[status], recurring:)
- publish_attendance_change!
+ publish_attendance_change!(acting_user:)
self
end
@@ -65,14 +65,18 @@ module DiscourseEvents
status == Invitee.statuses[:going]
end
- def publish_attendance_change!
+ def publish_attendance_change!(acting_user:)
event.publish_update!
update_topic_tracking!
- DiscourseEvent.trigger(:discourse_calendar_post_event_invitee_status_changed, self)
+ publish_status_changed!(acting_user:)
end
- def publish_attendance_removed!
- DiscourseEvent.trigger(:discourse_calendar_post_event_invitee_status_changed, self)
+ def publish_status_changed!(acting_user:)
+ DiscourseEvent.trigger(
+ :discourse_calendar_post_event_invitee_status_changed,
+ self,
+ acting_user:,
+ )
end
def self.extract_uniq_usernames(groups)
diff --git a/plugins/discourse-events/app/services/discourse_events/events/create_invitee.rb b/plugins/discourse-events/app/services/discourse_events/events/create_invitee.rb
index a6ee1d465c8..2338793140f 100644
--- a/plugins/discourse-events/app/services/discourse_events/events/create_invitee.rb
+++ b/plugins/discourse-events/app/services/discourse_events/events/create_invitee.rb
@@ -51,8 +51,14 @@ module DiscourseEvents
params.status != :going || !event.at_capacity?
end
- def create_invitee(user:, event:, params:)
- Invitee.create_attendance!(user.id, event.id, params.status, recurring: params.recurring)
+ def create_invitee(user:, event:, params:, guardian:)
+ Invitee.create_attendance!(
+ user.id,
+ event.id,
+ params.status,
+ recurring: params.recurring,
+ acting_user: guardian.user,
+ )
end
end
end
diff --git a/plugins/discourse-events/app/services/discourse_events/events/destroy_invitee.rb b/plugins/discourse-events/app/services/discourse_events/events/destroy_invitee.rb
index 3395668866c..df05232db14 100644
--- a/plugins/discourse-events/app/services/discourse_events/events/destroy_invitee.rb
+++ b/plugins/discourse-events/app/services/discourse_events/events/destroy_invitee.rb
@@ -44,9 +44,9 @@ module DiscourseEvents
event.can_user_update_attendance?(guardian.user)
end
- def destroy(invitee:)
+ def destroy(invitee:, guardian:)
invitee.destroy!
- invitee.publish_attendance_removed!
+ invitee.publish_status_changed!(acting_user: guardian.user)
end
def publish(event:)
diff --git a/plugins/discourse-events/app/services/discourse_events/events/update_invitee.rb b/plugins/discourse-events/app/services/discourse_events/events/update_invitee.rb
index 05438b841a7..d7f951c7ccf 100644
--- a/plugins/discourse-events/app/services/discourse_events/events/update_invitee.rb
+++ b/plugins/discourse-events/app/services/discourse_events/events/update_invitee.rb
@@ -51,8 +51,12 @@ module DiscourseEvents
params.status != :going || !event.at_capacity? || invitee.status == Invitee.statuses[:going]
end
- def update(invitee:, params:)
- invitee.update_attendance!(params.status, recurring: params.recurring)
+ def update(invitee:, params:, guardian:)
+ invitee.update_attendance!(
+ params.status,
+ recurring: params.recurring,
+ acting_user: guardian.user,
+ )
end
end
end
diff --git a/plugins/discourse-events/lib/discourse_workflows/nodes/event_participation_changed/v1.rb b/plugins/discourse-events/lib/discourse_workflows/nodes/event_participation_changed/v1.rb
index c8c67605411..9b6c2029dca 100644
--- a/plugins/discourse-events/lib/discourse_workflows/nodes/event_participation_changed/v1.rb
+++ b/plugins/discourse-events/lib/discourse_workflows/nodes/event_participation_changed/v1.rb
@@ -25,9 +25,10 @@ if defined?(DiscourseWorkflows)
i18n_scope: PostEventScoping::I18N_SCOPE,
)
- def initialize(invitee, *)
+ def initialize(invitee, payload = {})
super(parameters: {})
@invitee = invitee
+ @actor = payload[:acting_user]
end
# Re-submitting an unchanged RSVP still publishes, so without the
@@ -52,6 +53,7 @@ if defined?(DiscourseWorkflows)
recurring: !removed? && [email protected],
},
stats: serialize_event_stats,
+ actor: serialize_user(@actor),
}
end
diff --git a/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb b/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb
index 88e78b0a6f8..1ca0ae1bc27 100644
--- a/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb
+++ b/plugins/discourse-events/lib/discourse_workflows/nodes/post_event_schema.rb
@@ -108,6 +108,7 @@ if defined?(DiscourseWorkflows)
DiscourseWorkflows::Schema::USER_SCHEMA,
PARTICIPATION_SCHEMA,
STATS_SCHEMA,
+ DiscourseWorkflows::Schema::ACTOR_SCHEMA,
).freeze
end
end
diff --git a/plugins/discourse-events/spec/integration/workflows_event_triggers_spec.rb b/plugins/discourse-events/spec/integration/workflows_event_triggers_spec.rb
index b90a2ca1b10..5c1770f7257 100644
--- a/plugins/discourse-events/spec/integration/workflows_event_triggers_spec.rb
+++ b/plugins/discourse-events/spec/integration/workflows_event_triggers_spec.rb
@@ -80,6 +80,60 @@ RSpec.describe "Post event workflow triggers" do
Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.first["args"].first["trigger_data"]
expect(trigger_data["participation"]).to include("removed" => true, "status" => nil)
end
+
+ it "enqueues for each invitee whose status a bulk invite sets" do
+ event.update!(status: DiscourseEvents::Events::Event.statuses[:public])
+ newcomer = Fabricate(:user)
+ DiscourseEvents::Events::Invitee.create_attendance!(attendee.id, event.id, :interested)
+ workflow = publish_workflow("trigger-all", "trigger:event_participation_changed")
+ Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.clear
+
+ Jobs::DiscoursePostEventBulkInvite.new.execute(
+ event_id: event.id,
+ current_user_id: admin.id,
+ invitees: [
+ { "identifier" => attendee.username, "attendance" => "going" },
+ { "identifier" => newcomer.username, "attendance" => "not_going" },
+ ],
+ )
+
+ expect(enqueued_workflow_ids("trigger-all")).to eq([workflow.id, workflow.id])
+
+ participations =
+ Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.map do |job|
+ job["args"].first["trigger_data"].slice("user", "participation", "actor")
+ end
+ expect(participations).to contain_exactly(
+ a_hash_including(
+ "user" => a_hash_including("id" => attendee.id),
+ "participation" =>
+ a_hash_including("status" => "going", "previous_status" => "interested"),
+ "actor" => a_hash_including("id" => admin.id),
+ ),
+ a_hash_including(
+ "user" => a_hash_including("id" => newcomer.id),
+ "participation" => a_hash_including("status" => "not_going", "previous_status" => nil),
+ "actor" => a_hash_including("id" => admin.id),
+ ),
+ )
+ end
+
+ it "does not enqueue when a bulk invite leaves the status unchanged" do
+ event.update!(status: DiscourseEvents::Events::Event.statuses[:public])
+ DiscourseEvents::Events::Invitee.create_attendance!(attendee.id, event.id, :going).update!(
+ notified: true,
+ )
+ publish_workflow("trigger-all", "trigger:event_participation_changed")
+ Jobs::DiscourseWorkflows::ExecuteWorkflow.jobs.clear
+
+ Jobs::DiscoursePostEventBulkInvite.new.execute(
+ event_id: event.id,
+ current_user_id: admin.id,
+ invitees: [{ "identifier" => attendee.username, "attendance" => "going" }],
+ )
+
+ expect(enqueued_workflow_ids("trigger-all")).to be_empty
+ end
end
describe "trigger:event_ended" do
diff --git a/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_participation_changed/v1_spec.rb b/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_participation_changed/v1_spec.rb
index eaffcd8462c..5149ad4411f 100644
--- a/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_participation_changed/v1_spec.rb
+++ b/plugins/discourse-events/spec/lib/discourse_workflows/nodes/event_participation_changed/v1_spec.rb
@@ -67,6 +67,26 @@ RSpec.describe DiscourseWorkflows::Nodes::EventParticipationChanged::V1 do
previous_status: nil,
removed: false,
)
+ expect(output[:actor]).to be_nil
+ expect(output).to match_node_output_schema(described_class)
+ end
+
+ it "reports the user who changed the RSVP as actor", :aggregate_failures do
+ organizer = Fabricate(:admin)
+ tracked =
+ DiscourseEvent.track(:discourse_calendar_post_event_invitee_status_changed) do
+ DiscourseEvents::Events::Invitee.create_attendance!(
+ user.id,
+ event.id,
+ :going,
+ acting_user: organizer,
+ )
+ end
+
+ output = described_class.from_event(:any, *tracked[:params]).output
+
+ expect(output[:user][:username]).to eq(user.username)
+ expect(output[:actor][:username]).to eq(organizer.username)
expect(output).to match_node_output_schema(described_class)
end
diff --git a/plugins/discourse-events/spec/services/discourse_events/events/create_invitee_spec.rb b/plugins/discourse-events/spec/services/discourse_events/events/create_invitee_spec.rb
index cc66396e283..68124a51d8d 100644
--- a/plugins/discourse-events/spec/services/discourse_events/events/create_invitee_spec.rb
+++ b/plugins/discourse-events/spec/services/discourse_events/events/create_invitee_spec.rb
@@ -118,6 +118,15 @@ RSpec.describe(DiscourseEvents::Events::CreateInvitee) do
it { is_expected.to run_successfully }
+ it "publishes the staff member as the acting user" do
+ event =
+ DiscourseEvent
+ .track_events(:discourse_calendar_post_event_invitee_status_changed) { result }
+ .first
+
+ expect(event[:params].last).to eq(acting_user: admin)
+ end
+
it "creates the invitee for the other user" do
expect { result }.to change { DiscourseEvents::Events::Invitee.count }.by(1)
expect(result[:invitee]).to have_attributes(
diff --git a/plugins/discourse-events/spec/services/discourse_events/events/destroy_invitee_spec.rb b/plugins/discourse-events/spec/services/discourse_events/events/destroy_invitee_spec.rb
index 25e8f4e756a..cc29423da50 100644
--- a/plugins/discourse-events/spec/services/discourse_events/events/destroy_invitee_spec.rb
+++ b/plugins/discourse-events/spec/services/discourse_events/events/destroy_invitee_spec.rb
@@ -139,6 +139,15 @@ RSpec.describe(DiscourseEvents::Events::DestroyInvitee) do
it { is_expected.to run_successfully }
+ it "publishes the staff member as the acting user" do
+ event =
+ DiscourseEvent
+ .track_events(:discourse_calendar_post_event_invitee_status_changed) { result }
+ .first
+
+ expect(event[:params].last).to eq(acting_user: admin)
+ end
+
it "destroys the invitee" do
expect { result }.to change { DiscourseEvents::Events::Invitee.count }.by(-1)
end
diff --git a/plugins/discourse-events/spec/services/discourse_events/events/update_invitee_spec.rb b/plugins/discourse-events/spec/services/discourse_events/events/update_invitee_spec.rb
index b4b591fe139..a4d1c17a0b3 100644
--- a/plugins/discourse-events/spec/services/discourse_events/events/update_invitee_spec.rb
+++ b/plugins/discourse-events/spec/services/discourse_events/events/update_invitee_spec.rb
@@ -164,6 +164,15 @@ RSpec.describe(DiscourseEvents::Events::UpdateInvitee) do
it { is_expected.to run_successfully }
+ it "publishes the event creator as the acting user" do
+ event =
+ DiscourseEvent
+ .track_events(:discourse_calendar_post_event_invitee_status_changed) { result }
+ .first
+
+ expect(event[:params].last).to eq(acting_user: event_creator)
+ end
+
it "updates the invitee status" do
expect { result }.to change { creator_event_invitee.reload.status }.from(
DiscourseEvents::Events::Invitee.statuses[:going],
diff --git a/plugins/discourse-solved/app/services/discourse_solved/accept_answer.rb b/plugins/discourse-solved/app/services/discourse_solved/accept_answer.rb
index 798db893b78..fa3982b95ab 100644
--- a/plugins/discourse-solved/app/services/discourse_solved/accept_answer.rb
+++ b/plugins/discourse-solved/app/services/discourse_solved/accept_answer.rb
@@ -186,7 +186,7 @@ class DiscourseSolved::AcceptAnswer
end
def publish_solution(post:, topic:, guardian:)
- DiscourseEvent.trigger(:accepted_solution, post)
+ DiscourseEvent.trigger(:accepted_solution, post, acting_user: guardian.user)
MessageBus.publish(
"/topic/#{topic.id}",
{
diff --git a/plugins/discourse-solved/app/services/discourse_solved/unaccept_answer.rb b/plugins/discourse-solved/app/services/discourse_solved/unaccept_answer.rb
index 276c05a9938..57ff5d7b156 100644
--- a/plugins/discourse-solved/app/services/discourse_solved/unaccept_answer.rb
+++ b/plugins/discourse-solved/app/services/discourse_solved/unaccept_answer.rb
@@ -87,7 +87,7 @@ class DiscourseSolved::UnacceptAnswer
end
def publish_unaccepted(post:, topic:, guardian:)
- DiscourseEvent.trigger(:unaccepted_solution, post)
+ DiscourseEvent.trigger(:unaccepted_solution, post, acting_user: guardian.user)
MessageBus.publish(
"/topic/#{topic.id}",
{
diff --git a/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb b/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb
index 28fb047ac23..8db0ffe65d0 100644
--- a/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb
+++ b/plugins/discourse-solved/lib/discourse_workflows/nodes/solution_changed/v1.rb
@@ -17,6 +17,8 @@ if defined?(DiscourseWorkflows)
"enum" => CHANGES.values,
},
),
+ DiscourseWorkflows::Schema::POST_AUTHOR_SCHEMA,
+ DiscourseWorkflows::Schema::ACTOR_SCHEMA,
).freeze
description(
@@ -46,10 +48,11 @@ if defined?(DiscourseWorkflows)
new(event_name, *args)
end
- def initialize(event_name, post, *)
+ def initialize(event_name, post, payload = {})
super(parameters: {})
@change = CHANGES[event_name]
@post = post
+ @actor = payload[:acting_user]
end
def valid?
@@ -61,6 +64,8 @@ if defined?(DiscourseWorkflows)
change: @change,
post: serialize_post(@post),
topic: serialize_topic_list_item(topic),
+ user: serialize_user(@post.user),
+ actor: serialize_user(@actor),
}
end
diff --git a/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb b/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb
index e6f5a33634f..05b1352450e 100644
--- a/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb
+++ b/plugins/discourse-solved/spec/lib/discourse_workflows/nodes/solution_changed_spec.rb
@@ -63,6 +63,10 @@ RSpec.describe DiscourseWorkflows::Nodes::SolutionChanged::V1, discourse_workflo
[answer.id, other_answer.id, answer.id],
)
expect(data.map { |payload| payload.dig("topic", "id") }.uniq).to eq([topic.id])
+ expect(data.map { |payload| payload.dig("actor", "username") }.uniq).to eq([admin.username])
+ expect(data.map { |payload| payload.dig("user", "id") }).to eq(
+ [answer.user_id, other_answer.user_id, answer.user_id],
+ )
expect(data).to all(match_node_output_schema(described_class))
expect(post.topic.reload.topic_answers.pluck(:answer_post_id)).to eq([other_answer.id])
end
diff --git a/plugins/discourse-solved/spec/services/discourse_solved/accept_answer_spec.rb b/plugins/discourse-solved/spec/services/discourse_solved/accept_answer_spec.rb
index c4356ce0fb6..754c007a6cd 100644
--- a/plugins/discourse-solved/spec/services/discourse_solved/accept_answer_spec.rb
+++ b/plugins/discourse-solved/spec/services/discourse_solved/accept_answer_spec.rb
@@ -435,7 +435,7 @@ RSpec.describe DiscourseSolved::AcceptAnswer do
end
it "triggers the :accepted_solution event" do
- expect(events).to include(a_hash_including(params: [post]))
+ expect(events).to include(a_hash_including(params: [post, { acting_user: }]))
end
it "broadcasts the accepted solution" do
diff --git a/plugins/discourse-solved/spec/services/discourse_solved/unaccept_answer_spec.rb b/plugins/discourse-solved/spec/services/discourse_solved/unaccept_answer_spec.rb
index e877685d784..a0ef0d9eaf4 100644
--- a/plugins/discourse-solved/spec/services/discourse_solved/unaccept_answer_spec.rb
+++ b/plugins/discourse-solved/spec/services/discourse_solved/unaccept_answer_spec.rb
@@ -163,7 +163,7 @@ RSpec.describe DiscourseSolved::UnacceptAnswer do
end
it "triggers the :unaccepted_solution event" do
- expect(events).to include(a_hash_including(params: [post]))
+ expect(events).to include(a_hash_including(params: [post, { acting_user: user }]))
end
it "broadcasts the unaccepted solution" do
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb
index a66cc2926a2..9930b6ebd94 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_lifecycle.rb
@@ -12,15 +12,20 @@ module DiscourseWorkflows
OUTPUT_CONTRACTS = [
{
schema:
- Schema.merge(Schema::POST_SCHEMA, Schema::TOPIC_LIST_ITEM_SCHEMA, Schema::USER_SCHEMA),
+ Schema.merge(
+ Schema::POST_SCHEMA,
+ Schema::TOPIC_LIST_ITEM_SCHEMA,
+ Schema::USER_SCHEMA,
+ Schema::ACTOR_SCHEMA,
+ ),
},
].freeze
- def initialize(post, opts = nil, user = nil, *)
+ def initialize(post, opts = nil, actor = nil, *)
super(parameters: {})
@post = post
@opts = opts
- @user = user
+ @actor = actor
end
def valid?
@@ -32,7 +37,8 @@ module DiscourseWorkflows
{
post: serialize_post(@post),
topic: serialize_topic_list_item(topic),
- user: serialize_user(@user),
+ user: serialize_user(@actor),
+ actor: serialize_user(@actor),
}
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like/v1.rb
index a7b298be055..27e57f5dca0 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like/v1.rb
@@ -5,21 +5,21 @@ module DiscourseWorkflows
module PostLike
class V1 < NodeType
OPERATIONS = %w[like unlike].freeze
- OUTPUT_SCHEMA = {
- "$schema" => Schema::DRAFT_URI,
- "type" => "object",
- "properties" => {
- "post_id" => {
- "type" => "integer",
- },
- "username" => {
- "type" => "string",
- },
- "changed" => {
- "type" => "boolean",
- },
- },
- }.freeze
+ OUTPUT_SCHEMA =
+ Schema.merge(
+ Schema.document(
+ "post_id" => {
+ "type" => "integer",
+ },
+ "username" => {
+ "type" => "string",
+ },
+ "changed" => {
+ "type" => "boolean",
+ },
+ ),
+ Schema::ACTOR_SCHEMA,
+ ).freeze
description(
name: "action:post_like",
@@ -81,7 +81,7 @@ module DiscourseWorkflows
raise_node_error!(result.errors.full_messages.join(", "), item_index:) if result.failed?
end
- { post_id: post.id, username: actor.username, changed: }
+ { post_id: post.id, username: actor.username, actor: serialize_user(actor), changed: }
end
end
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like_changed/v1.rb
index ce60bfbdc68..b45ca93f734 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/post_like_changed/v1.rb
@@ -11,6 +11,7 @@ module DiscourseWorkflows
Schema::POST_SCHEMA,
Schema::TOPIC_LIST_ITEM_SCHEMA,
Schema::USER_SCHEMA,
+ Schema::ACTOR_SCHEMA,
Schema.document("change" => { "type" => "string", "enum" => CHANGES.values }),
).freeze
@@ -60,6 +61,7 @@ module DiscourseWorkflows
post: serialize_post(@post),
topic: serialize_topic_list_item(@post.topic),
user: serialize_user(@user),
+ actor: serialize_user(@user),
}
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_approved/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_approved/v1.rb
index 9e767c42714..59818988466 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_approved/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_approved/v1.rb
@@ -21,7 +21,7 @@ module DiscourseWorkflows
end
def output
- { reviewable: serialize_reviewable(@reviewable) }
+ { reviewable: serialize_reviewable(@reviewable), actor: serialize_user(@actor) }
end
end
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_status_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_status_changed/v1.rb
index a9a82fbe151..c3383ceb06a 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_status_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/reviewable_status_changed/v1.rb
@@ -14,7 +14,9 @@ module DiscourseWorkflows
group: "discourse_triggers",
palette_visible: false,
event: :reviewable_transitioned_to,
- output_contracts: [{ schema: Schema::REVIEWABLE_EVENT_SCHEMA }],
+ output_contracts: [
+ { schema: Schema.merge(Schema::REVIEWABLE_EVENT_SCHEMA, Schema::ACTOR_SCHEMA) },
+ ],
properties: -> do
{
statuses: {
@@ -43,10 +45,11 @@ module DiscourseWorkflows
)
end
- def initialize(status, reviewable)
+ def initialize(status, reviewable, payload = {})
super(parameters: {})
@status = status.to_s
@reviewable = reviewable
+ @actor = payload[:acting_user]
end
def valid?
@@ -56,7 +59,10 @@ module DiscourseWorkflows
end
def output
- { reviewable: serialize_reviewable(@reviewable).merge(status: @status) }
+ {
+ reviewable: serialize_reviewable(@reviewable).merge(status: @status),
+ actor: serialize_user(@actor),
+ }
end
def matches?(trigger_ctx)
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb
index 29e161674a2..8883ec026a2 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_closed/v1.rb
@@ -10,12 +10,14 @@ module DiscourseWorkflows
icon: "lock",
color: "grey",
},
- output_contracts: [{ schema: Schema::TOPIC_LIST_ITEM_SCHEMA }],
+ output_contracts: [
+ { schema: Schema.merge(Schema::TOPIC_LIST_ITEM_SCHEMA, Schema::ACTOR_SCHEMA) },
+ ],
),
)
def output
- { topic: serialize_topic_list_item(@topic) }
+ { topic: serialize_topic_list_item(@topic), actor: serialize_user(@actor) }
end
end
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_status_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_status_changed/v1.rb
index 04ff4a4d6a1..a827cb36d83 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_status_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_status_changed/v1.rb
@@ -15,6 +15,7 @@ module DiscourseWorkflows
OUTPUT_SCHEMA =
Schema.merge(
Schema::TOPIC_LIST_ITEM_SCHEMA,
+ Schema::ACTOR_SCHEMA,
Schema.document(
"status" => {
"type" => "string",
@@ -60,11 +61,12 @@ module DiscourseWorkflows
)
end
- def initialize(topic, status, enabled)
+ def initialize(topic, status, enabled, payload = {})
super(parameters: {})
@topic = topic
@status = status.to_s == "autoclosed" ? "closed" : status.to_s
@enabled = enabled
+ @actor = payload[:acting_user]
end
def valid?
@@ -76,6 +78,7 @@ module DiscourseWorkflows
def output
{
topic: serialize_topic_list_item(@topic),
+ actor: serialize_user(@actor),
status: @status,
enabled: @enabled,
change: change,
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb
index 64cf40555d0..21f74f38c62 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/nodes/topic_tag_changed/v1.rb
@@ -8,12 +8,10 @@ module DiscourseWorkflows
OUTPUT_SCHEMA =
Schema.merge(
Schema::TOPIC_LIST_ITEM_SCHEMA,
- {
- "$schema" => Schema::DRAFT_URI,
- "type" => "object",
- "properties" =>
- %w[old_tags new_tags added_tags removed_tags].index_with { TAG_LIST_SCHEMA },
- },
+ Schema::ACTOR_SCHEMA,
+ Schema.document(
+ %w[old_tags new_tags added_tags removed_tags].index_with { TAG_LIST_SCHEMA },
+ ),
).freeze
description(
@@ -50,6 +48,7 @@ module DiscourseWorkflows
new_tags: @new_tag_names,
added_tags: added_tags,
removed_tags: removed_tags,
+ actor: serialize_user(@user),
}
end
diff --git a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
index 20c27afb081..0354e6efc42 100644
--- a/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
+++ b/plugins/discourse-workflows/lib/discourse_workflows/schema.rb
@@ -170,6 +170,7 @@ module DiscourseWorkflows
POST_SCHEMA = entity("post", POST_PROPERTIES, "DiscourseWorkflows::PostSerializer payload")
USER_SCHEMA = entity("user", USER_PROPERTIES, "Basic safe user attributes")
ACTOR_SCHEMA = document("actor" => nullable_user("User who performed the action"))
+ POST_AUTHOR_SCHEMA = document("user" => nullable_user("Post author"))
ASSIGNEE_PROPERTIES = {
"type" => "object",
"properties" => {
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb
index 1efeb8adad1..82d1f504868 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_lifecycle_spec.rb
@@ -36,7 +36,8 @@ RSpec.describe DiscourseWorkflows::Nodes::PostLifecycle do
end
describe "#output" do
- it "returns the post, its topic, and the acting user", :aggregate_failures do
+ it "returns the post, its topic and the acting user as both user and actor",
+ :aggregate_failures do
output = trigger.output
expect(output[:post]).to include(
@@ -54,6 +55,7 @@ RSpec.describe DiscourseWorkflows::Nodes::PostLifecycle do
username: topic.user.username,
)
expect(output[:user]).to include(id: actor.id, username: actor.username)
+ expect(output[:actor]).to include(id: actor.id, username: actor.username)
expect(output).to match_node_output_schema(klass)
end
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_like_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_like_spec.rb
index 5a4e32f2f23..b306cd7b334 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_like_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/post_like_spec.rb
@@ -15,7 +15,12 @@ RSpec.describe DiscourseWorkflows::Nodes::PostLike::V1 do
it "likes the post as the actor" do
result = execute_node(configuration:)
- expect(result).to eq("post_id" => post.id, "username" => actor.username, "changed" => true)
+ expect(result).to include(
+ "post_id" => post.id,
+ "username" => actor.username,
+ "changed" => true,
+ "actor" => include("username" => actor.username),
+ )
expect(result).to match_node_output_schema(described_class)
expect(post.reload.like_count).to eq(1)
end
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb
index 0e29f3bbe4b..c772e8d5aae 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_approved_spec.rb
@@ -42,10 +42,12 @@ RSpec.describe DiscourseWorkflows::Nodes::ReviewableApproved::V1 do
describe "#output" do
it "returns reviewable data", :aggregate_failures do
+ moderator = Fabricate(:moderator)
reviewable.update!(status: :approved)
- output = described_class.new(:approved, reviewable).output
+ output = described_class.new(:approved, reviewable, acting_user: moderator).output
expect(output[:reviewable]).to include(status: "approved")
+ expect(output[:actor]).to include(id: moderator.id, username: moderator.username)
expect(output).to match_node_output_schema(described_class)
end
end
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb
index 6dd73f18785..59f65af709d 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/reviewable_status_changed_spec.rb
@@ -43,6 +43,21 @@ RSpec.describe DiscourseWorkflows::Nodes::ReviewableStatusChanged::V1 do
end
describe "#output" do
+ it "exposes the new status and the reviewer who transitioned the reviewable",
+ :aggregate_failures do
+ moderator = Fabricate(:moderator)
+ events =
+ DiscourseEvent.track_events(:reviewable_transitioned_to) do
+ reviewable.transition_to(:rejected, moderator)
+ end
+
+ output = described_class.new(*events.sole[:params]).output
+
+ expect(output[:reviewable]).to include(status: "rejected")
+ expect(output[:actor]).to include(id: moderator.id, username: moderator.username)
+ expect(output).to match_node_output_schema(described_class)
+ end
+
it "uses the target account for user reviewables" do
reviewable_user = Fabricate(:reviewable_user)
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_closed_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_closed_spec.rb
index 1378a6b856f..0662f6242e2 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_closed_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_closed_spec.rb
@@ -10,12 +10,14 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicClosed::V1 do
end
describe "#output" do
- it "returns topic_id and tags" do
- trigger = described_class.new(topic, "closed", true)
- output = trigger.output
+ it "returns the topic and the actor", :aggregate_failures do
+ moderator = Fabricate(:moderator)
+ output = described_class.new(topic, "closed", true, acting_user: moderator).output
expect(output[:topic][:id]).to eq(topic.id)
expect(output[:topic][:tags].map { |topic_tag| topic_tag[:name] }).to eq(["test-tag"])
+ expect(output[:actor]).to include(id: moderator.id, username: moderator.username)
+ expect(output).to match_node_output_schema(described_class)
end
end
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_status_changed_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_status_changed_spec.rb
index d715b54fb26..949a91c98a5 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_status_changed_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_status_changed_spec.rb
@@ -34,7 +34,7 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicStatusChanged::V1 do
output = trigger.output
expect(output).to match_node_output_schema(node_class)
if change == "closed"
- expect(output.keys).to eq([:topic])
+ expect(output.keys).to eq(%i[topic actor])
else
expect(output).to include(status: status, enabled: enabled, change: change)
end
@@ -76,6 +76,19 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicStatusChanged::V1 do
end
end
+ it "exposes the user who changed the status" do
+ admin = Fabricate(:admin)
+ events =
+ DiscourseEvent.track_events(:topic_status_updated) do
+ topic.update_status("archived", true, admin)
+ end
+
+ output = described_class.new(*events.sole[:params]).output
+
+ expect(output[:actor]).to include(id: admin.id, username: admin.username)
+ expect(output).to match_node_output_schema(described_class)
+ end
+
describe "#matches?" do
it "matches selected changes including automatic changes" do
trigger = described_class.new(topic, "autoclosed", false)
diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tag_changed_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tag_changed_spec.rb
index bd721b58d47..4e20cbe2a5b 100644
--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tag_changed_spec.rb
+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/nodes/topic_tag_changed_spec.rb
@@ -44,6 +44,7 @@ RSpec.describe DiscourseWorkflows::Nodes::TopicTagChanged::V1 do
expect(output[:added_tags]).to eq(%w[urgent])
expect(output[:removed_tags]).to eq(%w[help])
expect(output[:topic][:posters].map { |poster| poster[:user_id] }).to include(topic.user_id)
+ expect(output[:actor]).to include(id: topic.user.id, username: topic.user.username)
expect(output).to match_node_output_schema(described_class)
end
diff --git a/spec/models/reviewable_spec.rb b/spec/models/reviewable_spec.rb
index ffbabfd4563..b6d12fccb0a 100644
--- a/spec/models/reviewable_spec.rb
+++ b/spec/models/reviewable_spec.rb
@@ -640,6 +640,7 @@ RSpec.describe Reviewable, type: :model do
expect(event).to be_present
expect(event[:params][0]).to eq(:approved)
expect(event[:params][1]).to eq(reviewable)
+ expect(event[:params][2]).to eq(acting_user: moderator)
end
end
diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb
index 537dfbe8a2f..53d444f0a52 100644
--- a/spec/models/topic_spec.rb
+++ b/spec/models/topic_spec.rb
@@ -1610,7 +1610,9 @@ RSpec.describe Topic do
2.times { topic.update_status("closed", true, user) }
end
- expect(events.map { |event| event[:params] }).to eq([[topic, "closed", true]])
+ expect(events.map { |event| event[:params] }).to eq(
+ [[topic, "closed", true, { acting_user: user }]],
+ )
end
it "emits pin status events only when pin attributes change" do
@@ -1624,7 +1626,10 @@ RSpec.describe Topic do
end
expect(events.map { |event| event[:params] }).to eq(
- [[topic, "pinned", true], [topic, "pinned", false]],
+ [
+ [topic, "pinned", true, { acting_user: user }],
+ [topic, "pinned", false, { acting_user: user }],
+ ],
)
end
@@ -1642,9 +1647,9 @@ RSpec.describe Topic do
expect(events.map { |event| event[:params] }).to eq(
[
- [topic, "pinned", true],
- [topic, "pinned_globally", true],
- [topic, "pinned_globally", true],
+ [topic, "pinned", true, { acting_user: user }],
+ [topic, "pinned_globally", true, { acting_user: user }],
+ [topic, "pinned_globally", true, { acting_user: user }],
],
)
end
diff --git a/spec/services/topic_status_updater_spec.rb b/spec/services/topic_status_updater_spec.rb
index dbd7c6aa5eb..00182607eb9 100644
--- a/spec/services/topic_status_updater_spec.rb
+++ b/spec/services/topic_status_updater_spec.rb
@@ -23,7 +23,9 @@ RSpec.describe TopicStatusUpdater do
described_class.new(topic, admin).update!("closed", true)
end
- expect(events.map { |event| event[:params] }).to eq([[topic, "closed", true]])
+ expect(events.map { |event| event[:params] }).to eq(
+ [[topic, "closed", true, { acting_user: admin }]],
+ )
ensure
DiscourseEvent.off(:topic_status_updated, &handler) if handler
end