TopicView/PostSerializer should be able to handle topics without categories

This commit is contained in:
jbrw 2020-07-28 19:06:55 -04:00
parent 150e83d2a6
commit 8f140b8903
No known key found for this signature in database
GPG Key ID: FAFF7D94CE3F957B
2 changed files with 21 additions and 1 deletions

View File

@ -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')

View File

@ -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