aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md1
-rw-r--r--perllib/FixMyStreet/SendReport.pm17
-rw-r--r--perllib/FixMyStreet/SendReport/Email.pm5
-rw-r--r--perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm6
-rw-r--r--perllib/FixMyStreet/SendReport/Open311.pm8
-rw-r--r--perllib/FixMyStreet/SendReport/Zurich.pm5
-rw-r--r--t/app/sendreport/email/highways.t1
-rw-r--r--t/app/sendreport/email/tfl.t1
-rw-r--r--t/sendreport/open311.t22
-rw-r--r--templates/web/bromley/before_wrapper.html10
-rw-r--r--templates/web/bromley/report/new/top_message.html1
-rw-r--r--web/cobrands/bromley/base.scss4
12 files changed, 62 insertions, 19 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 48098f0d4..4b94191ac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@
- Don't include private reports when searching by ref from front page.
- Set fixmystreet.bodies sooner client-side, for two-tier locations.
- Fix front-end testing script when run with Vagrant.
+ - Handle missing category when sending open311 reports #2502
- Development improvements:
- Upgrade the underlying framework and a number of other packages.
- Add feature cobrand helper function.
diff --git a/perllib/FixMyStreet/SendReport.pm b/perllib/FixMyStreet/SendReport.pm
index db95850e6..b869299a2 100644
--- a/perllib/FixMyStreet/SendReport.pm
+++ b/perllib/FixMyStreet/SendReport.pm
@@ -60,4 +60,21 @@ sub add_body {
$self->body_config->{ $body->id } = $config;
}
+sub fetch_category {
+ my ($self, $body, $row, $category_override) = @_;
+
+ my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( {
+ body_id => $body->id,
+ category => $category_override || $row->category,
+ } );
+
+ unless ($contact) {
+ my $error = "Category " . $row->category . " does not exist for body " . $body->id . " and report " . $row->id . "\n";
+ $self->error( "Failed to send over Open311\n" ) unless $self->error;
+ $self->error( $self->error . "\n" . $error );
+ }
+
+ return $contact;
+}
+
1;
diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm
index 679530507..6cd9afccd 100644
--- a/perllib/FixMyStreet/SendReport/Email.pm
+++ b/perllib/FixMyStreet/SendReport/Email.pm
@@ -12,10 +12,7 @@ sub build_recipient_list {
my $all_confirmed = 1;
foreach my $body ( @{ $self->bodies } ) {
- my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( {
- body_id => $body->id,
- category => $row->category
- } );
+ my $contact = $self->fetch_category($body, $row) or next;
my ($body_email, $state, $note) = ( $contact->email, $contact->state, $contact->note );
diff --git a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm
index cf778c549..1ae938317 100644
--- a/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm
+++ b/perllib/FixMyStreet/SendReport/Email/SingleBodyOnly.pm
@@ -15,11 +15,7 @@ sub build_recipient_list {
my $body = $self->bodies->[0];
# We don't care what the category was, look up the relevant contact
- my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find({
- body_id => $body->id,
- category => $self->contact,
- });
- return unless $contact;
+ my $contact = $self->fetch_category($body, $row, $self->contact) or return;
@{$self->to} = map { [ $_, $body->name ] } split /,/, $contact->email;
return 1;
diff --git a/perllib/FixMyStreet/SendReport/Open311.pm b/perllib/FixMyStreet/SendReport/Open311.pm
index 8a6b992fd..45b056dc2 100644
--- a/perllib/FixMyStreet/SendReport/Open311.pm
+++ b/perllib/FixMyStreet/SendReport/Open311.pm
@@ -36,13 +36,9 @@ sub send {
my $cobrand = $body->get_cobrand_handler || $row->get_cobrand_logged;
$cobrand->call_hook(open311_config => $row, $h, \%open311_params);
- # Try and fill in some ones that we've been asked for, but not asked the user for
-
- my $contact = $row->result_source->schema->resultset("Contact")->not_deleted->find( {
- body_id => $body->id,
- category => $row->category
- } );
+ my $contact = $self->fetch_category($body, $row) or next;
+ # Try and fill in some ones that we've been asked for, but not asked the user for
my $extra = $row->get_extra_fields();
my $id_field = $contact->id_field;
diff --git a/perllib/FixMyStreet/SendReport/Zurich.pm b/perllib/FixMyStreet/SendReport/Zurich.pm
index 59adfd688..7416c64f9 100644
--- a/perllib/FixMyStreet/SendReport/Zurich.pm
+++ b/perllib/FixMyStreet/SendReport/Zurich.pm
@@ -29,10 +29,7 @@ sub build_recipient_list {
my $parent = $body->parent;
if ($parent && !$parent->parent) {
# Division, might have an individual contact email address
- my $contact = $row->result_source->schema->resultset("Contact")->find( {
- body_id => $body->id,
- category => $row->category
- } );
+ my $contact = $self->fetch_category($body, $row);
$body_email = $contact->email if $contact && $contact->email;
}
diff --git a/t/app/sendreport/email/highways.t b/t/app/sendreport/email/highways.t
index f53062336..452dda822 100644
--- a/t/app/sendreport/email/highways.t
+++ b/t/app/sendreport/email/highways.t
@@ -11,6 +11,7 @@ $mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id
$mech->create_contact_ok(email => 'highways@example.com', body_id => $highways->id, category => 'Pothole');
my $row = FixMyStreet::DB->resultset('Problem')->new( {
+ id => 123,
bodies_str => '1000',
category => 'Pothole',
cobrand => '',
diff --git a/t/app/sendreport/email/tfl.t b/t/app/sendreport/email/tfl.t
index 0322de551..8c6eeffa0 100644
--- a/t/app/sendreport/email/tfl.t
+++ b/t/app/sendreport/email/tfl.t
@@ -11,6 +11,7 @@ $mech->create_contact_ok(email => 'council@example.com', body_id => $bromley->id
$mech->create_contact_ok(email => 'tfl@example.com', body_id => $tfl->id, category => 'Traffic lights');
my $row = FixMyStreet::DB->resultset('Problem')->new( {
+ id => 456,
bodies_str => '1000',
category => 'Faulty street light',
cobrand => '',
diff --git a/t/sendreport/open311.t b/t/sendreport/open311.t
index e68a0aa3c..382df39f0 100644
--- a/t/sendreport/open311.t
+++ b/t/sendreport/open311.t
@@ -11,6 +11,7 @@ package main;
use CGI::Simple;
use Path::Tiny;
+use Test::Warn;
use FixMyStreet::Script::Reports;
use FixMyStreet::TestMech;
my $mech = FixMyStreet::TestMech->new;
@@ -133,4 +134,25 @@ subtest 'test sending multiple photos', sub {
], 'Multiple photos in media_url';
};
+my ($bad_category_report) = $mech->create_problems_for_body( 1, $body->id, 'Test', {
+ cobrand => 'fixmystreet',
+ category => 'Flytipping',
+ user => $user,
+});
+
+subtest 'test handles bad category', sub {
+ $body->update( { send_method => 'Open311', endpoint => 'http://endpoint.example.com', jurisdiction => 'FMS', api_key => 'test' } );
+ my $test_data;
+ FixMyStreet::override_config {
+ STAGING_FLAGS => { send_reports => 1 },
+ ALLOWED_COBRANDS => [ 'fixmystreet' ],
+ MAPIT_URL => 'http://mapit.uk/',
+ }, sub {
+ $test_data = FixMyStreet::Script::Reports::send();
+ };
+ $bad_category_report->discard_changes;
+ ok !$bad_category_report->whensent, 'Report not marked as sent';
+ like $bad_category_report->send_fail_reason, qr/Category Flytipping does not exist for body/, 'failure message set';
+};
+
done_testing();
diff --git a/templates/web/bromley/before_wrapper.html b/templates/web/bromley/before_wrapper.html
new file mode 100644
index 000000000..f88e46d8c
--- /dev/null
+++ b/templates/web/bromley/before_wrapper.html
@@ -0,0 +1,10 @@
+<div class="top_banner">
+ <p>
+ Whilst reports will be actioned in the usual way, please be aware that
+ there will be a temporary slightly longer response of 1 working day as
+ a back office software upgrade is taking place.
+ </p>
+ <p>
+ <a href="https://www.bromley.gov.uk/info/200119/customer_services/1022/contact_us_by_telephone">Please report urgent matters by calling us</a>.
+ </p>
+</div>
diff --git a/templates/web/bromley/report/new/top_message.html b/templates/web/bromley/report/new/top_message.html
new file mode 100644
index 000000000..04e265adc
--- /dev/null
+++ b/templates/web/bromley/report/new/top_message.html
@@ -0,0 +1 @@
+[% INCLUDE 'before_wrapper.html' %] \ No newline at end of file
diff --git a/web/cobrands/bromley/base.scss b/web/cobrands/bromley/base.scss
index 9435aa35d..768507173 100644
--- a/web/cobrands/bromley/base.scss
+++ b/web/cobrands/bromley/base.scss
@@ -371,6 +371,10 @@ body.mappage {
}
}
+body.mappage > .top_banner {
+ display: none;
+}
+
// Bromley's footer
.site-footer {
width: 100%;