A platform for community discussion. Free, open, simple.
FIX: Missing topic edited web hook when publishing a topic.
Guo Xiang Tan8cb189024506
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 5b13b17838a..220a75b5cf7 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -299,6 +299,7 @@ class TopicsController < ApplicationControllerif params[:category_id] && (params[:category_id].to_i != topic.category_id.to_i)category = Category.find_by(id: params[:category_id])+if category || (params[:category_id].to_i == 0)guardian.ensure_can_move_topic_to_category!(category)elsediff --git a/lib/topic_publisher.rb b/lib/topic_publisher.rbindex a7cecb7e4fc..f9934e98765 100644--- a/lib/topic_publisher.rb+++ b/lib/topic_publisher.rb@@ -8,12 +8,15 @@ class TopicPublisherdef publish!published_at = Time.zone.now+TopicTimestampChanger.new(timestamp: published_at, topic: @topic).change! doif @topic.private_message?@topic = TopicConverter.new(@topic, @published_by).convert_to_public_topic(@category_id)else- @topic.change_category_to_id(@category_id)+ PostRevisor.new(@topic.first_post, @topic).revise!(@published_by,+ category_id: @category_id,+ )end@topic.update_columns(visible: true)@@ -22,14 +25,17 @@ class TopicPublisher# Clean up any publishing artifactsSharedDraft.where(topic: @topic).delete_all+TopicTimer.where(topic: @topic).update_all(deleted_at: DateTime.now,deleted_by_id: @published_by.id)op = @topic.first_post+if op.present?op.revisions.delete_all+op.update_columns(version: 1,public_version: 1,diff --git a/spec/components/topic_publisher_spec.rb b/spec/components/topic_publisher_spec.rbindex 43d33172f58..897ef297ef8 100644--- a/spec/components/topic_publisher_spec.rb+++ b/spec/components/topic_publisher_spec.rb@@ -34,10 +34,12 @@ describe TopicPublisher doexpect(topic.created_at).to eq(published_at)expect(topic.updated_at).to eq(published_at)expect(topic.shared_draft).to be_blank+expect(UserHistory.where(acting_user_id: moderator.id,action: UserHistory.actions[:topic_published])).to be_present+op.reload# Should delete any edits on the OPdiff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rbindex 915374f2f59..27094beae48 100644--- a/spec/models/web_hook_spec.rb+++ b/spec/models/web_hook_spec.rb@@ -173,6 +173,24 @@ describe WebHook dopayload = JSON.parse(job_args["payload"])expect(payload["id"]).to eq(topic_id)end++ category = Fabricate(:category)++ expect do+ PostRevisor.new(post, post.topic).revise!(+ post.user,+ {+ category_id: category.id,+ }+ )+ end.to change { Jobs::EmitWebHookEvent.jobs.length }.by(1)++ job_args = Jobs::EmitWebHookEvent.jobs.last["args"].first++ expect(job_args["event_name"]).to eq("topic_edited")+ payload = JSON.parse(job_args["payload"])+ expect(payload["id"]).to eq(topic_id)+ expect(payload["category_id"]).to eq(category.id)enddescribe 'when topic has been deleted' do