FIX: post edited webhook does not reflect updated topic title
This fix ensures that when a topic title is edited the new title shows up in the post webhook instead of the old title. Rather than passing in the old topic object to the PostRevisor the PostRevisor initializer will load the updated topic object inside of the initializer if you don't pass it in. This will allow the post_edited webhook to have the correct topic values. Original bug reported at: https://meta.discourse.org/t/post-edited-webhook-does-not-reflect-updated-topic-title/144722
This commit is contained in:
parent
dbfec4b268
commit
c97244ca11
|
@ -366,7 +366,7 @@ class TopicsController < ApplicationController
|
|||
|
||||
if changes.length > 0
|
||||
first_post = topic.ordered_posts.first
|
||||
success = PostRevisor.new(first_post, topic).revise!(current_user, changes, validate_post: false)
|
||||
success = PostRevisor.new(first_post).revise!(current_user, changes, validate_post: false)
|
||||
end
|
||||
|
||||
# this is used to return the title to the client as it may have been changed by "TextCleaner"
|
||||
|
|
|
@ -946,6 +946,9 @@ RSpec.describe TopicsController do
|
|||
end
|
||||
|
||||
describe 'with permission' do
|
||||
fab!(:post_hook) { Fabricate(:post_web_hook) }
|
||||
fab!(:topic_hook) { Fabricate(:topic_web_hook) }
|
||||
|
||||
it 'succeeds' do
|
||||
put "/t/#{topic.slug}/#{topic.id}.json"
|
||||
|
||||
|
@ -971,6 +974,13 @@ RSpec.describe TopicsController do
|
|||
|
||||
topic.reload
|
||||
expect(topic.title).to eq('This is a new title for the topic')
|
||||
|
||||
expect(Jobs::EmitWebHookEvent.jobs.length).to eq(2)
|
||||
job_args = Jobs::EmitWebHookEvent.jobs[0]["args"].first
|
||||
|
||||
expect(job_args["event_name"]).to eq("post_edited")
|
||||
payload = JSON.parse(job_args["payload"])
|
||||
expect(payload["topic_title"]).to eq('This is a new title for the topic')
|
||||
end
|
||||
|
||||
it "returns errors with invalid titles" do
|
||||
|
|
Loading…
Reference in New Issue