aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew-github@dracos.co.uk>2018-06-22 12:57:51 +0100
committerMatthew Somerville <matthew-github@dracos.co.uk>2018-06-22 14:27:49 +0100
commitb9ff1828d109befbe279698d7403889e9987c704 (patch)
tree140005cf2f927f473c1df7c7efac1d27241695c6
parentd268f042ce441485b3512308055f37bd08c63588 (diff)
Defect type changes must be after category change.
As with priorities, they depend upon the category and so must be looked up after that has been updated.
-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 });