Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Embedded comments should only return regular posts #11773

Merged
merged 1 commit into from Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions app/controllers/embed_controller.rb
Expand Up @@ -74,6 +74,7 @@ def comments
@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)
Expand Down
3 changes: 2 additions & 1 deletion lib/topic_view.rb
Expand Up @@ -686,8 +686,9 @@ def get_sort_order(post_number)
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
Expand Down
19 changes: 19 additions & 0 deletions spec/components/topic_view_spec.rb
Expand Up @@ -36,6 +36,25 @@
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there was no test for this filter either so I added it in here.

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) }
Expand Down