FIX: missing post and topic edited webhooks

This commit is contained in:
Erick Guan 2016-11-04 21:16:30 +01:00
parent 9afa55a3fd
commit 8c8549b27b
No known key found for this signature in database
GPG Key ID: 10075E9E76407351
3 changed files with 16 additions and 13 deletions

View File

@ -40,10 +40,14 @@ class WebHook < ActiveRecord::Base
end
end
def self.enqueue_topic_hooks(event, topic, user)
def self.enqueue_topic_hooks(event, topic, user=nil)
WebHook.enqueue_hooks(:topic, topic_id: topic.id, user_id: user&.id, category_id: topic&.category&.id, event_name: event.to_s)
end
def self.enqueue_post_hooks(event, post, user=nil)
WebHook.enqueue_hooks(:post, post_id: post.id, topic_id: post&.topic&.id, user_id: user&.id, category_id: post&.topic&.category_id, event_name: event.to_s)
end
%i(topic_destroyed topic_recovered).each do |event|
DiscourseEvent.on(event) do |topic, user|
WebHook.enqueue_topic_hooks(event, topic, user)
@ -57,18 +61,16 @@ class WebHook < ActiveRecord::Base
%i(post_created
post_destroyed
post_recovered).each do |event|
DiscourseEvent.on(event) do |post, _, user|
WebHook.enqueue_hooks(:post,
post_id: post.id,
topic_id: post&.topic&.id,
user_id: user&.id,
category_id: post.topic&.category&.id,
event_name: event.to_s
)
WebHook.enqueue_post_hooks(event, post, user)
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
end
%i(user_created user_approved).each do |event|
DiscourseEvent.on(event) do |user|
WebHook.enqueue_hooks(:user, user_id: user.id, event_name: event.to_s)

View File

@ -446,6 +446,7 @@ class PostRevisor
def post_process_post
@post.invalidate_oneboxes = true
@post.trigger_post_process
DiscourseEvent.trigger(:post_edited, @post, self.topic_changed?)
end
def update_topic_word_counts

View File

@ -120,14 +120,14 @@ describe WebHook do
end
it 'should enqueue the right hooks for post events' do
user # bypass a user_created event
WebHook.expects(:enqueue_hooks).once
WebHook.expects(:enqueue_post_hooks).once
PostCreator.create(user, { raw: 'post', topic_id: topic.id, reply_to_post_number: 1, skip_validations: true })
WebHook.expects(:enqueue_hooks).once
# post destroy or recover triggers a moderator post
WebHook.expects(:enqueue_post_hooks).twice
PostDestroyer.new(user, post2).destroy
WebHook.expects(:enqueue_hooks).once
WebHook.expects(:enqueue_post_hooks).twice
PostDestroyer.new(user, post2).recover
end