mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:40:00 +08:00
FIX: Should not generate payload until active webhooks are exist
This commit is contained in:
parent
8cd4ceba49
commit
f2c3415548
|
@ -7,7 +7,7 @@ module HasDestroyedWebHook
|
|||
|
||||
def enqueue_destroyed_web_hook
|
||||
type = 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?
|
||||
yield
|
||||
WebHook.enqueue_hooks(type, "#{type}_destroyed".to_sym,
|
||||
id: id,
|
||||
|
|
|
@ -45,12 +45,12 @@ class PostDestroyer
|
|||
end
|
||||
|
||||
def destroy
|
||||
payload = WebHook.generate_payload(:post, @post)
|
||||
payload = WebHook.generate_payload(:post, @post) if WebHook.active_web_hooks(:post).exists?
|
||||
topic = @post.topic
|
||||
|
||||
if @post.is_first_post? && topic
|
||||
topic_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?
|
||||
end
|
||||
|
||||
delete_removed_posts_after = @opts[:delete_removed_posts_after] || SiteSetting.delete_removed_posts_after
|
||||
|
|
|
@ -125,10 +125,13 @@ describe WebHook do
|
|||
end
|
||||
|
||||
describe 'when there are no active hooks' do
|
||||
it 'should not enqueue anything' do
|
||||
it 'should not generate payload and enqueue anything' do
|
||||
topic_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).destroy
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -384,6 +387,12 @@ describe WebHook do
|
|||
expect(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' do
|
||||
post = Fabricate(:post)
|
||||
admin = Fabricate(:admin)
|
||||
|
|
Loading…
Reference in New Issue
Block a user