From d1e9f2f3bc24630cdd12c034418e751d4b7eb856 Mon Sep 17 00:00:00 2001 From: Chris Mytton Date: Fri, 3 Nov 2023 10:23:33 +0000 Subject: [PATCH] Add button to allow resending report logged email --- CHANGELOG.md | 1 + .../App/Controller/Admin/Reports.pm | 9 ++ t/app/controller/admin/report_edit.t | 86 +++++++++++++++++++ t/cobrand/bexley.t | 2 +- .../web/base/admin/reports/_edit_main.html | 5 ++ .../web/base/admin/reports/_edit_waste.html | 6 ++ 6 files changed, 108 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8afc62fd088..3f55c0e0bc6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Added support for 'multivaluelist' extra category questions using checkboxes. - Added support for 'datetime' extra category questions using a datetime picker. - Added option to make a phone number required for a category. + - Added button on report admin page to resend the report logged email, where relevant. - Development improvements: - Extra data columns now stored as JSON, not RABX. #3216 - Cobrands can provide custom distances for duplicate lookup. #4456 diff --git a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm index 5ab7e2bc6b7..0c7f5e188da 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Reports.pm @@ -292,6 +292,15 @@ sub edit : Path('/admin/report_edit') : Args(1) { $c->stash->{status_message} = _('That problem has been marked as sent.'); $c->forward( '/admin/log_edit', [ $id, 'problem', 'marked sent' ] ); } + elsif ( $c->get_param('resend_report_logged_email') ) { + $c->forward('/auth/check_csrf_token'); + $problem->send_logged_email({ + report => $problem, + cobrand => $c->cobrand, + }, 0, $c->cobrand); + $c->forward( '/admin/log_edit', [ $id, 'problem', 'resent report logged email' ] ); + $c->stash->{status_message} = _('Report logged email has been resent'); + } elsif ( $c->get_param('submit') ) { $c->forward('/auth/check_csrf_token'); diff --git a/t/app/controller/admin/report_edit.t b/t/app/controller/admin/report_edit.t index a2c820225b5..a1ad770f4cb 100644 --- a/t/app/controller/admin/report_edit.t +++ b/t/app/controller/admin/report_edit.t @@ -15,9 +15,21 @@ $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic ligh $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Yellow lines', email => 'yellow@example.com', extra => { group => 'Road' } ); +my $camden = $mech->create_body_ok(2505, 'Camden Council'); +my $camdencontact = $mech->create_contact_ok( body_id => $camden->id, category => 'Potholes', email => 'camden-pothole@example.com' ); + my $oxford = $mech->create_body_ok(2421, 'Oxford City Council'); $mech->create_contact_ok( body_id => $oxford->id, category => 'Graffiti', email => 'graffiti@example.net' ); +my $bromley = $mech->create_body_ok(2482, 'Bromley Council', {}, { + cobrand => 'bromley', + wasteworks_config => { request_timeframe => "two weeks" } +}); +my $child_cat = $mech->create_contact_ok( body_id => $bromley->id, category => 'Request new container', email => 'container@example.com' ); +$child_cat->set_extra_metadata( type => 'waste', group => 'Waste' ); +$child_cat->set_extra_fields({ code => 'notes', datatype => 'text', order => 1, variable => 'true', description => 'Notes' }); +$child_cat->update; + my $dt = DateTime->new( year => 2011, month => 04, @@ -664,4 +676,78 @@ subtest "Test display of contributed_as data" => sub { $mech->content_contains('Created Body: Oxfordshire County Council'); }; +FixMyStreet::override_config { + ALLOWED_COBRANDS => ['camden', 'oxfordshire'], +}, sub { + subtest "Resend report logged email" => sub { + $mech->clear_emails_ok; + ok $mech->host('oxfordshire.fixmystreet.com'); + + my ($ox_report) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Big pothole in road', { + category => 'Potholes', + }); + my $ox_report_id = $ox_report->id; + + $mech->get_ok("/admin/report_edit/$ox_report_id"); + $mech->content_contains("Resend report logged email"); + $mech->submit_form_ok({ button => 'resend_report_logged_email' }); + $mech->content_contains("Report logged email has been resent"); + + ok $mech->email_count_is(1), "one email sent"; + my $email = $mech->get_email; + like $email->header('Subject'), qr/Your report has been logged/; + }; + + subtest "Resend report logged email for reports created on behalf of a user" => sub { + $mech->clear_emails_ok; + ok $mech->host('camden.fixmystreet.com'); + + my ($camden_report) = $mech->create_problems_for_body(1, $camden->id, 'Big pothole in road', { + category => 'Potholes', + }); + my $camden_report_id = $camden_report->id; + + $mech->get_ok("/admin/report_edit/$camden_report_id"); + $mech->content_lacks("Resend report logged email", 'no resend button for reports on camden cobrand'); + + # Change the report to be created on behalf of a user + $camden_report->set_extra_metadata( contributed_as => 'another_user' ); + $camden_report->update; + + $mech->get_ok("/admin/report_edit/$camden_report_id"); + $mech->content_contains("Resend report logged email", 'resend button for reports as another user'); + $mech->submit_form_ok({ button => 'resend_report_logged_email' }); + $mech->content_contains("Report logged email has been resent"); + + ok $mech->email_count_is(1), "one email sent"; + my $email = $mech->get_email; + like $email->header('Subject'), qr/Your report has been logged/; + }; +}; + +FixMyStreet::override_config { + ALLOWED_COBRANDS => 'bromley', + COBRAND_FEATURES => { echo => { bromley => { sample_data => 1 } }, waste => { bromley => 1 }, payment_gateway => { bromley => { ggw_cost => 1000 } } }, + MAPIT_URL => 'http://mapit.uk/', +}, sub { + subtest "Resend report logged email on WasteWorks" => sub { + $mech->log_in_ok($superuser->email); + my ($ww_report) = $mech->create_problems_for_body(1, $bromley->id, 'Request new container', { + category => 'Request new container', + cobrand_data => 'waste', + }); + my $ww_report_id = $ww_report->id; + $mech->clear_emails_ok; + + $mech->get_ok("/admin/report_edit/$ww_report_id"); + $mech->content_contains("Resend report logged email"); + $mech->submit_form_ok({ button => 'resend_report_logged_email' }); + $mech->content_contains("Report logged email has been resent"); + + ok $mech->email_count_is(1), "one email sent"; + my $email = $mech->get_email; + like $email->header('Subject'), qr/Your report has been logged/; + }; +}; + done_testing(); diff --git a/t/cobrand/bexley.t b/t/cobrand/bexley.t index 638bc76cbc6..b8c030506b0 100644 --- a/t/cobrand/bexley.t +++ b/t/cobrand/bexley.t @@ -227,7 +227,7 @@ FixMyStreet::override_config { $user->update({ from_body => $body, is_superuser => 1, name => 'Staff User' }); $mech->get_ok('/admin/report_edit/' . $report->id); $mech->content_contains('View report on site'); - $mech->content_lacks('Resend report'); + $mech->content_lacks('value="Resend report"'); }; subtest "resending of reports by changing category" => sub { diff --git a/templates/web/base/admin/reports/_edit_main.html b/templates/web/base/admin/reports/_edit_main.html index 2a6086718d9..4bc009531b4 100644 --- a/templates/web/base/admin/reports/_edit_main.html +++ b/templates/web/base/admin/reports/_edit_main.html @@ -70,6 +70,11 @@
  • [% loc('Reason:') %] [% problem.send_fail_reason | html %]
  • [% END %]
  • [% loc('Last update:') %] [% PROCESS format_time time=problem.lastupdate %]
  • +[% IF (c.cobrand.report_sent_confirmation_email(problem) || problem.get_extra_metadata('contributed_as') == 'another_user') && !c.cobrand.suppress_report_sent_email(problem) %] +
  • + +
  • +[% END %]
  • [% loc('Alerts:') %] [% alert_count %]
  • [% loc('Service:') %] [% problem.service OR '' _ loc('None') _ '' %]
  • [% loc('Cobrand:') %] [% problem.cobrand %] diff --git a/templates/web/base/admin/reports/_edit_waste.html b/templates/web/base/admin/reports/_edit_waste.html index 79d94668e45..a749ee8581b 100644 --- a/templates/web/base/admin/reports/_edit_waste.html +++ b/templates/web/base/admin/reports/_edit_waste.html @@ -34,6 +34,12 @@
  • [% loc('Last update:') %] [% PROCESS format_time time=problem.lastupdate %]
  • +[% IF c.cobrand.report_sent_confirmation_email(problem) && !c.cobrand.suppress_report_sent_email(problem) %] +
  • + +
  • +[% END %] +
  • [% INCLUDE 'admin/state_groups_select.html' %]