FIX: Hide Uncategorized unless allow_uncategorized_topics (#12889)

Uncategorized was sometimes visible even if allow_uncategorized_topics
was false. This was especially happening on mobile, if at least one
topic was uncategorized.
This commit is contained in:
Bianca Nenciu 2021-05-04 06:05:08 +03:00 committed by GitHub
parent d1d9f83304
commit 77c92fd674
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

@ -144,7 +144,7 @@ class CategoryList
def prune_empty
return if SiteSetting.allow_uncategorized_topics
@categories.delete_if { |c| c.uncategorized? && c.displayable_topics.blank? }
@categories.delete_if { |c| c.uncategorized? }
end
# Attach some data for serialization to each topic

View File

@ -67,6 +67,19 @@ describe CategoriesController do
SiteSetting.get(:uncategorized_category_id), category.id
)
end
it 'does not show uncategorized unless allow_uncategorized_topics' do
SiteSetting.desktop_category_page_style = "categories_boxes_with_topics"
uncategorized = Category.find(SiteSetting.uncategorized_category_id)
Fabricate(:topic, category: uncategorized)
CategoryFeaturedTopic.feature_topics
SiteSetting.allow_uncategorized_topics = false
get "/categories.json"
expect(response.parsed_body["category_list"]["categories"].map { |x| x['id'] }).not_to include(uncategorized.id)
end
end
context 'extensibility event' do
@ -522,5 +535,16 @@ describe CategoriesController do
expect(json['category_list']['categories'].size).to eq(4)
expect(json['topic_list']['topics'].size).to eq(6)
end
it 'does not show uncategorized unless allow_uncategorized_topics' do
uncategorized = Category.find(SiteSetting.uncategorized_category_id)
Fabricate(:topic, category: uncategorized)
CategoryFeaturedTopic.feature_topics
SiteSetting.allow_uncategorized_topics = false
get "/categories_and_latest.json"
expect(response.parsed_body["category_list"]["categories"].map { |x| x['id'] }).not_to include(uncategorized.id)
end
end
end