Skip to content

A platform for community discussion. Free, open, simple.

TopicView/PostSerializer should be able to handle topics without categories

jbrw8f140b890384
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index 14db18126ab..b2f37ccf616 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -431,7 +431,7 @@ class TopicView
def category_group_moderator_user_ids
@category_group_moderator_user_ids ||= begin
- if SiteSetting.enable_category_group_moderation? && @topic.category&.reviewable_by_group&.present?
+ if SiteSetting.enable_category_group_moderation? && @topic.category&.reviewable_by_group.present?
posts_user_ids = Set.new(@posts.map(&:user_id))
Set.new(
@topic.category.reviewable_by_group.group_users.where(user_id: posts_user_ids).pluck('distinct user_id')
diff --git a/spec/serializers/topic_view_serializer_spec.rb b/spec/serializers/topic_view_serializer_spec.rb
index 2599c0816c6..3262da29b5f 100644
--- a/spec/serializers/topic_view_serializer_spec.rb
+++ b/spec/serializers/topic_view_serializer_spec.rb
@@ -379,4 +379,24 @@ describe TopicViewSerializer do
end
end
+ context "viewing private messages when enable_category_group_moderation is enabled" do
+ fab!(:pm_topic) do
+ Fabricate(:private_message_topic, topic_allowed_users: [
+ Fabricate.build(:topic_allowed_user, user: user),
+ Fabricate.build(:topic_allowed_user, user: admin)
+ ])
+ end
+ fab!(:post) { Fabricate(:post, topic: pm_topic) }
+
+ before do
+ SiteSetting.enable_category_group_moderation = true
+ end
+
+ # Ensure having enable_category_group_moderation turned on doesn't break private messages
+ it "should return posts" do
+ json = serialize_topic(pm_topic, user)
+ expect(json[:post_stream][:posts]).to be_present
+ end
+ end
+
end