FIX: show event name in webhook headers

This commit is contained in:
Erick Guan 2016-09-12 17:48:54 +08:00
parent 2d859ba0ed
commit 7423140825
No known key found for this signature in database
GPG key ID: 10075E9E76407351
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