mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
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:
committed by
GitHub
parent
c4d0bbce62
commit
fff578f5fb
@@ -1396,17 +1396,18 @@ class TopicsController < ApplicationController
|
|||||||
topic_query.joined_topic_user,
|
topic_query.joined_topic_user,
|
||||||
whisperer: guardian.is_whisperer?,
|
whisperer: guardian.is_whisperer?,
|
||||||
).listable_topics
|
).listable_topics
|
||||||
|
|
||||||
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
|
topics = TopicQuery.tracked_filter(topics, current_user.id) if params[:tracked].to_s == "true"
|
||||||
|
|
||||||
if params[:category_id]
|
if params[:category_id]
|
||||||
if params[:include_subcategories]
|
category_ids =
|
||||||
topics = topics.where(<<~SQL, category_id: params[:category_id])
|
if params[:include_subcategories]
|
||||||
category_id in (select id FROM categories WHERE parent_category_id = :category_id) OR
|
Category.subcategory_ids(params[:category_id].to_i)
|
||||||
category_id = :category_id
|
else
|
||||||
SQL
|
params[:category_id]
|
||||||
else
|
end
|
||||||
topics = topics.where("category_id = ?", params[:category_id])
|
|
||||||
end
|
topics = topics.where(category_id: category_ids)
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:tag_name].present?
|
if params[:tag_name].present?
|
||||||
|
|||||||
@@ -3516,7 +3516,7 @@ RSpec.describe TopicsController do
|
|||||||
expect(response.status).to eq(400)
|
expect(response.status).to eq(400)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can mark sub-categories unread" do
|
it "can dismiss sub-categories posts as read" do
|
||||||
sub = Fabricate(:category, parent_category_id: category.id)
|
sub = Fabricate(:category, parent_category_id: category.id)
|
||||||
|
|
||||||
topic.update!(category_id: sub.id)
|
topic.update!(category_id: sub.id)
|
||||||
@@ -3538,6 +3538,31 @@ RSpec.describe TopicsController do
|
|||||||
expect(TopicUser.get(post1.topic, post1.user).last_read_post_number).to eq(2)
|
expect(TopicUser.get(post1.topic, post1.user).last_read_post_number).to eq(2)
|
||||||
end
|
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" do
|
it "can mark tag topics unread" do
|
||||||
TopicTag.create!(topic_id: topic.id, tag_id: tag.id)
|
TopicTag.create!(topic_id: topic.id, tag_id: tag.id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user