From d778d99b5598c8b32e778c3e0752c79b66b10bfb Mon Sep 17 00:00:00 2001 From: tshenry Date: Wed, 4 Nov 2020 16:23:49 -0800 Subject: [PATCH] FIX: limit_topics_per_day should only apply to regular topics (#11127) PMs were being evaluted by both the limit_topics_per_day and limit_private_messages_per_day rate limiters when it should only be the latter. --- app/models/topic.rb | 1 + spec/models/topic_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app/models/topic.rb b/app/models/topic.rb index 4df894e2bc0..9df8b2edad0 100644 --- a/app/models/topic.rb +++ b/app/models/topic.rb @@ -441,6 +441,7 @@ class Topic < ActiveRecord::Base # Additional rate limits on topics: per day and private messages per day def limit_topics_per_day + return unless regular? if user && user.new_user_posting_on_first_day? limit_first_day_topics_per_day else diff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rb index 7ad36476dfb..b9aaa5e386b 100644 --- a/spec/models/topic_spec.rb +++ b/spec/models/topic_spec.rb @@ -2215,6 +2215,29 @@ describe Topic do end end + context "per day personal message limit" do + before do + SiteSetting.max_personal_messages_per_day = 1 + SiteSetting.max_topics_per_day = 0 + SiteSetting.max_topics_in_first_day = 0 + RateLimiter.enable + end + + after do + RateLimiter.clear_all! + RateLimiter.disable + end + + it "limits according to max_personal_messages_per_day" do + user1 = Fabricate(:user) + user2 = Fabricate(:user) + create_post(user: user, archetype: 'private_message', target_usernames: [user1.username, user2.username]) + expect { + create_post(user: user, archetype: 'private_message', target_usernames: [user1.username, user2.username]) + }.to raise_error(RateLimiter::LimitExceeded) + end + end + describe ".count_exceeds_minimun?" do before { SiteSetting.minimum_topics_similar = 20 }