aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Arter <davea@mysociety.org>2019-11-06 11:46:56 +0000
committerDave Arter <davea@mysociety.org>2019-12-09 12:50:07 +0000
commit9efd2981c85b3fae48118071e12058413f46a73c (patch)
tree9377238eeac76bd7853a851db44521f3f8c674eb
parent64d09262cabeac85704067d03a358b86265ef27b (diff)
[TfL] Set safety critical flag on reports
Adds a cobrand feature that can mark entire categories or just specific answers to extra questions as safety critical. When reports are made in those categories or with those answers, marks the report as safety critical.
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/TfL.pm28
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm9
-rw-r--r--t/cobrand/tfl.t174
4 files changed, 214 insertions, 0 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index 29ff4393f..854f6da89 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -30,6 +30,9 @@ sub report_validation {
sub report_new_munge_before_insert {
my ($self, $report) = @_;
+ # Make sure TfL reports are marked safety critical
+ $self->SUPER::report_new_munge_before_insert($report);
+
$report->subcategory($report->get_extra_field_value('service_sub_code'));
}
diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm
index ececa1184..846e1e776 100644
--- a/perllib/FixMyStreet/Cobrand/TfL.pm
+++ b/perllib/FixMyStreet/Cobrand/TfL.pm
@@ -160,4 +160,32 @@ sub update_email_shortlisted_user {
}
}
+sub report_new_munge_before_insert {
+ my ($self, $report) = @_;
+
+ # Sets the safety critical flag on this report according to category/extra
+ # fields selected.
+
+ my $safety_critical = 0;
+ my $categories = $self->feature('safety_critical_categories');
+ my $category = $categories->{$report->category};
+ if ( ref $category eq 'HASH' ) {
+ # report is safety critical if any of its field values match
+ # the critical values from the config
+ for my $code (keys %$category) {
+ my $value = $report->get_extra_field_value($code);
+ my %critical_values = map { $_ => 1 } @{ $category->{$code} };
+ $safety_critical ||= $critical_values{$value};
+ }
+ } elsif ($category) {
+ # the entire category is safety critical
+ $safety_critical = 1;
+ }
+
+ my $extra = $report->get_extra_fields;
+ @$extra = grep { $_->{name} ne 'safety_critical' } @$extra;
+ push @$extra, { name => 'safety_critical', value => $safety_critical ? 'yes' : 'no' };
+ $report->set_extra_fields(@$extra);
+}
+
1;
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index 83df590db..2054b5df6 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -413,4 +413,13 @@ sub category_extra_hidden {
return $self->SUPER::category_extra_hidden($meta);
}
+sub report_new_munge_before_insert {
+ my ($self, $report) = @_;
+
+ if ($report->to_body_named('TfL')) {
+ my $tfl = FixMyStreet::Cobrand->get_class_for_moniker('tfl')->new();
+ $tfl->report_new_munge_before_insert($report);
+ }
+}
+
1;
diff --git a/t/cobrand/tfl.t b/t/cobrand/tfl.t
index 1c3b7e25b..24305727b 100644
--- a/t/cobrand/tfl.t
+++ b/t/cobrand/tfl.t
@@ -35,6 +35,90 @@ my $contact2 = $mech->create_contact_ok(
category => 'Traffic lights',
email => 'trafficlights@example.com',
);
+$contact2->set_extra_fields({
+ code => "safety_critical",
+ description => "Safety critical",
+ automated => "hidden_field",
+ order => 1,
+ datatype => "singlevaluelist",
+ values => [
+ {
+ name => "Yes",
+ key => "yes"
+ },
+ {
+ name => "No",
+ key => "no"
+ }
+ ]
+});
+$contact2->update;
+my $contact3 = $mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Pothole',
+ email => 'pothole@example.com',
+);
+$contact3->set_extra_fields({
+ code => "safety_critical",
+ description => "Safety critical",
+ automated => "hidden_field",
+ order => 1,
+ datatype => "singlevaluelist",
+ values => [
+ {
+ name => "Yes",
+ key => "yes"
+ },
+ {
+ name => "No",
+ key => "no"
+ }
+ ]
+});
+$contact3->update;
+my $contact4 = $mech->create_contact_ok(
+ body_id => $body->id,
+ category => 'Flooding',
+ email => 'flooding@example.com',
+);
+$contact4->set_extra_fields(
+ {
+ code => "safety_critical",
+ description => "Safety critical",
+ automated => "hidden_field",
+ order => 1,
+ datatype => "singlevaluelist",
+ values => [
+ {
+ name => "Yes",
+ key => "yes"
+ },
+ {
+ name => "No",
+ key => "no"
+ }
+ ]
+ },
+ {
+ code => "location",
+ description => "Where is the flooding?",
+ variable => "true",
+ order => 1,
+ required => "true",
+ datatype => "singlevaluelist",
+ values => [
+ {
+ name => "Carriageway",
+ key => "carriageway"
+ },
+ {
+ name => "Footway",
+ key => "footway"
+ }
+ ]
+ }
+);
+$contact4->update;
FixMyStreet::override_config {
ALLOWED_COBRANDS => 'tfl',
@@ -200,6 +284,96 @@ subtest 'Bromley staff cannot access TfL admin' => sub {
};
FixMyStreet::override_config {
+ ALLOWED_COBRANDS => [ 'tfl', 'bromley', 'fixmystreet' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ COBRAND_FEATURES => {
+ internal_ips => { tfl => [ '127.0.0.1' ] },
+ safety_critical_categories => { tfl => {
+ Pothole => 1,
+ Flooding => {
+ location => [ "carriageway" ],
+ },
+ } },
+ },
+}, sub {
+
+for my $host ( 'tfl.fixmystreet.com', 'www.fixmystreet.com', 'bromley.fixmystreet.com' ) {
+ for my $test (
+ {
+ name => "test non-safety critical category",
+ safety_critical => 'no',
+ category => "Traffic lights"
+ },
+ {
+ name => "test safety critical category",
+ safety_critical => 'yes',
+ category => "Pothole"
+ },
+ {
+ name => "test category extra field - safety critical",
+ safety_critical => 'yes',
+ category => "Flooding",
+ extra_fields => {
+ location => "carriageway",
+ }
+ },
+ {
+ name => "test category extra field - non-safety critical",
+ safety_critical => 'no',
+ category => "Flooding",
+ extra_fields => {
+ location => "footway",
+ }
+ },
+ ) {
+ subtest $test->{name} . ' on ' . $host => sub {
+ $mech->log_in_ok( $user->email );
+ $mech->host($host);
+ $mech->get_ok('/around');
+ $mech->submit_form_ok( { with_fields => { pc => 'BR1 3UH', } }, "submit location" );
+ $mech->follow_link_ok( { text_regex => qr/skip this step/i, }, "follow 'skip this step' link" );
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ category => $test->{category}
+ },
+ button => 'submit_category_part_only',
+ }
+ );
+ $mech->submit_form_ok(
+ {
+ with_fields => {
+ title => 'Test Report',
+ detail => 'Test report details.',
+ may_show_name => '1',
+ category => $test->{category},
+ %{ $test->{extra_fields} || {} },
+ $host eq 'bromley.fixmystreet.com' ? (
+ fms_extra_title => 'DR',
+ first_name => "Joe",
+ last_name => "Bloggs",
+ ) : (
+ name => 'Joe Bloggs',
+ ),
+ }
+ },
+ "submit report form"
+ );
+
+ my $report = FixMyStreet::App->model('DB::Problem')->to_body( $body->id )->search(undef, {
+ order_by => { -desc => 'id' },
+ })->first;
+ ok $report, "Found the report";
+
+ is $report->get_extra_field_value('safety_critical'), $test->{safety_critical}, "safety critical flag set to " . $test->{safety_critical};
+
+ $mech->log_out_ok;
+ };
+ }
+}
+};
+
+FixMyStreet::override_config {
ALLOWED_COBRANDS => 'tfl',
MAPIT_URL => 'http://mapit.uk/',
COBRAND_FEATURES => { internal_ips => { tfl => [ '127.0.0.1' ] } },