diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin.pm | 67 | ||||
-rw-r--r-- | t/app/controller/admin.t | 32 | ||||
-rw-r--r-- | templates/web/base/admin/report_edit.html | 22 |
3 files changed, 51 insertions, 70 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm index b7f051c11..50b4360eb 100644 --- a/perllib/FixMyStreet/App/Controller/Admin.pm +++ b/perllib/FixMyStreet/App/Controller/Admin.pm @@ -723,37 +723,17 @@ sub report_edit : Path('report_edit') : Args(1) { elsif ( $c->get_param('submit') ) { $c->forward('/auth/check_csrf_token'); - my $done = 0; - my $edited = 0; - - my $new_state = $c->get_param('state'); my $old_state = $problem->state; - my $flagged = $c->get_param('flagged') ? 1 : 0; - my $non_public = $c->get_param('non_public') ? 1 : 0; - - # do this here so before we update the values in problem - if ( $c->get_param('anonymous') ne $problem->anonymous - || $c->get_param('name') ne $problem->name - || $c->get_param('email') ne $problem->user->email - || $c->get_param('title') ne $problem->title - || $c->get_param('detail') ne $problem->detail - || ($c->get_param('body') && $c->get_param('body') ne $problem->bodies_str) - || $flagged != $problem->flagged - || $non_public != $problem->non_public ) - { - $edited = 1; + my %columns = ( + flagged => $c->get_param('flagged') ? 1 : 0, + non_public => $c->get_param('non_public') ? 1 : 0, + ); + $columns{bodies_str} = $c->get_param('body') if $c->get_param('body'); + foreach (qw/state anonymous title detail name external_id external_body external_team/) { + $columns{$_} = $c->get_param($_); } - - $problem->anonymous( $c->get_param('anonymous') ); - $problem->title( $c->get_param('title') ); - $problem->detail( $c->get_param('detail') ); - $problem->state( $new_state ); - $problem->name( $c->get_param('name') ); - $problem->bodies_str( $c->get_param('body') ) if $c->get_param('body'); - - $problem->flagged( $flagged ); - $problem->non_public( $non_public ); + $problem->set_inflated_columns(\%columns); if ( $c->get_param('email') ne $problem->user->email ) { my $user = $c->model('DB::User')->find_or_create( @@ -770,7 +750,7 @@ sub report_edit : Path('report_edit') : Args(1) { $self->remove_photo($c, $problem, $remove_photo_param); } - if ( $remove_photo_param || $new_state eq 'hidden' ) { + if ( $remove_photo_param || $problem->state eq 'hidden' ) { $problem->get_photoset->delete_cached; } @@ -778,27 +758,20 @@ sub report_edit : Path('report_edit') : Args(1) { $problem->confirmed( \'current_timestamp' ); } - if ($done) { - $problem->discard_changes; - } - else { - $problem->lastupdate( \'current_timestamp' ) if $edited || $new_state ne $old_state; - $problem->update; + $problem->lastupdate( \'current_timestamp' ); + $problem->update; - if ( $new_state ne $old_state ) { - $c->forward( 'log_edit', [ $id, 'problem', 'state_change' ] ); - } - if ($edited) { - $c->forward( 'log_edit', [ $id, 'problem', 'edit' ] ); - } + if ( $problem->state ne $old_state ) { + $c->forward( 'log_edit', [ $id, 'problem', 'state_change' ] ); + } + $c->forward( 'log_edit', [ $id, 'problem', 'edit' ] ); - $c->stash->{status_message} = - '<p><em>' . _('Updated!') . '</em></p>'; + $c->stash->{status_message} = + '<p><em>' . _('Updated!') . '</em></p>'; - # do this here otherwise lastupdate and confirmed times - # do not display correctly - $problem->discard_changes; - } + # do this here otherwise lastupdate and confirmed times + # do not display correctly + $problem->discard_changes; } return 1; diff --git a/t/app/controller/admin.t b/t/app/controller/admin.t index dc7aed341..f8f280d63 100644 --- a/t/app/controller/admin.t +++ b/t/app/controller/admin.t @@ -327,7 +327,6 @@ foreach my $test ( non_public => undef, }, changes => { title => 'Edited Report', }, - log_count => 1, log_entries => [qw/edit/], resend => 0, }, @@ -344,7 +343,6 @@ foreach my $test ( non_public => undef, }, changes => { detail => 'Edited Detail', }, - log_count => 2, log_entries => [qw/edit edit/], resend => 0, }, @@ -361,7 +359,6 @@ foreach my $test ( non_public => undef, }, changes => { name => 'Edited User', }, - log_count => 3, log_entries => [qw/edit edit edit/], resend => 0, user => $user, @@ -381,7 +378,6 @@ foreach my $test ( changes => { flagged => 'on', }, - log_count => 4, log_entries => [qw/edit edit edit edit/], resend => 0, user => $user, @@ -399,7 +395,6 @@ foreach my $test ( non_public => undef, }, changes => { email => $user2->email, }, - log_count => 5, log_entries => [qw/edit edit edit edit edit/], resend => 0, user => $user2, @@ -417,8 +412,7 @@ foreach my $test ( non_public => undef, }, changes => { state => 'unconfirmed' }, - log_count => 6, - log_entries => [qw/state_change edit edit edit edit edit/], + log_entries => [qw/edit state_change edit edit edit edit edit/], resend => 0, }, { @@ -434,8 +428,7 @@ foreach my $test ( non_public => undef, }, changes => { state => 'confirmed' }, - log_count => 7, - log_entries => [qw/state_change state_change edit edit edit edit edit/], + log_entries => [qw/edit state_change edit state_change edit edit edit edit edit/], resend => 0, }, { @@ -451,9 +444,8 @@ foreach my $test ( non_public => undef, }, changes => { state => 'fixed' }, - log_count => 8, log_entries => - [qw/state_change state_change state_change edit edit edit edit edit/], + [qw/edit state_change edit state_change edit state_change edit edit edit edit edit/], resend => 0, }, { @@ -469,9 +461,8 @@ foreach my $test ( non_public => undef, }, changes => { state => 'hidden' }, - log_count => 9, log_entries => [ - qw/state_change state_change state_change state_change edit edit edit edit edit/ + qw/edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ ], resend => 0, }, @@ -491,9 +482,8 @@ foreach my $test ( state => 'confirmed', anonymous => 1, }, - log_count => 11, log_entries => [ - qw/edit state_change state_change state_change state_change state_change edit edit edit edit edit/ + qw/edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ ], resend => 0, }, @@ -510,9 +500,8 @@ foreach my $test ( non_public => undef, }, changes => {}, - log_count => 12, log_entries => [ - qw/resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ + qw/resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ ], resend => 1, }, @@ -531,9 +520,8 @@ foreach my $test ( changes => { non_public => 'on', }, - log_count => 13, log_entries => [ - qw/edit resend edit state_change state_change state_change state_change state_change edit edit edit edit edit/ + qw/edit resend edit state_change edit state_change edit state_change edit state_change edit state_change edit edit edit edit edit/ ], resend => 0, }, @@ -543,6 +531,7 @@ foreach my $test ( $log_entries->reset; $mech->get_ok("/admin/report_edit/$report_id"); + @{$test->{fields}}{'external_id', 'external_body', 'external_team'} = (13, "", ""); is_deeply( $mech->visible_form_values(), $test->{fields}, 'initial form values' ); my $new_fields = { @@ -557,7 +546,7 @@ foreach my $test ( } is_deeply( $mech->visible_form_values(), $new_fields, 'changed form values' ); - is $log_entries->count, $test->{log_count}, 'log entry count'; + is $log_entries->count, scalar @{$test->{log_entries}}, 'log entry count'; is $log_entries->next->action, $_, 'log entry added' for @{ $test->{log_entries} }; $report->discard_changes; @@ -596,6 +585,9 @@ subtest 'change email to new user' => sub { anonymous => 1, flagged => 'on', non_public => 'on', + external_id => '13', + external_body => '', + external_team => '', }; is_deeply( $mech->visible_form_values(), $fields, 'initial form values' ); diff --git a/templates/web/base/admin/report_edit.html b/templates/web/base/admin/report_edit.html index e3deccaf6..677c2a171 100644 --- a/templates/web/base/admin/report_edit.html +++ b/templates/web/base/admin/report_edit.html @@ -52,7 +52,7 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a> [% IF problem.used_map %][% loc('used map') %][% ELSE %][% loc("didn't use map") %][% END %])</small> </li> -<li>[% loc('Body:') %] +<li>[% loc('Bodies') %]: [% IF problem.bodies_str %] [% FOREACH body IN problem.bodies.values %] [% SET body_printed = 1 %] @@ -67,6 +67,9 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a> [% END %] <small>([% loc('other areas:') %] [% problem.areas | remove('^,') | remove( ',$' ) | replace(',', ', ') %])</small> </li> +[% IF problem.bodies_missing %] +<li>[% loc('Missing bodies:') %] [% problem.bodies_missing | html %]</li> +[% END %] [% IF problem.extra.address %] <li>[% loc('Property address:') %] [% problem.extra.address | html %]</li> [% END %] @@ -74,8 +77,14 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a> <li class="sm">[% loc('Created:') %] [% PROCESS format_time time=problem.created %]</li> <li class="sm">[% loc('Confirmed:') %] [% PROCESS format_time time=problem.confirmed no_time='-' %]</li> <li class="sm">[% loc('Sent:') %] [% PROCESS format_time time=problem.whensent %] -[% IF problem.state == 'confirmed' AND problem.whensent %]<input onclick="return confirm('[% loc('You really want to resend?') %]')" type="submit" name="resend" value="[% loc('Resend report') %]">[% END %] -[% IF NOT problem.whensent %]<input type="submit" name="mark_sent" value="[% loc('Mark as sent') %]">[% END %] + [% IF problem.send_method_used %] + ([% problem.send_method_used %]) + [% END %] + [% IF problem.state == 'confirmed' AND problem.whensent %] + <input onclick="return confirm('[% loc('You really want to resend?') %]')" type="submit" name="resend" value="[% loc('Resend report') %]"> + [% ELSIF NOT problem.whensent %] + <input type="submit" name="mark_sent" value="[% loc('Mark as sent') %]"> + [% END %] </li> <li class="sm">[% loc('Last update:') %] [% PROCESS format_time time=problem.lastupdate %]</li> <li>[% loc('Service:') %] [% problem.service OR '<em>' _ loc('None') _ '</em>' %]</li> @@ -85,6 +94,13 @@ class="admin-offsite-link">[% problem.latitude %], [% problem.longitude %]</a> <li>[% loc('Extra data:') %] [% problem.extra ? 'Yes' : 'No' %]</li> <li>[% loc('Going to send questionnaire?') %] [% IF problem.send_questionnaire %][% loc('Yes') %][% ELSE %][% loc('No') %][% END %]</li> +<li><label for="external_id">[% loc('External ID') %]:</label> + <input type="text" name="external_id" id="external_id" value="[% problem.external_id | html %]"> +<li><label for="external_body">[% loc('External body') %]:</label> + <input type="text" name="external_body" body="external_body" value="[% problem.external_body | html %]"> +<li><label for="external_team">[% loc('External team') %]:</label> + <input type="text" name="external_team" team="external_team" value="[% problem.external_team | html %]"> + </ul> </div> |