aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm17
-rw-r--r--t/app/controller/report_inspect.t26
3 files changed, 37 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bbf001338..daf4fea1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@
- Send details of unresponsive bodies to mobile app #2164
- Fix issue with category filter when category contains comma #2166
- Inspectors can unset priority. #2171
+ - Defect type is recorded if category change made. #2172
- Open311 improvements:
- CLOSED status maps to 'closed' state if extended statuses are enabled.
diff --git a/perllib/FixMyStreet/App/Controller/Report.pm b/perllib/FixMyStreet/App/Controller/Report.pm
index 669d3c41f..a1f357644 100644
--- a/perllib/FixMyStreet/App/Controller/Report.pm
+++ b/perllib/FixMyStreet/App/Controller/Report.pm
@@ -375,12 +375,6 @@ sub inspect : Private {
}
}
- if ( $c->get_param('defect_type') ) {
- $problem->defect_type($problem->defect_types->find($c->get_param('defect_type')));
- } else {
- $problem->defect_type(undef);
- }
-
if ( $c->get_param('include_update') ) {
$update_text = Utils::cleanup_text( $c->get_param('public_update'), { allow_multiline => 1 } );
if (!$update_text) {
@@ -461,7 +455,8 @@ sub inspect : Private {
$c->forward('/report/new/set_report_extras', [ \@contacts, $param_prefix ]);
}
- # Updating priority must come after category, in case category has changed (and so might have priorities)
+ # Updating priority/defect type must come after category, in case
+ # category has changed (and so might have priorities/defect types)
if ($permissions->{report_inspect} || $permissions->{report_edit_priority}) {
if ($c->get_param('priority')) {
$problem->response_priority( $problem->response_priorities->find({ id => $c->get_param('priority') }) );
@@ -470,6 +465,14 @@ sub inspect : Private {
}
}
+ if ($permissions->{report_inspect}) {
+ if ( $c->get_param('defect_type') ) {
+ $problem->defect_type($problem->defect_types->find($c->get_param('defect_type')));
+ } else {
+ $problem->defect_type(undef);
+ }
+ }
+
if ($valid) {
if ( $reputation_change != 0 ) {
$problem->user->update_reputation($reputation_change);
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 260339da8..33e3b39c3 100644
--- a/t/app/controller/report_inspect.t
+++ b/t/app/controller/report_inspect.t
@@ -7,6 +7,14 @@ my $oxon = $mech->create_body_ok(2237, 'Oxfordshire County Council', { can_be_de
my $contact = $mech->create_contact_ok( body_id => $oxon->id, category => 'Cows', email => 'cows@example.net' );
my $contact2 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Sheep', email => 'SHEEP', send_method => 'Open311' );
my $contact3 = $mech->create_contact_ok( body_id => $oxon->id, category => 'Badgers', email => 'badgers@example.net' );
+my $dt = FixMyStreet::DB->resultset("DefectType")->create({
+ body => $oxon,
+ name => 'Small Defect', description => "Teeny",
+});
+FixMyStreet::DB->resultset("ContactDefectType")->create({
+ contact => $contact,
+ defect_type => $dt,
+});
my $rp = FixMyStreet::DB->resultset("ResponsePriority")->create({
body => $oxon,
name => 'High Priority',
@@ -394,6 +402,24 @@ FixMyStreet::override_config {
is $report->response_priority->id, $rp->id, 'response priority set';
};
+ subtest "check can set defect type for category when changing from category with no defect types" => sub {
+ $report->update({ category => 'Sheep', defect_type_id => undef });
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_inspect' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ include_update => 0,
+ defect_type => $dt->id,
+ category => 'Cows',
+ }
+ });
+ $report->discard_changes;
+ is $report->defect_type->id, $dt->id, 'defect type set';
+ $report->update({ defect_type_id => undef });
+ };
+
subtest "check can't set priority that isn't for a category" => sub {
$report->discard_changes;
$report->update({ category => 'Cows', response_priority_id => $rp->id });