A platform for community discussion. Free, open, simple.
FIX: Can't dismiss unread posts in topics of a sub-subcategory (#22870)
Alan Guo Xiang Tanfff578f5fb39
diff --git a/app/controllers/topics_controller.rb b/app/controllers/topics_controller.rbindex 48d388d7047..5b662283a5f 100644--- a/app/controllers/topics_controller.rb+++ b/app/controllers/topics_controller.rb@@ -1396,17 +1396,18 @@ class TopicsController < ApplicationControllertopic_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)endif params[:tag_name].present?diff --git a/spec/requests/topics_controller_spec.rb b/spec/requests/topics_controller_spec.rbindex 79e6c8dfc41..9b19ce1243e 100644--- a/spec/requests/topics_controller_spec.rb+++ b/spec/requests/topics_controller_spec.rb@@ -3516,7 +3516,7 @@ RSpec.describe TopicsController doexpect(response.status).to eq(400)end- it "can mark sub-categories unread" do+ it "can dismiss sub-categories posts as read" dosub = Fabricate(:category, parent_category_id: category.id)topic.update!(category_id: sub.id)@@ -3538,6 +3538,31 @@ RSpec.describe TopicsController doexpect(TopicUser.get(post1.topic, post1.user).last_read_post_number).to eq(2)end+ it "can dismiss sub-subcategories posts as read" do+ SiteSetting.max_category_nesting = 3++ sub_category = Fabricate(:category, parent_category_id: category.id)+ sub_subcategory = Fabricate(:category, parent_category_id: sub_category.id)++ topic.update!(category_id: sub_subcategory.id)++ post_1 = create_post(user: user, topic_id: topic.id)+ post_2 = create_post(topic_id: topic.id)++ put "/topics/bulk.json",+ params: {+ category_id: category.id,+ include_subcategories: true,+ filter: "unread",+ operation: {+ type: "dismiss_posts",+ },+ }++ expect(response.status).to eq(200)+ expect(TopicUser.get(post_1.topic, post_1.user).last_read_post_number).to eq(2)+ end+it "can mark tag topics unread" doTopicTag.create!(topic_id: topic.id, tag_id: tag.id)