Skip to content

Commit

Permalink
[FMS] Add a dropdown to the admin to change send_status
Browse files Browse the repository at this point in the history
If a report is marked as not sent can choose whether to set
it as processed, unprocessed or skipped.

#3908
  • Loading branch information
MorayMySoc authored and dracos committed Dec 20, 2023
1 parent f8241c5 commit 99f49bb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
3 changes: 3 additions & 0 deletions perllib/FixMyStreet/App/Controller/Admin/Reports.pm
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,9 @@ sub edit : Path('/admin/report_edit') : Args(1) {
} else {
$problem->unset_extra_metadata('closed_updates');
}
if ($c->get_param('send_state') && ($c->get_param('send_state') ne $problem->send_state)) {
$problem->send_state($c->get_param('send_state'));

Check warning on line 334 in perllib/FixMyStreet/App/Controller/Admin/Reports.pm

View check run for this annotation

Codecov / codecov/patch

perllib/FixMyStreet/App/Controller/Admin/Reports.pm#L334

Added line #L334 was not covered by tests
};

$c->forward( '/admin/reports/edit_category', [ $problem, $problem->state ne $old_state ] );
$c->forward('/admin/update_user', [ $problem ]);
Expand Down
46 changes: 44 additions & 2 deletions t/app/controller/admin/report_edit.t
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ my $user = $mech->create_user_ok('[email protected]', name => 'Test User');
my $user2 = $mech->create_user_ok('[email protected]', name => 'Test User 2');
my $superuser = $mech->create_user_ok('[email protected]', name => 'Super User', is_superuser => 1);

my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council');
my $oxfordshire = $mech->create_body_ok(2237, 'Oxfordshire County Council', {}, {cobrand => 'oxfordshire'});
my $user3 = $mech->create_user_ok('[email protected]', name => 'Body User', from_body => $oxfordshire);
my $oxfordshirecontact = $mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Potholes', email => '[email protected]', extra => { group => 'Road' } );
$mech->create_contact_ok( body_id => $oxfordshire->id, category => 'Traffic lights', email => '[email protected]' );
Expand Down Expand Up @@ -272,7 +272,7 @@ foreach my $test (
non_public => undef,
closed_updates => undef,
},
changes => {},
changes => { send_state => '' },
log_entries => [
qw/resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/
],
Expand All @@ -290,6 +290,7 @@ foreach my $test (
flagged => 'on',
non_public => undef,
closed_updates => undef,
send_state => '',
},
changes => {
non_public => 'on',
Expand All @@ -311,6 +312,7 @@ foreach my $test (
flagged => 'on',
non_public => 'on',
closed_updates => undef,
send_state => '',
},
changes => { closed_updates => 'on' },
log_entries => [
Expand All @@ -329,6 +331,7 @@ foreach my $test (
flagged => 'on',
non_public => 'on',
closed_updates => undef,
send_state => '',
},
expect_comment => 1,
changes => { state => 'investigating' },
Expand All @@ -349,6 +352,7 @@ foreach my $test (
flagged => 'on',
non_public => 'on',
closed_updates => undef,
send_state => '',
},
expect_comment => 1,
expected_text => '*Category changed from ‘Other’ to ‘Potholes’*',
Expand Down Expand Up @@ -415,6 +419,7 @@ foreach my $test (
$mech->content_contains("Subject: <ins style='background-color:#cfc'>Edited </ins>Repor<del style='background-color:#fcc'>t to Edi</del>") if $test->{changes}{title};
}

delete $test->{changes}->{send_state}; # send_state can have a value of '' so may not correspond to the report
is $report->$_, $test->{changes}->{$_}, "$_ updated" for grep { $_ ne 'username' } keys %{ $test->{changes} };

if ( $test->{user} ) {
Expand Down Expand Up @@ -491,6 +496,7 @@ subtest 'change email to new user' => sub {
external_id => '13',
external_body => '',
external_team => '',
send_state => '',
};

is_deeply( $mech->visible_form_values(), $fields, 'initial form values' );
Expand Down Expand Up @@ -664,4 +670,40 @@ subtest "Test display of contributed_as data" => sub {
$mech->content_contains('Created Body</strong>: Oxfordshire County Council');
};

subtest "Test display and changing of send_status" => sub {

$mech->get_ok("/admin/report_edit/$report_id");
$mech->content_like(qr/label for="send_state"/, "Change status available for superuser");
$mech->content_unlike(qr/selected value="processed"/, 'processed not selected in dropdown');
$mech->content_unlike(qr/selected value="skipped"/, 'skipped not selected in dropdown');
for my $send_state (
qw/skipped processed/
) {
$mech->submit_form_ok( { with_fields => { send_state => $send_state } } );
$mech->content_like(qr/selected value="$send_state"/, $send_state . ' send_state selected for unsent report');
$report->discard_changes;
is $report->send_state, $send_state, 'Send state changed to ' . $send_state;
}
$report->mark_as_sent;
$report->update;
$mech->get_ok("/admin/report_edit/$report_id");
$mech->content_unlike(qr/label for="send_state"/, "Sent report doesn't allow changing sent status");

my ($ox_report2) = $mech->create_problems_for_body(1, $oxfordshire->id, 'Another Oxfordshire report', {
category => 'Potholes',
areas => ',2237,2421,', # Cached used by categories_for_point...
latitude => 51.7549262252,
longitude => -1.25617899435,
});

FixMyStreet::override_config {
ALLOWED_COBRANDS => [ 'oxfordshire'],
}, sub {
$user3->user_body_permissions->create({ body => $oxfordshire, permission_type => 'report_edit' });
$mech->log_in_ok($user3->email);
$mech->get_ok("/admin/report_edit/" . $ox_report2->id);
$mech->content_unlike(qr/label for="send_state"/, "Body user can't change send_state");
}
};

done_testing();
8 changes: 8 additions & 0 deletions templates/web/base/admin/reports/_edit_main.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@
<input type="submit" class="btn" name="mark_sent" value="[% loc('Mark as sent') %]">
[% END %]
</li>
[% IF NOT problem.whensent AND c.user.is_superuser %]
<li class="sm"><label for="send_state">[% loc('Send state:') %]</label>
<select class="form-control" name="send_state" id="send_state">
[% FOREACH state IN [ ['', '-- Change --'], ['processed', loc('Processed')], ['skipped', loc('Skipped')]] %]
<option [% 'selected ' IF state.0 == problem.send_state %] value="[% state.0 %]">[% state.1 %]</option>
[% END %]
</select></li>
[% END %]
[% IF c.user.is_superuser AND problem.send_fail_count > 0 %]
<li class="sm">[% loc('Send Fail Count:') %] [% problem.send_fail_count %]</li>
<li class="sm">[% loc('Last failure:') %] [% PROCESS format_time time=problem.send_fail_timestamp %]</li>
Expand Down

0 comments on commit 99f49bb

Please sign in to comment.