mirror of
https://github.com/codeninjasllc/discourse.git
synced 2025-02-17 04:01:29 -05:00
FIX: don't send emails to mailing_list users when bounce threshold is reached
This commit is contained in:
parent
a382d5d2d2
commit
17890f95a1
2 changed files with 38 additions and 16 deletions
|
@ -36,22 +36,20 @@ module Jobs
|
|||
|
||||
users.each do |user|
|
||||
if Guardian.new(user).can_see?(post)
|
||||
if EmailLog.reached_max_emails?(user)
|
||||
skip(user.email, user.id, post.id, I18n.t('email_log.exceeded_emails_limit'))
|
||||
next
|
||||
end
|
||||
|
||||
if user.user_stat.bounce_score >= SiteSetting.bounce_score_threshold
|
||||
skip(user.email, user.id, post.id, I18n.t('email_log.exceeded_bounces_limit'))
|
||||
next
|
||||
end
|
||||
|
||||
begin
|
||||
if EmailLog.reached_max_emails?(user)
|
||||
EmailLog.create!(
|
||||
email_type: 'mailing_list',
|
||||
to_address: user.email,
|
||||
user_id: user.id,
|
||||
post_id: post.id,
|
||||
skipped: true,
|
||||
skipped_reason: "[MailingList] #{I18n.t('email_log.exceeded_emails_limit')}"
|
||||
)
|
||||
else
|
||||
message = UserNotifications.mailing_list_notify(user, post)
|
||||
if message
|
||||
EmailLog.unique_email_per_post(post, user) do
|
||||
Email::Sender.new(message, :mailing_list, user).send
|
||||
end
|
||||
if message = UserNotifications.mailing_list_notify(user, post)
|
||||
EmailLog.unique_email_per_post(post, user) do
|
||||
Email::Sender.new(message, :mailing_list, user).send
|
||||
end
|
||||
end
|
||||
rescue => e
|
||||
|
@ -61,5 +59,16 @@ module Jobs
|
|||
end
|
||||
|
||||
end
|
||||
|
||||
def skip(to_address, user_id, post_id, reason)
|
||||
EmailLog.create!(
|
||||
email_type: 'mailing_list',
|
||||
to_address: to_address,
|
||||
user_id: user_id,
|
||||
post_id: post_id,
|
||||
skipped: true,
|
||||
skipped_reason: "[MailingList] #{reason}"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,11 +3,13 @@ require "rails_helper"
|
|||
describe Jobs::NotifyMailingListSubscribers do
|
||||
|
||||
context "with mailing list on" do
|
||||
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
before do
|
||||
SiteSetting.default_email_mailing_list_mode = true
|
||||
SiteSetting.default_email_mailing_list_mode_frequency = 1
|
||||
end
|
||||
let(:user) { Fabricate(:user) }
|
||||
|
||||
context "SiteSetting.max_emails_per_day_per_user" do
|
||||
|
||||
|
@ -23,6 +25,17 @@ describe Jobs::NotifyMailingListSubscribers do
|
|||
end
|
||||
end
|
||||
|
||||
context "SiteSetting.bounce_score_threshold" do
|
||||
|
||||
it "stops sending mail once bounce threshold is reached" do
|
||||
user.user_stat.update_columns(bounce_score: SiteSetting.bounce_score_threshold + 1)
|
||||
post = Fabricate(:post)
|
||||
Jobs::NotifyMailingListSubscribers.new.execute(post_id: post.id)
|
||||
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
context "totally skipped if mailing list mode disabled" do
|
||||
|
||||
it "sends no email to the user" do
|
||||
|
|
Loading…
Reference in a new issue