Skip to content

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

FIX: filter out unlisted topics from group mentions endpoint (#37800)

Alan Guo Xiang Tance3e958a2a00
diff --git a/app/models/group.rb b/app/models/group.rb
index c4501680c9f..e720b05636c 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -434,6 +434,7 @@ class Group < ActiveRecord::Base
.includes(:user, :topic, topic: :category)
.references(:posts, :topics, :category)
.where.not(topics: { archetype: Archetype.private_message })
+ .where("topics.visible")
.where(post_type: Post.types[:regular])
.where("group_mentions.group_id = ?", self.id)
diff --git a/spec/requests/groups_controller_spec.rb b/spec/requests/groups_controller_spec.rb
index 9d3bbcff1ad..a5be5a66827 100644
--- a/spec/requests/groups_controller_spec.rb
+++ b/spec/requests/groups_controller_spec.rb
@@ -607,6 +607,21 @@ RSpec.describe GroupsController do
expect(response.status).to eq(200)
expect(response.parsed_body["posts"]).to be_empty
end
+
+ it "excludes posts from unlisted topics" do
+ visible_post = Fabricate(:post)
+ GroupMention.create!(post: visible_post, group: group)
+
+ unlisted_post = Fabricate(:post)
+ unlisted_post.topic.update!(visible: false)
+ GroupMention.create!(post: unlisted_post, group: group)
+
+ sign_in(user)
+ get "/groups/#{group.name}/mentions.json"
+
+ expect(response.status).to eq(200)
+ expect(response.parsed_body["posts"].map { |p| p["id"] }).to contain_exactly(visible_post.id)
+ end
end
describe "#posts" do