FIX: Missing topic edited web hook when publishing a topic.

This commit is contained in:
Guo Xiang Tan 2019-04-16 14:09:51 +08:00
parent d6e45864ce
commit 8cb1890245
4 changed files with 28 additions and 1 deletions

@ -299,6 +299,7 @@ class TopicsController < ApplicationController
if 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)
else

@ -8,12 +8,15 @@ class TopicPublisher
def publish!
published_at = Time.zone.now
TopicTimestampChanger.new(timestamp: published_at, topic: @topic).change! do
if @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 artifacts
SharedDraft.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,

@ -34,10 +34,12 @@ describe TopicPublisher do
expect(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 OP

@ -173,6 +173,24 @@ describe WebHook do
payload = 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)
end
describe 'when topic has been deleted' do