From 742314082542c0cabaf0766ce3e24fe8dff88cef Mon Sep 17 00:00:00 2001 From: Erick Guan Date: Mon, 12 Sep 2016 17:48:54 +0800 Subject: [PATCH] FIX: show event name in webhook headers --- app/jobs/regular/emit_web_hook_event.rb | 2 +- app/models/web_hook.rb | 11 ++++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/app/jobs/regular/emit_web_hook_event.rb b/app/jobs/regular/emit_web_hook_event.rb index 56a31b6c7..d3315b33f 100644 --- a/app/jobs/regular/emit_web_hook_event.rb +++ b/app/jobs/regular/emit_web_hook_event.rb @@ -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) diff --git a/app/models/web_hook.rb b/app/models/web_hook.rb index de1fc9d12..823df4233 100644 --- a/app/models/web_hook.rb +++ b/app/models/web_hook.rb @@ -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