Merge pull request #4437 from fantasticfears/webhooks-event-name
FIX: show event name in webhook headers
This commit is contained in:
commit
451050c6c4
|
@ -49,7 +49,7 @@ module Jobs
|
||||||
'X-Discourse-Event-Id' => web_hook_event.id,
|
'X-Discourse-Event-Id' => web_hook_event.id,
|
||||||
'X-Discourse-Event-Type' => @opts[:event_type]
|
'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?
|
if @web_hook.secret.present?
|
||||||
headers['X-Discourse-Event-Signature'] = "sha256=" + OpenSSL::HMAC.hexdigest("sha256", @web_hook.secret, body)
|
headers['X-Discourse-Event-Signature'] = "sha256=" + OpenSSL::HMAC.hexdigest("sha256", @web_hook.secret, body)
|
||||||
|
|
|
@ -40,18 +40,18 @@ class WebHook < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.enqueue_topic_hooks(topic, user)
|
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)
|
WebHook.enqueue_hooks(:topic, topic_id: topic.id, user_id: user&.id, category_id: topic&.category&.id, event_name: event.to_s)
|
||||||
end
|
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(topic, user)
|
WebHook.enqueue_topic_hooks(event, topic, user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
DiscourseEvent.on(:topic_created) do |topic, _, user|
|
DiscourseEvent.on(:topic_created) do |topic, _, user|
|
||||||
WebHook.enqueue_topic_hooks(topic, user)
|
WebHook.enqueue_topic_hooks(:topic_created, topic, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
%i(post_created
|
%i(post_created
|
||||||
|
@ -63,7 +63,8 @@ class WebHook < ActiveRecord::Base
|
||||||
post_id: post.id,
|
post_id: post.id,
|
||||||
topic_id: post&.topic&.id,
|
topic_id: post&.topic&.id,
|
||||||
user_id: user&.id,
|
user_id: user&.id,
|
||||||
category_id: post.topic&.category&.id
|
category_id: post.topic&.category&.id,
|
||||||
|
event_name: event.to_s
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue