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:
parent
94b258deda
commit
1b49a90e5b
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue