Skip to content

Commit

Permalink
Add button to allow resending report logged email
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismytton committed Dec 12, 2023
1 parent 999621a commit d1e9f2f
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions perllib/FixMyStreet/App/Controller/Admin/Reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
86 changes: 86 additions & 0 deletions t/app/controller/admin/report_edit.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 => '[email protected]', 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 => '[email protected]' );

my $oxford = $mech->create_body_ok(2421, 'Oxford City Council');
$mech->create_contact_ok( body_id => $oxford->id, category => 'Graffiti', email => '[email protected]' );

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 => '[email protected]' );
$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,
Expand Down Expand Up @@ -664,4 +676,78 @@ subtest "Test display of contributed_as data" => sub {
$mech->content_contains('Created Body</strong>: 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();
2 changes: 1 addition & 1 deletion t/cobrand/bexley.t
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions templates/web/base/admin/reports/_edit_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@
<li class="sm truncate_height">[% loc('Reason:') %] [% problem.send_fail_reason | html %]</li>
[% END %]
<li class="sm">[% loc('Last update:') %] [% PROCESS format_time time=problem.lastupdate %]</li>
[% IF (c.cobrand.report_sent_confirmation_email(problem) || problem.get_extra_metadata('contributed_as') == 'another_user') && !c.cobrand.suppress_report_sent_email(problem) %]
<li class="sm">
<input type="submit" class="btn" name="resend_report_logged_email" value="[% loc('Resend report logged email') %]">
</li>
[% END %]
<li>[% loc('Alerts:') %] [% alert_count %]</li>
<li>[% loc('Service:') %] [% problem.service OR '<em>' _ loc('None') _ '</em>' %]</li>
<li>[% loc('Cobrand:') %] [% problem.cobrand %]
Expand Down
6 changes: 6 additions & 0 deletions templates/web/base/admin/reports/_edit_waste.html
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
<li class="sm">[% loc('Last update:') %] [% PROCESS format_time time=problem.lastupdate %]</li>
<!-- <li>[% loc('Service:') %] [% problem.service OR '<em>' _ loc('None') _ '</em>' %]</li> -->

[% IF c.cobrand.report_sent_confirmation_email(problem) && !c.cobrand.suppress_report_sent_email(problem) %]
<li class="sm">
<input type="submit" class="btn" name="resend_report_logged_email" value="[% loc('Resend report logged email') %]">
</li>
[% END %]

<li>
<label class="inline-text" for="state">[% loc('State:') %]</label>
[% INCLUDE 'admin/state_groups_select.html' %]
Expand Down

0 comments on commit d1e9f2f

Please sign in to comment.