mirror of
https://github.com/discourse/discourse.git
synced 2025-03-22 17:05:34 +08:00
FIX: Missing topic edited web hook when publishing a topic.
This commit is contained in:
parent
d6e45864ce
commit
8cb1890245
app/controllers
lib
spec
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user