diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/Update.pm | 2 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/TfL.pm | 19 | ||||
-rw-r--r-- | t/cobrand/tfl.t | 11 | ||||
-rw-r--r-- | templates/email/default/alert-update.html | 2 | ||||
-rw-r--r-- | templates/email/default/alert-update.txt | 2 |
6 files changed, 41 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/Update.pm b/perllib/FixMyStreet/App/Controller/Report/Update.pm index 610f0f4eb..e04d99ac1 100644 --- a/perllib/FixMyStreet/App/Controller/Report/Update.pm +++ b/perllib/FixMyStreet/App/Controller/Report/Update.pm @@ -642,6 +642,8 @@ sub signup_for_alerts : Private { $alert->disable(); } + $c->cobrand->call_hook(update_email_shortlisted_user => $update); + return 1; } diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index f2551a16d..26638d41c 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -325,4 +325,9 @@ sub send_questionnaire { return 1; } +sub update_email_shortlisted_user { + my ($self, $update) = @_; + FixMyStreet::Cobrand::TfL::update_email_shortlisted_user($self, $update); +} + 1; diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm index 4543c1751..ececa1184 100644 --- a/perllib/FixMyStreet/Cobrand/TfL.pm +++ b/perllib/FixMyStreet/Cobrand/TfL.pm @@ -141,4 +141,23 @@ sub must_have_2fa { return 0; } +sub update_email_shortlisted_user { + my ($self, $update) = @_; + my $c = $self->{c}; + my $shortlisted_by = $update->problem->shortlisted_user; + if ($shortlisted_by && $shortlisted_by->from_body && $shortlisted_by->from_body->name eq 'TfL' && $shortlisted_by->id ne $update->user_id) { + $c->send_email('alert-update.txt', { + to => [ [ $shortlisted_by->email, $shortlisted_by->name ] ], + report => $update->problem, + problem_url => $c->cobrand->base_url_for_report($update->problem) . $update->problem->url, + data => [ { + item_photo => $update->photo, + item_text => $update->text, + item_name => $update->name, + item_anonymous => $update->anonymous, + } ], + }); + } +} + 1; diff --git a/t/cobrand/tfl.t b/t/cobrand/tfl.t index 6e6920c60..1c3b7e25b 100644 --- a/t/cobrand/tfl.t +++ b/t/cobrand/tfl.t @@ -87,6 +87,7 @@ subtest "reference number included in email" => sub { like $mech->get_text_body_from_email($email[0]), qr/Report reference: FMS$id/, "FMS-prefixed ID in TfL email"; is $email[1]->header('To'), $report->user->email; like $mech->get_text_body_from_email($email[1]), qr/report's reference number is FMS$id/, "FMS-prefixed ID in reporter email"; + $mech->clear_emails_ok; $mech->get_ok( '/report/' . $report->id ); $mech->content_contains('FMS' . $report->id) or diag $mech->content; @@ -172,6 +173,16 @@ subtest 'TfL admin allows inspectors to be assigned to borough areas' => sub { $staffuser->update({ area_ids => undef}); # so login below doesn't break }; +subtest 'Leave an update on a shortlisted report, get an email' => sub { + my $report = FixMyStreet::DB->resultset("Problem")->find({ title => 'Test Report 1'}); + $staffuser->add_to_planned_reports($report); + $mech->log_in_ok( $user->email ); + $mech->get_ok('/report/' . $report->id); + $mech->submit_form_ok({ with_fields => { update => 'This is an update' }}); + my $email = $mech->get_text_body_from_email; + like $email, qr/This is an update/; +}; + subtest 'TfL staff can access TfL admin' => sub { $mech->log_in_ok( $staffuser->email ); $mech->get_ok('/admin'); diff --git a/templates/email/default/alert-update.html b/templates/email/default/alert-update.html index e026cf146..1f1591b3d 100644 --- a/templates/email/default/alert-update.html +++ b/templates/email/default/alert-update.html @@ -14,7 +14,9 @@ INCLUDE '_email_top.html'; [% start_padded_box | safe %] <h1 style="[% h1_style %]">New updates on <a href="[% problem_url %]">[% title %]</a></h1> [%~ INCLUDE '_email_comment_list.html' %] + [% IF unsubscribe_url %] <p style="[% p_style %]"><a href="[% unsubscribe_url %]">Unsubscribe from alerts about this report</a></p> + [% END %] [% end_padded_box | safe %] </th> [% WRAPPER '_email_sidebar.html' object = report %] diff --git a/templates/email/default/alert-update.txt b/templates/email/default/alert-update.txt index 952b2dbca..903c68e35 100644 --- a/templates/email/default/alert-update.txt +++ b/templates/email/default/alert-update.txt @@ -21,6 +21,7 @@ please do not reply to it. [% signature %] +[% IF unsubscribe_url %] Unsubscribe? We currently email you whenever someone leaves an update on the @@ -28,3 +29,4 @@ We currently email you whenever someone leaves an update on the If you no longer wish to receive an email whenever this report is updated, please follow this link: [% unsubscribe_url %] +[% END %] |