aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md4
-rw-r--r--perllib/FixMyStreet/App/Controller/Report.pm25
-rw-r--r--t/app/controller/report_inspect.t46
-rw-r--r--web/cobrands/fixmystreet/staff.js7
4 files changed, 73 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9249149bd..1d070c62f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,10 @@
- Fix issue displaying admin timeline. #2159
- 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
+ - Admin improvements:
+ - Mandatory defect type selection if defect raised.
- 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 f5d7db069..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,9 +455,22 @@ 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)
- if ($c->get_param('priority') && ($permissions->{report_inspect} || $permissions->{report_edit_priority})) {
- $problem->response_priority( $problem->response_priorities->find({ id => $c->get_param('priority') }) );
+ # 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') }) );
+ } else {
+ $problem->response_priority(undef);
+ }
+ }
+
+ 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) {
diff --git a/t/app/controller/report_inspect.t b/t/app/controller/report_inspect.t
index 6a001225d..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 });
@@ -414,6 +440,26 @@ FixMyStreet::override_config {
is $report->response_priority, undef, 'response priority set';
};
+ subtest "check can unset priority" => sub {
+ $report->discard_changes;
+ $report->update({ category => 'Cows', response_priority_id => $rp->id });
+ $report->discard_changes;
+ is $report->response_priority->id, $rp->id, 'response priority set';
+ $user->user_body_permissions->delete;
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_category' });
+ $user->user_body_permissions->create({ body => $oxon, permission_type => 'report_edit_priority' });
+ $mech->get_ok("/report/$report_id");
+ $mech->submit_form_ok({
+ button => 'save',
+ with_fields => {
+ priority => "",
+ }
+ });
+
+ $report->discard_changes;
+ is $report->response_priority, undef, 'response priority unset';
+ };
+
subtest "check nearest address display" => sub {
$mech->get_ok("/report/$report_id");
$mech->content_lacks('Nearest calculated address', 'No address displayed');
diff --git a/web/cobrands/fixmystreet/staff.js b/web/cobrands/fixmystreet/staff.js
index 824e8fa0b..2f2de7b20 100644
--- a/web/cobrands/fixmystreet/staff.js
+++ b/web/cobrands/fixmystreet/staff.js
@@ -84,11 +84,18 @@ $.extend(fixmystreet.set_up, {
if ($(this).val() !== "action scheduled") {
$("#js-inspect-action-scheduled").addClass("hidden");
$('#raise_defect_yes').prop('required', false);
+ $('#defect_type').prop('required', false);
} else {
$("#js-inspect-action-scheduled").removeClass("hidden");
$('#raise_defect_yes').prop('required', true);
+ var dt_required = $('#defect_type')[0].length > 1 && $('input[name=raise_defect]:checked').val();
+ $('#defect_type').prop('required', dt_required ? true : false);
}
});
+ $('input[name=raise_defect]').change(function() {
+ var dt_required = $('#defect_type')[0].length > 1 && this.value;
+ $('#defect_type').prop('required', dt_required ? true : false);
+ });
},
list_item_actions: function() {