FIX: Can't dismiss unread posts in topics of a sub-subcategory (#22870)

This is a similar fix to 32d4810e2b

Why this change?

Prior to this change, there is a bug in `TopicsController#bulk`
where it does not dismiss new unred posts in sub-subcategories when the
`category_id` and `include_subcategories=true` params are present. This
is because the controller did not account for sub-subcategories when
fetching the category ids of the new topics that should be dismissed.

This commit fixes the problem by relying on the `Category.subcategory_ids` class
method which accounts for sub-subcategories.
This commit is contained in:
Alan Guo Xiang Tan
2023-07-31 11:22:16 +08:00
committed by GitHub
parent c4d0bbce62
commit fff578f5fb
2 changed files with 35 additions and 9 deletions

View File

@@ -1396,17 +1396,18 @@ class TopicsController < ApplicationController
topic_query.joined_topic_user,
whisperer: guardian.is_whisperer?,
).listable_topics
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
if params[:category_id]
if params[:include_subcategories]
topics = topics.where(<<~SQL, category_id: params[:category_id])
category_id in (select id FROM categories WHERE parent_category_id = :category_id) OR
category_id = :category_id
SQL
else
topics = topics.where("category_id = ?", params[:category_id])
end
category_ids =
if params[:include_subcategories]
Category.subcategory_ids(params[:category_id].to_i)
else
params[:category_id]
end
topics = topics.where(category_id: category_ids)
end
if params[:tag_name].present?