FIX: `max topic invitations per day` should apply on PM invites as well

FIX: do not apply `max topic invitations per day` on email invites
This commit is contained in:
Arpit Jalan 2018-03-12 23:16:32 +05:30
parent d243b82fb3
commit 82143a421c
2 changed files with 18 additions and 5 deletions

View File

@ -804,6 +804,7 @@ SQL
end
if target_user && private_message? && topic_allowed_users.create!(user_id: target_user.id)
rate_limit_topic_invitation(invited_by)
add_small_action(invited_by, "invited_user", target_user.username)
create_invite_notification!(
@ -814,9 +815,9 @@ SQL
true
elsif username_or_email =~ /^.+@.+$/ && guardian.can_invite_via_email?(self)
rate_limit_topic_invitation(invited_by)
if target_user
rate_limit_topic_invitation(invited_by)
Invite.extend_permissions(self, target_user, invited_by)
create_invite_notification!(

View File

@ -471,7 +471,7 @@ describe Topic do
context 'rate limits' do
before do
SiteSetting.max_topic_invitations_per_day = 2
SiteSetting.max_topic_invitations_per_day = 1
RateLimiter.enable
end
@ -481,7 +481,6 @@ describe Topic do
end
it "rate limits topic invitations" do
start = Time.now.tomorrow.beginning_of_day
freeze_time(start)
@ -489,10 +488,23 @@ describe Topic do
topic = Fabricate(:topic, user: trust_level_2)
topic.invite(topic.user, user.username)
topic.invite(topic.user, "walter@white.com")
expect {
topic.invite(topic.user, "user@example.com")
topic.invite(topic.user, another_user.username)
}.to raise_error(RateLimiter::LimitExceeded)
end
it "rate limits PM invitations" do
start = Time.now.tomorrow.beginning_of_day
freeze_time(start)
trust_level_2 = Fabricate(:user, trust_level: 2)
topic = Fabricate(:private_message_topic, user: trust_level_2)
topic.invite(topic.user, user.username)
expect {
topic.invite(topic.user, another_user.username)
}.to raise_error(RateLimiter::LimitExceeded)
end
end