diff options
author | Dave Arter <davea@mysociety.org> | 2016-06-15 12:02:53 +0100 |
---|---|---|
committer | Dave Arter <davea@mysociety.org> | 2016-06-15 14:10:33 +0100 |
commit | b5b3b8e3cee367a8f82b4179a5d03f4d30e1215e (patch) | |
tree | d794ea247a6b5a2c7dcff42e77990217eacb02e9 /perllib | |
parent | 96c72fa72e547a2ce5b435db3cae8c3c45efafc1 (diff) |
[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.
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/App.pm | 5 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/FixMyStreet.pm | 7 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UKCouncils.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Email.pm | 8 |
5 files changed, 39 insertions, 9 deletions
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)); |