A platform for community discussion. Free, open, simple.
UX: Exclude child catgegories of muted category in similar to search (#19414)
Alan Guo Xiang Tan332ac0f299fb
diff --git a/app/models/topic.rb b/app/models/topic.rbindex f917f4fdeb2..8c407873e16 100644--- a/app/models/topic.rb+++ b/app/models/topic.rb@@ -642,7 +642,7 @@ class Topic < ActiveRecord::Baseexcluded_category_ids_sql = <<~SQL#{excluded_category_ids_sql}UNION- #{CategoryUser.where(notification_level: CategoryUser.notification_levels[:muted], user: user).select(:category_id).to_sql}+ #{CategoryUser.muted_category_ids_query(user, include_direct: true).select("categories.id").to_sql}SQLenddiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex 0e1e784bd53..11c13e0a91f 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -701,6 +701,17 @@ RSpec.describe Topic doexpect(Topic.similar_to("has evil trout made any topics?", "", user)).to eq([])end+ it 'does not return topics from child categories where the user has muted the parent category' do+ expect(Topic.similar_to("has evil trout made any topics?", "", user)).to eq([topic])++ parent_category = topic.category+ child_category = Fabricate(:category, parent_category: parent_category)+ topic.update!(category: child_category)+ CategoryUser.create!(category: parent_category, user: user, notification_level: CategoryUser.notification_levels[:muted])++ expect(Topic.similar_to("has evil trout made any topics?", "", user)).to eq([])+ end+context "with secure categories" dofab!(:group) { Fabricate(:group) }fab!(:private_category) { Fabricate(:private_category, group: group) }