Commit bbfaed449e98a525ffc3764b42caaf0a2273462f

Authored by Antonio Terceiro
1 parent 33478426

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.
app/models/organization.rb
... ... @@ -135,7 +135,11 @@ class Organization < Profile
135 135 end
136 136  
137 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 143 end
140 144  
141 145 def already_request_membership?(person)
... ...
test/unit/organization_test.rb
... ... @@ -123,9 +123,9 @@ class OrganizationTest &lt; ActiveSupport::TestCase
123 123 assert_equal ['admin1@email.com', 'admin2@email.com'], o.notification_emails
124 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 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 129 end
130 130  
131 131 should 'list pending enterprise validations' do
... ...