From 77c92fd6742c6ede5f7570fd93716b68cb0b04c2 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Tue, 4 May 2021 06:05:08 +0300 Subject: [PATCH] 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. --- app/models/category_list.rb | 2 +- spec/requests/categories_controller_spec.rb | 24 +++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/app/models/category_list.rb b/app/models/category_list.rb index 7488a76178e..babb15164a0 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -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 diff --git a/spec/requests/categories_controller_spec.rb b/spec/requests/categories_controller_spec.rb index ddbc383ac89..fc170246928 100644 --- a/spec/requests/categories_controller_spec.rb +++ b/spec/requests/categories_controller_spec.rb @@ -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