aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2013-11-04 19:04:17 +0000
committerStruan Donald <struan@exo.org.uk>2013-11-04 19:04:17 +0000
commitf8166c2ed6879b46c1e00a18154989da757e2d1e (patch)
treeba2d4531b6500ec89b1a930be17c412889d7e131
parent08b33bdbd4a0dc29941cb5d714f1ea70f0142fde (diff)
parentde74765ac39f677b2eeef1a6d8fcc7fad170f251 (diff)
Merge branch 'multiple_emails_per_contact'
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm16
-rw-r--r--t/app/model/problem.t46
2 files changed, 59 insertions, 3 deletions
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 9006e2f11..21f8f7ca0 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -33,14 +33,24 @@ sub build_recipient_list {
$self->unconfirmed_notes->{$body_email}{$row->category} = $note;
}
+ my $body_name = $body->name;
# see something uses council areas but doesn't send to councils so just use a
# generic name here to minimise confusion
if ( $row->cobrand eq 'seesomething' ) {
- push @{ $self->to }, [ $body_email, 'See Something, Say Something' ];
+ $body_name = 'See Something, Say Something';
+ }
+
+ my @emails;
+ # allow multiple emails per contact
+ if ( $body_email =~ /,/ ) {
+ @emails = split(/,/, $body_email);
} else {
- push @{ $self->to }, [ $body_email, $body->name ];
+ @emails = ( $body_email );
+ }
+ for my $email ( @emails ) {
+ push @{ $self->to }, [ $email, $body_name ];
+ $recips{$email} = 1;
}
- $recips{$body_email} = 1;
}
return () unless $all_confirmed;
diff --git a/t/app/model/problem.t b/t/app/model/problem.t
index 18c210f6f..7303eedac 100644
--- a/t/app/model/problem.t
+++ b/t/app/model/problem.t
@@ -589,6 +589,52 @@ foreach my $test ( {
};
}
+subtest 'check can set mutiple emails as a single contact' => sub {
+ my $override = {
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ BASE_URL => 'http://www.fixmystreet.com',
+ MAPIT_URL => 'http://mapit.mysociety.org/',
+ };
+
+ my $contact = {
+ body_id => 2651, # Edinburgh
+ category => 'trees',
+ email => '2636@example.com,2636-2@example.com',
+ };
+ my $new_contact = FixMyStreet::App->model('DB::Contact')->find_or_create( {
+ %contact_params,
+ %$contact } );
+ ok $new_contact, "created multiple email test contact";
+
+ $mech->clear_emails_ok;
+
+ FixMyStreet::App->model('DB::Problem')->search(
+ {
+ whensent => undef
+ }
+ )->update( { whensent => \'ms_current_timestamp()' } );
+
+ $problem->discard_changes;
+ $problem->update( {
+ bodies_str => $contact->{ body_id },
+ state => 'confirmed',
+ confirmed => \'ms_current_timestamp()',
+ whensent => undef,
+ category => 'trees',
+ name => 'Test User',
+ cobrand => 'fixmystreet',
+ send_fail_count => 0,
+ } );
+
+ FixMyStreet::override_config $override, sub {
+ FixMyStreet::App->model('DB::Problem')->send_reports();
+ };
+
+ $mech->email_count_is(1);
+ my $email = $mech->get_email;
+ is $email->header('To'), '"City of Edinburgh Council" <2636@example.com>, "City of Edinburgh Council" <2636-2@example.com>', 'To contains two email addresses';
+};
+
subtest 'check can turn on report sent email alerts' => sub {
my $send_confirmation_mail_override = Sub::Override->new(
"FixMyStreet::Cobrand::Default::report_sent_confirmation_email",