From 949f3c30f232a090387eecd53970b87c7fc62648 Mon Sep 17 00:00:00 2001 From: Eduardo Navarro Date: Fri, 27 Mar 2020 15:23:31 +0100 Subject: [PATCH] Don't send emails to groups without an email The corner case of sending a mail to only a group, that hasn't an email defined, was not taken into account. This patch makes the code not to send an email in this case. Fixes #9114. Co-authored-by: David Kang --- src/api/app/mailers/event_mailer.rb | 6 ++++-- src/api/spec/mailers/event_mailer_spec.rb | 11 +++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/api/app/mailers/event_mailer.rb b/src/api/app/mailers/event_mailer.rb index 7ca320594bf..15b9be51cea 100644 --- a/src/api/app/mailers/event_mailer.rb +++ b/src/api/app/mailers/event_mailer.rb @@ -21,6 +21,9 @@ def event(subscribers, e) subscribers = subscribers.to_a return if subscribers.empty? + recipients = subscribers.map(&:display_name).reject(&:blank?) + return if recipients.empty? + set_headers begin locals = { event: e.expanded_payload } @@ -33,7 +36,6 @@ def event(subscribers, e) template_name = e.template_name orig = e.originator - tos = subscribers.map(&:display_name) if orig orig = orig.display_name @@ -41,7 +43,7 @@ def event(subscribers, e) orig = mail_sender end - mail(to: tos.sort, + mail(to: recipients.sort, subject: e.subject, from: orig, date: e.created_at) do |format| diff --git a/src/api/spec/mailers/event_mailer_spec.rb b/src/api/spec/mailers/event_mailer_spec.rb index b04bfa438e0..4b0fc8df130 100644 --- a/src/api/spec/mailers/event_mailer_spec.rb +++ b/src/api/spec/mailers/event_mailer_spec.rb @@ -114,5 +114,16 @@ it { expect(mail.html_part.to_s).to include("I =E2=9D=A4=EF=B8=8F