Merge pull request #4365 from gdpelican/fix/daily-mlm-notifications

Don't halt notification emails for those on daily mailing list mode
This commit is contained in:
Robin Ward 2016-08-08 14:30:56 -04:00 committed by GitHub
commit 8b252f19d7
2 changed files with 10 additions and 2 deletions

View file

@ -103,6 +103,7 @@ module Jobs
end end
if user.user_option.mailing_list_mode? && if user.user_option.mailing_list_mode? &&
user.user_option.mailing_list_mode_frequency == 1 && # don't catch notifications for users on daily mailing list mode
(!post.try(:topic).try(:private_message?)) && (!post.try(:topic).try(:private_message?)) &&
NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type]) NOTIFICATIONS_SENT_BY_MAILING_LIST.include?(email_args[:notification_type])
# no need to log a reason when the mail was already sent via the mailing list job # no need to log a reason when the mail was already sent via the mailing list job

View file

@ -201,6 +201,13 @@ describe Jobs::UserEmail do
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id) Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id)
end end
it "does send the email if the user is using daily mailing list mode" do
Email::Sender.any_instance.expects(:send)
user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 0)
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 it "does not send notification if limit is reached" do
SiteSetting.max_emails_per_day_per_user = 2 SiteSetting.max_emails_per_day_per_user = 2
@ -218,9 +225,9 @@ describe Jobs::UserEmail do
expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1) expect(EmailLog.where(user_id: user.id, skipped: true).count).to eq(1)
end end
it "doesn't send the mail if the user is using mailing list mode" do it "doesn't send the mail if the user is using individual mailing list mode" do
Email::Sender.any_instance.expects(:send).never Email::Sender.any_instance.expects(:send).never
user.user_option.update_column(:mailing_list_mode, true) user.user_option.update(mailing_list_mode: true, mailing_list_mode_frequency: 1)
# sometimes, we pass the notification_id # sometimes, we pass the notification_id
Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id) Jobs::UserEmail.new.execute(type: :user_mentioned, user_id: user.id, notification_id: notification.id, post_id: post.id)
# other times, we only pass the type of notification # other times, we only pass the type of notification