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.rbindex 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.rbindex 4a3549e0a23..a646aede74a 100644--- a/lib/topic_view.rb+++ b/lib/topic_view.rb@@ -686,8 +686,9 @@ class TopicViewenddef 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)elsediff --git a/spec/components/topic_view_spec.rb b/spec/components/topic_view_spec.rbindex 489bcdc8654..d772becfd8e 100644--- a/spec/components/topic_view_spec.rb+++ b/spec/components/topic_view_spec.rb@@ -36,6 +36,25 @@ describe TopicView doexpect { TopicView.new(topic.id, admin) }.not_to raise_errorend+ 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" dodescribe "filters posts with ignored users" dofab!(:ignored_user) { Fabricate(:ignored_user, user: evil_trout, ignored_user: user) }