FIX: Serialize categories for group posts (#26663)

This is necessary when "lazy load categories" feature is enabled to
make sure the categories are rendered for group posts.
This commit is contained in:
Bianca Nenciu
2024-04-19 16:33:37 +03:00
committed by GitHub
parent bf715c8235
commit 1deeff2336
4 changed files with 1064 additions and 1051 deletions

View File

@ -196,7 +196,16 @@ class GroupsController < ApplicationController
posts =
group.posts_for(guardian, params.permit(:before_post_id, :before, :category_id)).limit(20)
render_serialized posts.to_a, GroupPostSerializer
response = { posts: serialize_data(posts, GroupPostSerializer) }
if guardian.can_lazy_load_categories?
category_ids = posts.map { |p| p.topic.category_id }.compact.uniq
categories = Category.secured(guardian).with_parents(category_ids)
response[:categories] = serialize_data(categories, CategoryBadgeSerializer)
end
render json: response
end
def posts_feed