Merge pull request #4437 from fantasticfears/webhooks-event-name

FIX: show event name in webhook headers
This commit is contained in:
Guo Xiang Tan 2016-09-16 14:27:12 +08:00 committed by GitHub
commit 451050c6c4
2 changed files with 7 additions and 6 deletions

View File

@ -49,7 +49,7 @@ module Jobs
'X-Discourse-Event-Id' => web_hook_event.id,
'X-Discourse-Event-Type' => @opts[:event_type]
}
headers['X-Discourse-Event'] = @opts[:event_name] if @opts[:event_name].present?
headers['X-Discourse-Event'] = @opts[:event_name].to_s if @opts[:event_name].present?
if @web_hook.secret.present?
headers['X-Discourse-Event-Signature'] = "sha256=" + OpenSSL::HMAC.hexdigest("sha256", @web_hook.secret, body)

View File

@ -40,18 +40,18 @@ class WebHook < ActiveRecord::Base
end
end
def self.enqueue_topic_hooks(topic, user)
WebHook.enqueue_hooks(:topic, topic_id: topic.id, user_id: user&.id, category_id: topic&.category&.id)
def self.enqueue_topic_hooks(event, topic, user)
WebHook.enqueue_hooks(:topic, topic_id: topic.id, user_id: user&.id, category_id: 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(topic, user)
WebHook.enqueue_topic_hooks(event, topic, user)
end
end
DiscourseEvent.on(:topic_created) do |topic, _, user|
WebHook.enqueue_topic_hooks(topic, user)
WebHook.enqueue_topic_hooks(:topic_created, topic, user)
end
%i(post_created
@ -63,7 +63,8 @@ class WebHook < ActiveRecord::Base
post_id: post.id,
topic_id: post&.topic&.id,
user_id: user&.id,
category_id: post.topic&.category&.id
category_id: post.topic&.category&.id,
event_name: event.to_s
)
end
end