FIX: don't apply max emails per day per user to forgot password
This commit is contained in:
parent
f5f4c36795
commit
cdce060a38
|
@ -121,7 +121,7 @@ module Jobs
|
|||
email_args[:email_token] = email_token if email_token.present?
|
||||
email_args[:new_email] = user.email if type.to_s == "notify_old_email"
|
||||
|
||||
if EmailLog.reached_max_emails?(user)
|
||||
if EmailLog.reached_max_emails?(user, type.to_s)
|
||||
return skip_message(I18n.t('email_log.exceeded_emails_limit'))
|
||||
end
|
||||
|
||||
|
|
|
@ -28,12 +28,12 @@ class EmailLog < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def self.reached_max_emails?(user)
|
||||
return false if SiteSetting.max_emails_per_day_per_user == 0
|
||||
def self.reached_max_emails?(user, email_type=nil)
|
||||
return false if SiteSetting.max_emails_per_day_per_user == 0 || email_type == 'forgot_password'
|
||||
|
||||
count = sent.where('created_at > ?', 1.day.ago)
|
||||
.where(user_id: user.id)
|
||||
.count
|
||||
.where(user_id: user.id)
|
||||
.count
|
||||
|
||||
count >= SiteSetting.max_emails_per_day_per_user
|
||||
end
|
||||
|
|
|
@ -222,15 +222,22 @@ describe Jobs::UserEmail do
|
|||
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id)
|
||||
end
|
||||
|
||||
it "does not send notification if limit is reached" do
|
||||
SiteSetting.max_emails_per_day_per_user = 2
|
||||
context 'max_emails_per_day_per_user limit is reached' do
|
||||
before do
|
||||
SiteSetting.max_emails_per_day_per_user = 2
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
end
|
||||
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
it "does not send notification if limit is reached" do
|
||||
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
||||
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
|
||||
end
|
||||
|
||||
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
||||
|
||||
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
|
||||
it "sends forgot password email" do
|
||||
Jobs::UserEmail.new.execute(type: :forgot_password, user_id: user.id, notification_id: notification.id, post_id: post.id)
|
||||
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(0)
|
||||
end
|
||||
end
|
||||
|
||||
it "does not send notification if bounce threshold is reached" do
|
||||
|
|
|
@ -53,18 +53,24 @@ describe EmailLog do
|
|||
end
|
||||
|
||||
describe '#reached_max_emails?' do
|
||||
it "tracks when max emails are reached" do
|
||||
before do
|
||||
SiteSetting.max_emails_per_day_per_user = 2
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id, skipped: true)
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id, created_at: 3.days.ago)
|
||||
end
|
||||
|
||||
it "tracks when max emails are reached" do
|
||||
expect(EmailLog.reached_max_emails?(user)).to eq(false)
|
||||
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
|
||||
expect(EmailLog.reached_max_emails?(user)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false for forgot_password email" do
|
||||
user.email_logs.create(email_type: 'blah', to_address: user.email, user_id: user.id)
|
||||
expect(EmailLog.reached_max_emails?(user, 'forgot_password')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe '#count_per_day' do
|
||||
|
|
Loading…
Reference in New Issue