Skip to content

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

FIX: Embedded comments should only return regular posts (#11773)

Robin Ward53ab3dda5d5e
diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb
index 2a05f7d8238..fd4702ba3a7 100644
--- a/app/controllers/embed_controller.rb
+++ b/app/controllers/embed_controller.rb
@@ -74,6 +74,7 @@ class EmbedController < ApplicationController
@topic_view = TopicView.new(topic_id,
current_user,
limit: SiteSetting.embed_post_limit,
+ only_regular: true,
exclude_first: true,
exclude_deleted_users: true,
exclude_hidden: true)
diff --git a/lib/topic_view.rb b/lib/topic_view.rb
index 4a3549e0a23..a646aede74a 100644
--- a/lib/topic_view.rb
+++ b/lib/topic_view.rb
@@ -686,8 +686,9 @@ class TopicView
end
def filter_post_types(posts)
- visible_types = Topic.visible_post_types(@user)
+ return posts.where(post_type: Post.types[:regular]) if @only_regular
+ visible_types = Topic.visible_post_types(@user)
if @user.present?
posts.where("posts.user_id = ? OR post_type IN (?)", @user.id, visible_types)
else
diff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rb
index 489bcdc8654..d772becfd8e 100644
--- a/spec/components/topic_view_spec.rb
+++ b/spec/components/topic_view_spec.rb
@@ -36,6 +36,25 @@ describe TopicView do
expect { TopicView.new(topic.id, admin) }.not_to raise_error
end
+ context "filter options" do
+ fab!(:p0) { Fabricate(:post, topic: topic) }
+ fab!(:p1) { Fabricate(:post, topic: topic, post_type: Post.types[:moderator_action]) }
+ fab!(:p2) { Fabricate(:post, topic: topic, post_type: Post.types[:small_action]) }
+
+ it "omits moderator actions and small posts when only_regular is set" do
+ tv = TopicView.new(topic.id, nil)
+ expect(tv.filtered_post_ids).to eq([p0.id, p1.id, p2.id])
+
+ tv = TopicView.new(topic.id, nil, only_regular: true)
+ expect(tv.filtered_post_ids).to eq([p0.id])
+ end
+
+ it "omits the first post when exclude_first is set" do
+ tv = TopicView.new(topic.id, nil, exclude_first: true)
+ expect(tv.filtered_post_ids).to eq([p0.id, p1.id, p2.id])
+ end
+ end
+
context "setup_filtered_posts" do
describe "filters posts with ignored users" do
fab!(:ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: user) }