[deploy] Only Throttle Confirmation Emails for Existing Users (#7780)
This commit is contained in:
parent
744dea426d
commit
625ff37398
2 changed files with 4 additions and 3 deletions
|
|
@ -611,7 +611,7 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def can_send_confirmation_email
|
def can_send_confirmation_email
|
||||||
return if changes[:email].blank?
|
return if changes[:email].blank? || id.blank?
|
||||||
|
|
||||||
rate_limiter.track_limit_by_action(:send_email_confirmation)
|
rate_limiter.track_limit_by_action(:send_email_confirmation)
|
||||||
rate_limiter.check_limit!(:send_email_confirmation)
|
rate_limiter.check_limit!(:send_email_confirmation)
|
||||||
|
|
|
||||||
|
|
@ -201,11 +201,12 @@ RSpec.describe User, type: :model do
|
||||||
expect(user.errors[:username].to_s).to include("taken")
|
expect(user.errors[:username].to_s).to include("taken")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "validates can_send_confirmation_email" do
|
it "validates can_send_confirmation_email for existing user" do
|
||||||
user = build(:user)
|
user = create(:user)
|
||||||
limiter = RateLimitChecker.new(user)
|
limiter = RateLimitChecker.new(user)
|
||||||
allow(user).to receive(:rate_limiter).and_return(limiter)
|
allow(user).to receive(:rate_limiter).and_return(limiter)
|
||||||
allow(limiter).to receive(:limit_by_action).and_return(true)
|
allow(limiter).to receive(:limit_by_action).and_return(true)
|
||||||
|
user.update(email: "new_email@yo.com")
|
||||||
expect(user).not_to be_valid
|
expect(user).not_to be_valid
|
||||||
expect(user.errors[:email].to_s).to include("confirmation could not be sent. Rate limit reached")
|
expect(user.errors[:email].to_s).to include("confirmation could not be sent. Rate limit reached")
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue