Skip to content

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

Don't enqueue topic webhook unless a post has a topic

scossar9d0807224bc8
diff --git a/config/initializers/012-web_hook_events.rb b/config/initializers/012-web_hook_events.rb
index ad5d94dcce1..2a844926948 100644
--- a/config/initializers/012-web_hook_events.rb
+++ b/config/initializers/012-web_hook_events.rb
@@ -18,8 +18,13 @@ end
end
DiscourseEvent.on(:post_edited) do |post, topic_changed|
- WebHook.enqueue_post_hooks(:post_edited, post)
- WebHook.enqueue_topic_hooks(:topic_edited, post.topic) if post.is_first_post? && topic_changed
+ if post.topic
+ WebHook.enqueue_post_hooks(:post_edited, post)
+
+ if post.is_first_post? && topic_changed
+ WebHook.enqueue_topic_hooks(:topic_edited, post.topic)
+ end
+ end
end
%i(
diff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rb
index 73f4470c8f4..fe4e9a2de2c 100644
--- a/spec/models/web_hook_spec.rb
+++ b/spec/models/web_hook_spec.rb
@@ -145,6 +145,24 @@ describe WebHook do
end
end
+ describe 'when topic has been deleted' do
+ it 'should not enqueue a post/topic edited hooks' do
+ topic.trash!
+ post.reload
+
+ PostRevisor.new(post, topic).revise!(
+ post.user,
+ {
+ category_id: Category.last.id,
+ raw: "#{post.raw} new"
+ },
+ {}
+ )
+
+ expect(Jobs::EmitWebHookEvent.jobs.count).to eq(0)
+ end
+ end
+
it 'should enqueue the right hooks for post events' do
Fabricate(:web_hook)
@@ -188,7 +206,7 @@ describe WebHook do
end
it 'should enqueue the right hooks for user events' do
- _user_web_hook = Fabricate(:user_web_hook, active: true)
+ Fabricate(:user_web_hook, active: true)
Sidekiq::Testing.fake! do
user