Commit bbfaed449e98a525ffc3764b42caaf0a2273462f
1 parent
33478426
Exists in
master
and in
27 other branches
Organization: mail the environment with no contacts
When an organization (community or enterprise) has no admins and no recorded contact email, redirect any mails sent to that org to the environment contact email.
Showing
2 changed files
with
7 additions
and
3 deletions
Show diff stats
app/models/organization.rb
@@ -135,7 +135,11 @@ class Organization < Profile | @@ -135,7 +135,11 @@ class Organization < Profile | ||
135 | end | 135 | end |
136 | 136 | ||
137 | def notification_emails | 137 | def notification_emails |
138 | - [contact_email.blank? ? nil : contact_email].compact + admins.map(&:email) | 138 | + emails = [contact_email].select(&:present?) + admins.map(&:email) |
139 | + if emails.empty? | ||
140 | + emails << environment.contact_email | ||
141 | + end | ||
142 | + emails | ||
139 | end | 143 | end |
140 | 144 | ||
141 | def already_request_membership?(person) | 145 | def already_request_membership?(person) |
test/unit/organization_test.rb
@@ -123,9 +123,9 @@ class OrganizationTest < ActiveSupport::TestCase | @@ -123,9 +123,9 @@ class OrganizationTest < ActiveSupport::TestCase | ||
123 | assert_equal ['admin1@email.com', 'admin2@email.com'], o.notification_emails | 123 | assert_equal ['admin1@email.com', 'admin2@email.com'], o.notification_emails |
124 | end | 124 | end |
125 | 125 | ||
126 | - should 'return empty array if contact_email is a blank string and it has no admin' do | 126 | + should 'use the environment contact email if no emails are listed here' do |
127 | o = build(Organization, :contact_email => '', :environment => Environment.default) | 127 | o = build(Organization, :contact_email => '', :environment => Environment.default) |
128 | - assert_equal [], o.notification_emails | 128 | + assert_equal [o.environment.contact_email], o.notification_emails |
129 | end | 129 | end |
130 | 130 | ||
131 | should 'list pending enterprise validations' do | 131 | should 'list pending enterprise validations' do |