mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 04:19:05 +08:00
1ce6ff0a55
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.
62 lines
1.1 KiB
Ruby
62 lines
1.1 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WebHookPostSerializer < PostSerializer
|
|
|
|
attributes :topic_posts_count,
|
|
:topic_filtered_posts_count,
|
|
:topic_archetype,
|
|
:category_slug
|
|
|
|
def include_topic_title?
|
|
true
|
|
end
|
|
|
|
def include_raw?
|
|
true
|
|
end
|
|
|
|
%i{
|
|
can_view
|
|
can_edit
|
|
can_delete
|
|
can_recover
|
|
can_wiki
|
|
actions_summary
|
|
can_view_edit_history
|
|
yours
|
|
primary_group_flair_url
|
|
primary_group_flair_bg_color
|
|
primary_group_flair_color
|
|
notice_args
|
|
notice_type
|
|
}.each do |attr|
|
|
define_method("include_#{attr}?") do
|
|
false
|
|
end
|
|
end
|
|
|
|
def topic_posts_count
|
|
object.topic ? object.topic.posts_count : 0
|
|
end
|
|
|
|
def topic_filtered_posts_count
|
|
object.topic ? object.topic.posts.where(post_type: Post.types[:regular]).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
|
|
end
|