FIX: don't apply max_emails_per_day_per_user on critical emails
This commit is contained in:
parent
a470bce8fb
commit
86f1cc8c92
|
@ -56,17 +56,6 @@ module Jobs
|
|||
quoted
|
||||
}
|
||||
|
||||
CRITICAL_EMAIL_TYPES ||= Set.new %w{
|
||||
account_created
|
||||
admin_login
|
||||
confirm_new_email
|
||||
confirm_old_email
|
||||
forgot_password
|
||||
notify_old_email
|
||||
signup
|
||||
signup_after_approval
|
||||
}
|
||||
|
||||
def message_for_email(user, post, type, notification, notification_type=nil, notification_data_hash=nil, email_token=nil, to_address=nil)
|
||||
set_skip_context(type, user.id, to_address || user.email, post.try(:id))
|
||||
|
||||
|
@ -125,7 +114,7 @@ module Jobs
|
|||
return skip_message(I18n.t('email_log.exceeded_emails_limit'))
|
||||
end
|
||||
|
||||
if !CRITICAL_EMAIL_TYPES.include?(type.to_s) && user.user_stat.bounce_score >= SiteSetting.bounce_score_threshold
|
||||
if !EmailLog::CRITICAL_EMAIL_TYPES.include?(type.to_s) && user.user_stat.bounce_score >= SiteSetting.bounce_score_threshold
|
||||
return skip_message(I18n.t('email_log.exceeded_bounces_limit'))
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,17 @@
|
|||
require_dependency 'distributed_mutex'
|
||||
|
||||
class EmailLog < ActiveRecord::Base
|
||||
CRITICAL_EMAIL_TYPES ||= Set.new %w{
|
||||
account_created
|
||||
admin_login
|
||||
confirm_new_email
|
||||
confirm_old_email
|
||||
forgot_password
|
||||
notify_old_email
|
||||
signup
|
||||
signup_after_approval
|
||||
}
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :post
|
||||
belongs_to :topic
|
||||
|
@ -29,7 +40,7 @@ class EmailLog < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def self.reached_max_emails?(user, email_type=nil)
|
||||
return false if SiteSetting.max_emails_per_day_per_user == 0 || email_type == 'forgot_password'
|
||||
return false if SiteSetting.max_emails_per_day_per_user == 0 || CRITICAL_EMAIL_TYPES.include?(email_type)
|
||||
|
||||
count = sent.where('created_at > ?', 1.day.ago)
|
||||
.where(user_id: user.id)
|
||||
|
|
|
@ -234,7 +234,7 @@ describe Jobs::UserEmail do
|
|||
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
|
||||
end
|
||||
|
||||
it "sends forgot password email" do
|
||||
it "sends critical 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
|
||||
|
|
|
@ -67,9 +67,10 @@ describe EmailLog do
|
|||
expect(EmailLog.reached_max_emails?(user)).to eq(true)
|
||||
end
|
||||
|
||||
it "returns false for forgot_password email" do
|
||||
it "returns false for critical 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)
|
||||
expect(EmailLog.reached_max_emails?(user, 'confirm_new_email')).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue