FIX: Preload user-specific category fields (#25663)
This is used when lazy_load_categories is enabled to fetch more info about the category.
This commit is contained in:
parent
1f50e7e38f
commit
9a6406d4bb
|
@ -240,7 +240,11 @@ class Category < ActiveRecord::Base
|
|||
|
||||
# Categories with children
|
||||
with_children =
|
||||
Category.where(parent_category_id: category_ids).pluck(:parent_category_id).to_set
|
||||
Category
|
||||
.secured(@guardian)
|
||||
.where(parent_category_id: category_ids)
|
||||
.pluck(:parent_category_id)
|
||||
.to_set
|
||||
|
||||
# Update category attributes
|
||||
categories.each do |category|
|
||||
|
|
|
@ -1041,6 +1041,7 @@ RSpec.describe CategoriesController do
|
|||
end
|
||||
|
||||
describe "#find" do
|
||||
fab!(:group)
|
||||
fab!(:category) { Fabricate(:category, name: "Foo") }
|
||||
fab!(:subcategory) { Fabricate(:category, name: "Foobar", parent_category: category) }
|
||||
|
||||
|
@ -1051,6 +1052,17 @@ RSpec.describe CategoriesController do
|
|||
expect(response.parsed_body["categories"].map { |c| c["id"] }).to eq([subcategory.id])
|
||||
end
|
||||
|
||||
it "preloads user-specific fields" do
|
||||
subcategory.update!(read_restricted: true)
|
||||
|
||||
get "/categories/find.json", params: { ids: [category.id] }
|
||||
|
||||
serialized = response.parsed_body["categories"].first
|
||||
expect(serialized["notification_level"]).to eq(CategoryUser.default_notification_level)
|
||||
expect(serialized["permission"]).to eq(nil)
|
||||
expect(serialized["has_children"]).to eq(false)
|
||||
end
|
||||
|
||||
it "does not return hidden category" do
|
||||
category.update!(read_restricted: true)
|
||||
|
||||
|
|
Loading…
Reference in New Issue