From b7ebe574df25454e4174c12e73e2eb06b5f984b4 Mon Sep 17 00:00:00 2001 From: Ryan Boder Date: Tue, 1 Oct 2019 21:41:33 -0400 Subject: [PATCH] FEATURE: Add topic and category context to post webhook payload (#8110) Adds additional fields topic_archetype and category_slug to the post webhook so that handlers have some context about the post event without having to call back to the API. Discussed [here](https://meta.discourse.org/t/webhooks-how-best-to-differentiate-a-pm-from-a-public-post/76363/13). --- app/serializers/web_hook_post_serializer.rb | 16 +++++++++++++++- .../serializers/web_hook_post_serializer_spec.rb | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/serializers/web_hook_post_serializer.rb b/app/serializers/web_hook_post_serializer.rb index 2f78f3ca88..030b55203b 100644 --- a/app/serializers/web_hook_post_serializer.rb +++ b/app/serializers/web_hook_post_serializer.rb @@ -2,7 +2,9 @@ class WebHookPostSerializer < PostSerializer - attributes :topic_posts_count + attributes :topic_posts_count, + :topic_archetype, + :category_slug def include_topic_title? true @@ -32,6 +34,18 @@ class WebHookPostSerializer < PostSerializer object.topic ? object.topic.posts_count : 0 end + def topic_archetype + object.topic ? object.topic.archetype : '' + end + + def include_category_slug? + object.topic && object.topic.category + end + + def category_slug + object.topic && object.topic.category ? object.topic.category.slug_for_url : '' + end + def include_readers_count? false end diff --git a/spec/serializers/web_hook_post_serializer_spec.rb b/spec/serializers/web_hook_post_serializer_spec.rb index 7d0cae9845..c844fda4b7 100644 --- a/spec/serializers/web_hook_post_serializer_spec.rb +++ b/spec/serializers/web_hook_post_serializer_spec.rb @@ -12,7 +12,7 @@ RSpec.describe WebHookPostSerializer do it 'should only include the required keys' do count = serialized_for_user(admin).keys.count - difference = count - 36 + difference = count - 38 expect(difference).to eq(0), lambda { message = +""