Skip to content

Commit

Permalink
fixup! fixup! fixup! [Bucks] Add email alternative to templates
Browse files Browse the repository at this point in the history
  • Loading branch information
MorayMySoc committed Aug 16, 2022
1 parent 54a1366 commit f7200d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
10 changes: 6 additions & 4 deletions perllib/FixMyStreet/Template.pm
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ it all to text.

sub email_sanitize_text : Fn('email_sanitize_text') {
my $update = shift;
my $column = shift;

my $text = $update->{item_text};
my $text = $column ? $update->{$column} : $update->{item_text};
my $extra = $update->{item_extra};
utf8::encode($extra) if $extra;
$extra = $extra ? RABX::wire_rd(new IO::String($extra)) : {};

my $staff = $extra->{is_superuser} || $extra->{is_body_user};
my $staff = $extra->{is_superuser} || $extra->{is_body_user} || $column;

return $text unless $staff;

Expand Down Expand Up @@ -250,13 +251,14 @@ in updates from staff/superusers.

sub email_sanitize_html : Fn('email_sanitize_html') {
my $update = shift;
my $column = shift;

my $text = $update->{item_text};
my $text = $column ? $update->{$column} : $update->{item_text};
my $extra = $update->{item_extra};
utf8::encode($extra) if $extra;
$extra = $extra ? RABX::wire_rd(new IO::String($extra)) : {};

my $staff = $extra->{is_superuser} || $extra->{is_body_user};
my $staff = $extra->{is_superuser} || $extra->{is_body_user} || $column;

return _staff_html_markup($text, $staff);
}
Expand Down
10 changes: 5 additions & 5 deletions t/app/controller/report_new_update.t
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ $template = FixMyStreet::DB->resultset("ResponseTemplate")->create({
text => 'Thanks for your report. We will investigate within 5 working days.',
email_text => 'Thanks for your report.
This is the email alternative.',
This is the email <a href="https://google.com">alternative</a>.',
auto_response => 1,
});

Expand All @@ -85,17 +85,17 @@ subtest "test report creation with initial auto-update and alternative email tex
my ($email_for_subscriber) = grep { $_->header('To') =~ /test-3/ } @emails;

is $mech->get_text_body_from_email($email_for_subscriber) =~ /Thanks for your report. We will investigate within 5 working days./, 1, "Text template sent to subscriber";
is $mech->get_text_body_from_email($email_for_reporter) =~ /This is the email alternative/, 1, "Email template sent to reporter";
is $mech->get_html_body_from_email($email_for_reporter) =~ /<p style="margin: 0 0 16px 0;">\r\nThis is the email alternative.<\/p>/, 1, "Email template text in paragraphs";
is $mech->get_text_body_from_email($email_for_reporter) =~ /This is the email alternative \[https:\/\/google.com\]/, 1, "Email template sent to reporter";
is $mech->get_html_body_from_email($email_for_reporter) =~ /<p style="margin: 0 0 16px 0;">\r\nThis is the email <a href\="https:\/\/google\.com">alternative<\/a>.<\/p>/, 1, "Email template text in paragraphs";

my $counciluser = $mech->create_user_ok('[email protected]', name => 'Council User', from_body => $body, is_superuser => 1);
$mech->log_in_ok($counciluser->email);
$mech->get_ok("/admin/report_edit/$report_id");
$mech->content_contains("This is the email alternative.", "Extra template email text displayed");
$mech->content_contains('This is the email ', "Extra template email text displayed");
my $update_id = $report->comments->first->id;
$mech->get_ok("/admin/update_edit/$update_id");
$mech->content_contains("Template email response:", "Template email input present");
$mech->content_contains("This is the email alternative.", "Template email input populated");
$mech->content_contains("This is the email ", "Template email input populated");
$report->comments->first->delete;
$update_id = $mech->create_comment_for_problem($report, $comment_user, 'User', 'Non-template update', 0, 'confirmed', 'confirmed')->id;
$mech->get_ok("/admin/report_edit/$report_id");
Expand Down
3 changes: 1 addition & 2 deletions templates/email/default/templated_email_alert-update.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
[% start_padded_box | safe %]
<h1 style="[% h1_style %]">New updates on <a href="[% problem_url %]">[% title %]</a></h1>
[% FOR row IN data -%]
[% update.item_text = row.item_private_email_text %]
[% email_sanitize_html(update) | replace('<p>', '<p style="' _ list_item_p_style _ '">') %]
[% email_sanitize_html(row, "item_private_email_text") | replace('<p>', '<p style="' _ list_item_p_style _ '">') %]
[% END %]
[% TRY %][% INCLUDE '_alert_update_after_updates.html' %][% CATCH file %][% END %]
[% IF unsubscribe_url %]
Expand Down
3 changes: 1 addition & 2 deletions templates/email/default/templated_email_alert-update.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
Subject: New [% site_name %] council updates on report: '[% report.title %]'

[% FOR row IN data -%]
[% update.item_text = row.item_private_email_text %]
[% email_sanitize_text(update) %]
[% email_sanitize_text(row, 'item_private_email_text') %]
[% END %]

[% state_message %]
Expand Down

0 comments on commit f7200d5

Please sign in to comment.