A platform for community discussion. Free, open, simple.
FIX: Should not generate payload until active webhooks are exist
Vinoth Kannanf2c341554893
diff --git a/app/models/concerns/has_destroyed_web_hook.rb b/app/models/concerns/has_destroyed_web_hook.rbindex 98d165d070c..081189ff83e 100644--- a/app/models/concerns/has_destroyed_web_hook.rb+++ b/app/models/concerns/has_destroyed_web_hook.rb@@ -7,7 +7,7 @@ module HasDestroyedWebHookdef enqueue_destroyed_web_hooktype = self.class.name.underscore.to_sym- payload = WebHook.generate_payload(type, self)+ payload = WebHook.generate_payload(type, self) if WebHook.active_web_hooks(type).exists?yieldWebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym,id: id,diff --git a/lib/post_destroyer.rb b/lib/post_destroyer.rbindex fee0fc79ea8..9509a965644 100644--- a/lib/post_destroyer.rb+++ b/lib/post_destroyer.rb@@ -45,12 +45,12 @@ class PostDestroyerenddef destroy- payload = WebHook.generate_payload(:post, @post)+ payload = WebHook.generate_payload(:post, @post) if WebHook.active_web_hooks(:post).exists?topic = @post.topicif @post.is_first_post? && topictopic_view = TopicView.new(topic.id, Discourse.system_user)- topic_payload = WebHook.generate_payload(:topic, topic_view, WebHookTopicViewSerializer)+ topic_payload = WebHook.generate_payload(:topic, topic_view, WebHookTopicViewSerializer) if WebHook.active_web_hooks(:topic).exists?enddelete_removed_posts_after = @opts[:delete_removed_posts_after] || SiteSetting.delete_removed_posts_afterdiff --git a/spec/models/web_hook_spec.rb b/spec/models/web_hook_spec.rbindex 67e0f914a02..f424cb0033a 100644--- a/spec/models/web_hook_spec.rb+++ b/spec/models/web_hook_spec.rb@@ -125,10 +125,13 @@ describe WebHook doenddescribe 'when there are no active hooks' do- it 'should not enqueue anything' do+ it 'should not generate payload and enqueue anything' dotopic_web_hook.destroy!post = PostCreator.create(user, raw: 'post', title: 'topic', skip_validations: true)expect(Jobs::EmitWebHookEvent.jobs.length).to eq(0)++ WebHook.expects(:generate_payload).times(0)+ PostDestroyer.new(admin, post).destroyendend@@ -384,6 +387,12 @@ describe WebHook doexpect(payload["id"]).to eq(tag.id)end+ it 'should not generate payload if webhooks not exist' do+ WebHook.expects(:generate_payload).times(0)+ tag = Fabricate(:tag)+ tag.destroy!+ end+it 'should enqueue the right hooks for flag events' dopost = Fabricate(:post)admin = Fabricate(:admin)