aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet/App/Controller
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2017-09-29 16:48:58 +0100
committerStruan Donald <struan@exo.org.uk>2017-10-04 12:05:21 +0100
commit70ddda2c5e851c012b2bb98ec74c87490be6dad0 (patch)
tree7378d895be770ee533c999f1e08b4b2a78dbf391 /perllib/FixMyStreet/App/Controller
parent2c083bab1fab506a06f27561a5e17408f4b0b723 (diff)
correctly handle category changes in inspector form
This resolves two issues when updating the report category in the staff users inspect form: * report category is only updated if the rest of the form is valid * only one update on the report is left Previously changing the category would create an update in addition to any public update created, and the category was always updated even when validation errors occurred elsewhere in the form.
Diffstat (limited to 'perllib/FixMyStreet/App/Controller')
-rw-r--r--perllib/FixMyStreet/App/Controller/Admin.pm27
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm6
2 files changed, 21 insertions, 12 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin.pm b/perllib/FixMyStreet/App/Controller/Admin.pm
index 0caa25710..b854f16f5 100644
--- a/perllib/FixMyStreet/App/Controller/Admin.pm
+++ b/perllib/FixMyStreet/App/Controller/Admin.pm
@@ -950,7 +950,7 @@ Handles changing a problem's category and the complexity that comes with it.
=cut
sub report_edit_category : Private {
- my ($self, $c, $problem) = @_;
+ my ($self, $c, $problem, $no_comment) = @_;
if ((my $category = $c->get_param('category')) ne $problem->category) {
my $category_old = $problem->category;
@@ -978,16 +978,21 @@ sub report_edit_category : Private {
}
$problem->bodies_str(join( ',', @new_body_ids ));
- $problem->add_to_comments({
- text => '*' . sprintf(_('Category changed from ‘%s’ to ‘%s’'), $category_old, $category) . '*',
- created => \'current_timestamp',
- confirmed => \'current_timestamp',
- user_id => $c->user->id,
- name => $c->user->from_body ? $c->user->from_body->name : $c->user->name,
- state => 'confirmed',
- mark_fixed => 0,
- anonymous => 0,
- });
+ my $update_text = '*' . sprintf(_('Category changed from ‘%s’ to ‘%s’'), $category_old, $category) . '*';
+ if ($no_comment) {
+ $c->stash->{update_text} = $update_text;
+ } else {
+ $problem->add_to_comments({
+ text => $update_text,
+ created => \'current_timestamp',
+ confirmed => \'current_timestamp',
+ user_id => $c->user->id,
+ name => $c->user->from_body ? $c->user->from_body->name : $c->user->name,
+ state => 'confirmed',
+ mark_fixed => 0,
+ anonymous => 0,
+ });
+ }
}
}
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index ba9fa11b9..c72c75d3a 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -424,7 +424,11 @@ sub inspect : Private {
}
if ($permissions->{report_inspect} || $permissions->{report_edit_category}) {
- $c->forward( '/admin/report_edit_category', [ $problem ] );
+ $c->forward( '/admin/report_edit_category', [ $problem, 1 ] );
+
+ if ($c->stash->{update_text}) {
+ $update_text .= "\n\n" . $c->stash->{update_text};
+ }
# The new category might require extra metadata (e.g. pothole size), so
# we need to update the problem with the new values.