FIX: Do not return muted child categories termless hashtag search (#19526)

We generally do not return muted child categories to the user
if they have muted the parent category, this commit respects that
rule for CategoryHashtagDataSource
This commit is contained in:
Martin Brennan 2022-12-20 13:45:03 +10:00 committed by GitHub
parent 94b258deda
commit 1b49a90e5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 6 deletions

View File

@ -74,13 +74,13 @@ class CategoryHashtagDataSource
Category
.includes(:parent_category)
.secured(guardian)
.joins(
"LEFT JOIN category_users ON category_users.user_id = #{guardian.user.id}
AND category_users.category_id = categories.id",
)
.where(
"category_users.notification_level IS NULL OR category_users.notification_level != ?",
CategoryUser.notification_levels[:muted],
"categories.id NOT IN (#{
CategoryUser
.muted_category_ids_query(guardian.user, include_direct: true)
.select("categories.id")
.to_sql
})",
)
.order(topic_count: :desc)
.take(limit)

View File

@ -91,6 +91,15 @@ RSpec.describe CategoryHashtagDataSource do
)
expect(described_class.search_without_term(guardian, 5).map(&:slug)).not_to include("random")
end
it "does not return child categories where the user has muted the parent" do
CategoryUser.create!(
user: user,
category: parent_category,
notification_level: CategoryUser.notification_levels[:muted],
)
expect(described_class.search_without_term(guardian, 5).map(&:slug)).not_to include("random")
end
end
describe "#search_sort" do