mirror of
https://github.com/discourse/discourse.git
synced 2025-05-28 22:37:37 +08:00
DEV: Async category search for sidebar modal (#25686)
This commit is contained in:

committed by
GitHub

parent
716e3a4dd5
commit
13083d03ae
@ -341,6 +341,12 @@ class CategoriesController < ApplicationController
|
||||
else
|
||||
true
|
||||
end
|
||||
include_ancestors =
|
||||
if params[:include_ancestors].present?
|
||||
ActiveModel::Type::Boolean.new.cast(params[:include_ancestors])
|
||||
else
|
||||
false
|
||||
end
|
||||
prioritized_category_id = params[:prioritized_category_id].to_i if params[
|
||||
:prioritized_category_id
|
||||
].present?
|
||||
@ -388,7 +394,18 @@ class CategoriesController < ApplicationController
|
||||
|
||||
Category.preload_user_fields!(guardian, categories)
|
||||
|
||||
render_serialized(categories, SiteCategorySerializer, root: :categories, scope: guardian)
|
||||
if include_ancestors
|
||||
ancestors = Category.secured(guardian).ancestors_of(categories.map(&:id))
|
||||
|
||||
render_json_dump(
|
||||
{
|
||||
categories: serialize_data(categories, SiteCategorySerializer, scope: guardian),
|
||||
ancestors: serialize_data(ancestors, SiteCategorySerializer, scope: guardian),
|
||||
},
|
||||
)
|
||||
else
|
||||
render_serialized(categories, SiteCategorySerializer, root: :categories, scope: guardian)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
Reference in New Issue
Block a user