From b5b3b8e3cee367a8f82b4179a5d03f4d30e1215e Mon Sep 17 00:00:00 2001 From: Dave Arter Date: Wed, 15 Jun 2016 12:02:53 +0100 Subject: [UK Councils] Send correct confirm emails for updates Some UK councils with Open311 integrations (e.g. Bromley) have a custom wording in the confirmation email sent when updates are left on reports, to make the user aware that the update is sent to the council in question. Bromley noticed that some emails were being sent without this wording, leading at least one user to contact the council directly about the report. It turns out that although the email template contains an IF clause to use the appropriate wording for Bromley (and Stevenage) reports, the incorrect template file was being used when updates were made via the Bromley cobrand. This commit solves the problem by introducing a new `Cobrand::Default::path_to_email_templates` method, which is overridden by `Cobrand::UKCouncils` to include the `templates/email/fixmystreet` path. Paths returned by this method are used as the `additional_template_paths` param when templating emails. A regression test is included. Additionally moves email templates for fixmystreet.com to a directory name reflecting their purpose, in the same way the web templates are arranged. --- perllib/FixMyStreet/App.pm | 5 +- perllib/FixMyStreet/Cobrand/Default.pm | 18 +++++++ perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 7 +++ perllib/FixMyStreet/Cobrand/UKCouncils.pm | 10 ++++ perllib/FixMyStreet/Email.pm | 8 ++- t/cobrand/bromley.t | 62 +++++++++++++++++++++- templates/email/fixmystreet.com/signature.txt | 11 ++++ .../email/fixmystreet.com/submit-oxfordshire.txt | 45 ++++++++++++++++ templates/email/fixmystreet.com/submit.txt | 45 ++++++++++++++++ .../fixmystreet.com/update-confirm-donotsend.txt | 8 +++ templates/email/fixmystreet/signature.txt | 11 ---- templates/email/fixmystreet/submit-oxfordshire.txt | 45 ---------------- templates/email/fixmystreet/submit.txt | 45 ---------------- .../email/fixmystreet/update-confirm-donotsend.txt | 8 --- 14 files changed, 209 insertions(+), 119 deletions(-) create mode 100644 templates/email/fixmystreet.com/signature.txt create mode 100644 templates/email/fixmystreet.com/submit-oxfordshire.txt create mode 100644 templates/email/fixmystreet.com/submit.txt create mode 100644 templates/email/fixmystreet.com/update-confirm-donotsend.txt delete mode 100644 templates/email/fixmystreet/signature.txt delete mode 100644 templates/email/fixmystreet/submit-oxfordshire.txt delete mode 100644 templates/email/fixmystreet/submit.txt delete mode 100644 templates/email/fixmystreet/update-confirm-donotsend.txt diff --git a/perllib/FixMyStreet/App.pm b/perllib/FixMyStreet/App.pm index 1a651d282..be0e91101 100644 --- a/perllib/FixMyStreet/App.pm +++ b/perllib/FixMyStreet/App.pm @@ -310,10 +310,7 @@ sub send_email { from => [ $sender, _($sender_name) ], %{ $c->stash }, %$extra_stash_values, - additional_template_paths => [ - FixMyStreet->path_to( 'templates', 'email', $c->cobrand->moniker, $c->stash->{lang_code} )->stringify, - FixMyStreet->path_to( 'templates', 'email', $c->cobrand->moniker )->stringify, - ] + additional_template_paths => $c->cobrand->path_to_email_templates($c->stash->{lang_code}), }; return if FixMyStreet::Email::is_abuser($c->model('DB')->schema, $vars->{to}); diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index 4dc024d48..ee71f583f 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -32,6 +32,24 @@ sub path_to_web_templates { return $paths; } +=head1 path_to_email_templates + + $path = $cobrand->path_to_email_templates( ); + +Returns the path to the email templates for this cobrand - by default +"templates/email/$moniker" (and then default in Email.pm). + +=cut + +sub path_to_email_templates { + my ( $self, $lang_code ) = @_; + my $paths = [ + FixMyStreet->path_to( 'templates', 'email', $self->moniker, $lang_code )->stringify, + FixMyStreet->path_to( 'templates', 'email', $self->moniker )->stringify, + ]; + return $paths; +} + =head1 country Returns the country that this cobrand operates in, as an ISO3166-alpha2 code. diff --git a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm index c8c1eef66..d3de9da3a 100644 --- a/perllib/FixMyStreet/Cobrand/FixMyStreet.pm +++ b/perllib/FixMyStreet/Cobrand/FixMyStreet.pm @@ -10,6 +10,13 @@ sub path_to_web_templates { FixMyStreet->path_to( 'templates/web/fixmystreet.com' )->stringify, ]; } +sub path_to_email_templates { + my ( $self, $lang_code ) = @_; + return [ + FixMyStreet->path_to( 'templates', 'email', 'fixmystreet.com')->stringify, + ]; +} + # FixMyStreet should return all cobrands sub restriction { diff --git a/perllib/FixMyStreet/Cobrand/UKCouncils.pm b/perllib/FixMyStreet/Cobrand/UKCouncils.pm index 0321e0297..d9e8f8673 100644 --- a/perllib/FixMyStreet/Cobrand/UKCouncils.pm +++ b/perllib/FixMyStreet/Cobrand/UKCouncils.pm @@ -21,6 +21,16 @@ sub path_to_web_templates { ]; } +sub path_to_email_templates { + my ( $self, $lang_code ) = @_; + my $paths = [ + FixMyStreet->path_to( 'templates', 'email', $self->moniker, $lang_code )->stringify, + FixMyStreet->path_to( 'templates', 'email', $self->moniker )->stringify, + FixMyStreet->path_to( 'templates', 'email', 'fixmystreet.com')->stringify, + ]; + return $paths; +} + sub site_key { my $self = shift; return $self->council_url; diff --git a/perllib/FixMyStreet/Email.pm b/perllib/FixMyStreet/Email.pm index ce7dad47a..b12fcfab4 100644 --- a/perllib/FixMyStreet/Email.pm +++ b/perllib/FixMyStreet/Email.pm @@ -92,13 +92,11 @@ sub send_cron { unpack('h*', random_bytes(5, 1)), FixMyStreet->config('EMAIL_DOMAIN') ); + my @include_path = @{ $cobrand->path_to_email_templates($lang_code) }; + push @include_path, FixMyStreet->path_to( 'templates', 'email', 'default' )->stringify; my $tt = Template->new({ ENCODING => 'utf8', - INCLUDE_PATH => [ - FixMyStreet->path_to( 'templates', 'email', $cobrand->moniker, $lang_code )->stringify, - FixMyStreet->path_to( 'templates', 'email', $cobrand->moniker )->stringify, - FixMyStreet->path_to( 'templates', 'email', 'default' )->stringify, - ], + INCLUDE_PATH => \@include_path, }); $vars->{signature} = _render_template($tt, 'signature.txt', $vars); $vars->{site_name} = Utils::trim_text(_render_template($tt, 'site-name.txt', $vars)); diff --git a/t/cobrand/bromley.t b/t/cobrand/bromley.t index 1f61cd3de..6066c66b6 100644 --- a/t/cobrand/bromley.t +++ b/t/cobrand/bromley.t @@ -7,7 +7,7 @@ my $mech = FixMyStreet::TestMech->new; # Create test data my $user = $mech->create_user_ok( 'bromley@example.com' ); -my $body = $mech->create_body_ok( 2482, 'Bromley', id => 2482 ); +my $body = $mech->create_body_ok( 2482, 'Bromley Council', id => 2482 ); $mech->create_contact_ok( body_id => $body->id, category => 'Other', @@ -56,6 +56,66 @@ subtest 'testing special Open311 behaviour', sub { is $report->external_id, 248, 'Report has right external ID'; }; +for my $test ( + { + cobrand => 'bromley', + fields => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => 'Update from an unregistered user', + add_alert => undef, + first_name => 'Unreg', + last_name => 'User', + fms_extra_title => 'DR', + may_show_name => undef, + } + }, + { + cobrand => 'fixmystreet', + fields => { + submit_update => 1, + rznvy => 'unregistered@example.com', + update => 'Update from an unregistered user', + add_alert => undef, + name => 'Unreg User', + fms_extra_title => 'DR', + may_show_name => undef, + } + }, +) +{ + subtest 'check Bromley update emails via ' . $test->{cobrand} . ' cobrand are correct' => sub { + $mech->log_out_ok(); + $mech->clear_emails_ok(); + + my $report_id = $report->id; + + FixMyStreet::override_config { + ALLOWED_COBRANDS => [ $test->{cobrand} ], + }, sub { + $mech->get_ok("/report/$report_id"); + $mech->submit_form_ok( + { + with_fields => $test->{fields} + }, + 'submit update' + ); + }; + $mech->content_contains('Nearly done! Now check your email'); + + my $email = $mech->get_email; + ok $email, "got an email"; + like $email->body, qr/This update will be sent to Bromley Council/i, "Email indicates problem will be sent to Bromley"; + unlike $email->body, qr/Note that we do not send updates to/i, "Email does not say updates aren't sent to Bromley"; + + my $unreg_user = FixMyStreet::App->model( 'DB::User' )->find( { email => 'unregistered@example.com' } ); + + ok $unreg_user, 'found user'; + + $mech->delete_user( $unreg_user ); + }; +} + # Clean up $mech->delete_user($user); $mech->delete_body($body); diff --git a/templates/email/fixmystreet.com/signature.txt b/templates/email/fixmystreet.com/signature.txt new file mode 100644 index 000000000..834e69b9d --- /dev/null +++ b/templates/email/fixmystreet.com/signature.txt @@ -0,0 +1,11 @@ +All the best, + +The FixMyStreet team + +https://www.FixMyStreet.com +Twitter: https://twitter.com/FixMyStreet +Facebook: http://www.facebook.com/fixmystreet + +Problems? questions? + +Visit https://www.fixmystreet.com/faq diff --git a/templates/email/fixmystreet.com/submit-oxfordshire.txt b/templates/email/fixmystreet.com/submit-oxfordshire.txt new file mode 100644 index 000000000..f0fc5e9b7 --- /dev/null +++ b/templates/email/fixmystreet.com/submit-oxfordshire.txt @@ -0,0 +1,45 @@ +Subject: FMS Problem Report: [% title %] + +Dear [% bodies_name %], + +[% missing %][% multiple %]A user of +FixMyStreet has submitted the following report +of a local problem that they believe might require your attention. + +[% fuzzy %], or to provide an update on the problem, +please visit the following link: + + [% url %] + +[% has_photo %]---------- + +Name: [% name %] + +Email: [% email %] + +[% phone_line %][% category_line %]Subject: [% title %] + +Details: [% detail %] + +[% easting_northing %]Latitude: [% latitude %] + +Longitude: [% longitude %] + +View OpenStreetMap of this location: [% osm_url %] + +[% closest_address %]---------- + +Replies to this email will go to the user who submitted the problem. + +[% signature %] + +This message was sent via FixMyStreet, a project of UKCOD, registered charity +number 1076346. If there is a more appropriate email address for messages about +[% category_footer %], please let us know by visiting . +This will help improve the service for local people. We +also welcome any other feedback you may have. + +FixMyStreet is now available for full integration into council +websites, making life easier for both you and your residents. +Read more here: https://www.fixmystreet.com/council + diff --git a/templates/email/fixmystreet.com/submit.txt b/templates/email/fixmystreet.com/submit.txt new file mode 100644 index 000000000..17642e645 --- /dev/null +++ b/templates/email/fixmystreet.com/submit.txt @@ -0,0 +1,45 @@ +Subject: Problem Report: [% title %] + +Dear [% bodies_name %], + +[% missing %][% multiple %]A user of +FixMyStreet has submitted the following report +of a local problem that they believe might require your attention. + +[% fuzzy %], or to provide an update on the problem, +please visit the following link: + + [% url %] + +[% has_photo %]---------- + +Name: [% name %] + +Email: [% email %] + +[% phone_line %][% category_line %]Subject: [% title %] + +Details: [% detail %] + +[% easting_northing %]Latitude: [% latitude %] + +Longitude: [% longitude %] + +View OpenStreetMap of this location: [% osm_url %] + +[% closest_address %]---------- + +Replies to this email will go to the user who submitted the problem. + +[% signature %] + +This message was sent via FixMyStreet, a project of UKCOD, registered charity +number 1076346. If there is a more appropriate email address for messages about +[% category_footer %], please let us know by visiting . +This will help improve the service for local people. We +also welcome any other feedback you may have. + +FixMyStreet is now available for full integration into council +websites, making life easier for both you and your residents. +Read more here: https://www.fixmystreet.com/council + diff --git a/templates/email/fixmystreet.com/update-confirm-donotsend.txt b/templates/email/fixmystreet.com/update-confirm-donotsend.txt new file mode 100644 index 000000000..2e04dc0bf --- /dev/null +++ b/templates/email/fixmystreet.com/update-confirm-donotsend.txt @@ -0,0 +1,8 @@ +[% IF update.problem.bodies_str != 2482 AND update.problem.bodies_str != 2347 %] +Note that we do not send updates to [% update.problem.body %] - they are +intended as a place for [% INCLUDE 'site-name.txt' | trim %] users to +discuss, support, and offer advice. +[% ELSE %] +This update will be sent to [% update.problem.body %] and will +also be displayed on the [% INCLUDE 'site-name.txt' | trim %] website. +[% END %] diff --git a/templates/email/fixmystreet/signature.txt b/templates/email/fixmystreet/signature.txt deleted file mode 100644 index 834e69b9d..000000000 --- a/templates/email/fixmystreet/signature.txt +++ /dev/null @@ -1,11 +0,0 @@ -All the best, - -The FixMyStreet team - -https://www.FixMyStreet.com -Twitter: https://twitter.com/FixMyStreet -Facebook: http://www.facebook.com/fixmystreet - -Problems? questions? - -Visit https://www.fixmystreet.com/faq diff --git a/templates/email/fixmystreet/submit-oxfordshire.txt b/templates/email/fixmystreet/submit-oxfordshire.txt deleted file mode 100644 index f0fc5e9b7..000000000 --- a/templates/email/fixmystreet/submit-oxfordshire.txt +++ /dev/null @@ -1,45 +0,0 @@ -Subject: FMS Problem Report: [% title %] - -Dear [% bodies_name %], - -[% missing %][% multiple %]A user of -FixMyStreet has submitted the following report -of a local problem that they believe might require your attention. - -[% fuzzy %], or to provide an update on the problem, -please visit the following link: - - [% url %] - -[% has_photo %]---------- - -Name: [% name %] - -Email: [% email %] - -[% phone_line %][% category_line %]Subject: [% title %] - -Details: [% detail %] - -[% easting_northing %]Latitude: [% latitude %] - -Longitude: [% longitude %] - -View OpenStreetMap of this location: [% osm_url %] - -[% closest_address %]---------- - -Replies to this email will go to the user who submitted the problem. - -[% signature %] - -This message was sent via FixMyStreet, a project of UKCOD, registered charity -number 1076346. If there is a more appropriate email address for messages about -[% category_footer %], please let us know by visiting . -This will help improve the service for local people. We -also welcome any other feedback you may have. - -FixMyStreet is now available for full integration into council -websites, making life easier for both you and your residents. -Read more here: https://www.fixmystreet.com/council - diff --git a/templates/email/fixmystreet/submit.txt b/templates/email/fixmystreet/submit.txt deleted file mode 100644 index 17642e645..000000000 --- a/templates/email/fixmystreet/submit.txt +++ /dev/null @@ -1,45 +0,0 @@ -Subject: Problem Report: [% title %] - -Dear [% bodies_name %], - -[% missing %][% multiple %]A user of -FixMyStreet has submitted the following report -of a local problem that they believe might require your attention. - -[% fuzzy %], or to provide an update on the problem, -please visit the following link: - - [% url %] - -[% has_photo %]---------- - -Name: [% name %] - -Email: [% email %] - -[% phone_line %][% category_line %]Subject: [% title %] - -Details: [% detail %] - -[% easting_northing %]Latitude: [% latitude %] - -Longitude: [% longitude %] - -View OpenStreetMap of this location: [% osm_url %] - -[% closest_address %]---------- - -Replies to this email will go to the user who submitted the problem. - -[% signature %] - -This message was sent via FixMyStreet, a project of UKCOD, registered charity -number 1076346. If there is a more appropriate email address for messages about -[% category_footer %], please let us know by visiting . -This will help improve the service for local people. We -also welcome any other feedback you may have. - -FixMyStreet is now available for full integration into council -websites, making life easier for both you and your residents. -Read more here: https://www.fixmystreet.com/council - diff --git a/templates/email/fixmystreet/update-confirm-donotsend.txt b/templates/email/fixmystreet/update-confirm-donotsend.txt deleted file mode 100644 index 2e04dc0bf..000000000 --- a/templates/email/fixmystreet/update-confirm-donotsend.txt +++ /dev/null @@ -1,8 +0,0 @@ -[% IF update.problem.bodies_str != 2482 AND update.problem.bodies_str != 2347 %] -Note that we do not send updates to [% update.problem.body %] - they are -intended as a place for [% INCLUDE 'site-name.txt' | trim %] users to -discuss, support, and offer advice. -[% ELSE %] -This update will be sent to [% update.problem.body %] and will -also be displayed on the [% INCLUDE 'site-name.txt' | trim %] website. -[% END %] -- cgit v1.2.3