From 63fabdb6f2ccc9cd6df9931d5272c42111594703 Mon Sep 17 00:00:00 2001 From: Justin DiRose Date: Wed, 2 Oct 2019 14:51:40 -0500 Subject: [PATCH] FIX: first post true if user creates topic first (#8139) Reported here: https://meta.discourse.org/t/user-was-banned-for-posting-a-reply-within-3-seconds/128823/12 The problem here is the user could create a topic, then reply and get silenced on the second time (though technically their first post) for being below the min_first_post_typing_time threshold. --- lib/new_post_manager.rb | 3 ++- spec/requests/posts_controller_spec.rb | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index c047b78495a..aee243b04be 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -40,7 +40,8 @@ class NewPostManager !!( args[:first_post_checks] && - user.post_count == 0 + user.post_count == 0 && + user.topic_count == 0 ) end diff --git a/spec/requests/posts_controller_spec.rb b/spec/requests/posts_controller_spec.rb index 7e10e1a4ae0..a7e8c7d1a18 100644 --- a/spec/requests/posts_controller_spec.rb +++ b/spec/requests/posts_controller_spec.rb @@ -859,6 +859,23 @@ describe PostsController do expect(user).not_to be_silenced end + it "doesn't enqueue posts when user first creates a topic" do + user.user_stat.update_column(:topic_count, 1) + + post "/posts.json", params: { + raw: 'this is the test content', + title: 'this is the test title for the topic', + composer_open_duration_msecs: 204, + typing_duration_msecs: 100, + topic_id: topic.id + } + + expect(response.status).to eq(200) + parsed = ::JSON.parse(response.body) + + expect(parsed["action"]).not_to be_present + end + it "doesn't enqueue replies when the topic is closed" do topic = Fabricate(:closed_topic)