From de2febcc0c6f2d01e7d0128c51f962c0c4940ec4 Mon Sep 17 00:00:00 2001 From: Krzysztof Kotlarek Date: Thu, 29 Jun 2023 11:25:58 +1000 Subject: [PATCH] FIX: error when CategoryList tried to find relevant topics (#22339) Recently, we added the option for watched tag/categories to take precedence over muted tag/categories. Therefore, `remove_muted_tags` is using `category_users` to check if categories are not watched. There was missing join in CategoryList which was causing an error. --- app/models/category_list.rb | 17 +++++++++++------ spec/models/category_list_spec.rb | 7 +++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/models/category_list.rb b/app/models/category_list.rb index e2c12a10065..8eee48792e2 100644 --- a/app/models/category_list.rb +++ b/app/models/category_list.rb @@ -86,12 +86,17 @@ class CategoryList if @guardian.authenticated? @all_topics = - @all_topics.joins( - "LEFT JOIN topic_users tu ON topics.id = tu.topic_id AND tu.user_id = #{@guardian.user.id.to_i}", - ).where( - "COALESCE(tu.notification_level,1) > :muted", - muted: TopicUser.notification_levels[:muted], - ) + @all_topics + .joins( + "LEFT JOIN topic_users tu ON topics.id = tu.topic_id AND tu.user_id = #{@guardian.user.id.to_i}", + ) + .joins( + "LEFT JOIN category_users ON category_users.category_id = topics.category_id AND category_users.user_id = #{@guardian.user.id}", + ) + .where( + "COALESCE(tu.notification_level,1) > :muted", + muted: TopicUser.notification_levels[:muted], + ) end @all_topics = TopicQuery.remove_muted_tags(@all_topics, @guardian.user).includes(:last_poster) diff --git a/spec/models/category_list_spec.rb b/spec/models/category_list_spec.rb index cd68bcc4dc4..bb341cc2f58 100644 --- a/spec/models/category_list_spec.rb +++ b/spec/models/category_list_spec.rb @@ -43,6 +43,13 @@ RSpec.describe CategoryList do SiteSetting.default_tags_muted = muted_tag.name Fabricate(:topic, category: public_cat, tags: [muted_tag]) + muted_tag_2 = Fabricate(:tag) + TagUser.create!( + tag: muted_tag_2, + user: user, + notification_level: TagUser.notification_levels[:muted], + ) + CategoryFeaturedTopic.feature_topics expect(