FIX: missing post and topic edited webhooks
This commit is contained in:
parent
9afa55a3fd
commit
8c8549b27b
|
@ -40,10 +40,14 @@ class WebHook < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
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)
|
WebHook.enqueue_hooks(:topic, topic_id: topic.id, user_id: user&.id, category_id: topic&.category&.id, event_name: event.to_s)
|
||||||
end
|
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|
|
%i(topic_destroyed topic_recovered).each do |event|
|
||||||
DiscourseEvent.on(event) do |topic, user|
|
DiscourseEvent.on(event) do |topic, user|
|
||||||
WebHook.enqueue_topic_hooks(event, topic, user)
|
WebHook.enqueue_topic_hooks(event, topic, user)
|
||||||
|
@ -57,18 +61,16 @@ class WebHook < ActiveRecord::Base
|
||||||
%i(post_created
|
%i(post_created
|
||||||
post_destroyed
|
post_destroyed
|
||||||
post_recovered).each do |event|
|
post_recovered).each do |event|
|
||||||
|
|
||||||
DiscourseEvent.on(event) do |post, _, user|
|
DiscourseEvent.on(event) do |post, _, user|
|
||||||
WebHook.enqueue_hooks(:post,
|
WebHook.enqueue_post_hooks(event, post, user)
|
||||||
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
|
end
|
||||||
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|
|
%i(user_created user_approved).each do |event|
|
||||||
DiscourseEvent.on(event) do |user|
|
DiscourseEvent.on(event) do |user|
|
||||||
WebHook.enqueue_hooks(:user, user_id: user.id, event_name: event.to_s)
|
WebHook.enqueue_hooks(:user, user_id: user.id, event_name: event.to_s)
|
||||||
|
|
|
@ -446,6 +446,7 @@ class PostRevisor
|
||||||
def post_process_post
|
def post_process_post
|
||||||
@post.invalidate_oneboxes = true
|
@post.invalidate_oneboxes = true
|
||||||
@post.trigger_post_process
|
@post.trigger_post_process
|
||||||
|
DiscourseEvent.trigger(:post_edited, @post, self.topic_changed?)
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_topic_word_counts
|
def update_topic_word_counts
|
||||||
|
|
|
@ -120,14 +120,14 @@ describe WebHook do
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should enqueue the right hooks for post events' do
|
it 'should enqueue the right hooks for post events' do
|
||||||
user # bypass a user_created event
|
WebHook.expects(:enqueue_post_hooks).once
|
||||||
WebHook.expects(:enqueue_hooks).once
|
|
||||||
PostCreator.create(user, { raw: 'post', topic_id: topic.id, reply_to_post_number: 1, skip_validations: true })
|
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
|
PostDestroyer.new(user, post2).destroy
|
||||||
|
|
||||||
WebHook.expects(:enqueue_hooks).once
|
WebHook.expects(:enqueue_post_hooks).twice
|
||||||
PostDestroyer.new(user, post2).recover
|
PostDestroyer.new(user, post2).recover
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue