DEV: Include raw in post webhook serializer

DEV: Include raw in post webhook serializer

This came in as a request on meta to include the raw field in the post webhook serializer.

https://meta.discourse.org/t/-/49045/55?u=blake

Including this field can prevent needing to make a 2nd API request to get the raw field of a post.

It would be handy down the road if we updated the webhook ui to specify fields or arguments that you wanted to be included in the serialized data, but most requests I’ve seen to update the serializers have been valid requests that are good to add anyways, so I don’t think we have reached that point yet.

diff --git a/app/serializers/web_hook_post_serializer.rb b/app/serializers/web_hook_post_serializer.rb
index 2099a17..4c5176c 100644
--- a/app/serializers/web_hook_post_serializer.rb
+++ b/app/serializers/web_hook_post_serializer.rb
@@ -11,6 +11,10 @@ class WebHookPostSerializer < PostSerializer
     true
   end
 
+  def include_raw?
+    true
+  end
+
   %i{
     can_view
     can_edit
diff --git a/spec/serializers/web_hook_post_serializer_spec.rb b/spec/serializers/web_hook_post_serializer_spec.rb
index 790a132..9e5c1f6 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 - 39
+    difference = count - 40
 
     expect(difference).to eq(0), lambda {
       message = +""

GitHub sha: 1ce6ff0a

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/setting-up-webhooks/49045/56