From add3d46bc0ba29b7ced2cda9c540eb9c2e90d96d Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Wed, 9 Sep 2020 12:47:37 -0400 Subject: [PATCH] FIX: `approve post count` did not take new topics into account This means if a user created a new topic, and it was approved, it would not count towards their approval count. Replies worked correctly. --- lib/new_post_manager.rb | 2 +- spec/components/new_post_manager_spec.rb | 26 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/new_post_manager.rb b/lib/new_post_manager.rb index 081e6e524f0..3f2f63eefb4 100644 --- a/lib/new_post_manager.rb +++ b/lib/new_post_manager.rb @@ -88,7 +88,7 @@ class NewPostManager return :post_count if ( user.trust_level <= TrustLevel.levels[:basic] && - user.post_count < SiteSetting.approve_post_count + (user.post_count + user.topic_count) < SiteSetting.approve_post_count ) return :trust_level if user.trust_level < SiteSetting.approve_unless_trust_level.to_i diff --git a/spec/components/new_post_manager_spec.rb b/spec/components/new_post_manager_spec.rb index e8f6fa16342..65cbe56cf30 100644 --- a/spec/components/new_post_manager_spec.rb +++ b/spec/components/new_post_manager_spec.rb @@ -71,6 +71,32 @@ describe NewPostManager do end end + context 'basic post/topic count restrictions' do + before do + SiteSetting.approve_post_count = 1 + end + + it "works with a correct `user_stat.post_count`" do + result = NewPostManager.default_handler(manager) + expect(result.action).to eq(:enqueued) + expect(result.reason).to eq(:post_count) + + manager.user.user_stat.update(post_count: 1) + result = NewPostManager.default_handler(manager) + expect(result).to eq(nil) + end + + it "works with a correct `user_stat.topic_count`" do + result = NewPostManager.default_handler(manager) + expect(result.action).to eq(:enqueued) + expect(result.reason).to eq(:post_count) + + manager.user.user_stat.update(topic_count: 1) + result = NewPostManager.default_handler(manager) + expect(result).to eq(nil) + end + end + context 'with a high approval post count and TL0' do before do SiteSetting.approve_post_count = 100