FIX: Can't dismiss new topics that belong to a sub-sub category (#22849)

What is the context for this change?

Prior to this change, there is a bug in `TopicsController#reset_new`
where it does not dismiss new topics 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-28 12:06:42 +08:00
committed by GitHub
parent 26fc5d2d1f
commit 32d4810e2b
2 changed files with 42 additions and 11 deletions

View File

@@ -1062,13 +1062,17 @@ class TopicsController < ApplicationController
if tag_name = params[:tag_id]
tag_name = DiscourseTagging.visible_tags(guardian).where(name: tag_name).pluck(:name).first
end
topic_scope =
if params[:category_id].present?
category_ids = [params[:category_id].to_i]
if ActiveModel::Type::Boolean.new.cast(params[:include_subcategories])
category_ids =
category_ids.concat(Category.where(parent_category_id: params[:category_id]).pluck(:id))
end
category_id = params[:category_id].to_i
category_ids =
if ActiveModel::Type::Boolean.new.cast(params[:include_subcategories])
Category.subcategory_ids(category_id)
else
[category_id]
end
category_ids &= guardian.allowed_category_ids
if category_ids.blank?