aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Somerville <matthew@mysociety.org>2019-10-21 13:38:01 +0100
committerMatthew Somerville <matthew@mysociety.org>2019-10-28 11:35:20 +0000
commit1022f0672adfaaab85e3e2d2ca1adddc6ea706dd (patch)
tree28e0ac2a54be7f39007b38b4bf35d535b8a2ff5a
parent64687c93beffc07d0fcb10459e5a898544bf8aae (diff)
[UK] Factor out Confirm open311_config to role.
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm30
-rw-r--r--perllib/FixMyStreet/Cobrand/Buckinghamshire.pm28
-rw-r--r--perllib/FixMyStreet/Cobrand/Hounslow.pm32
-rw-r--r--perllib/FixMyStreet/Cobrand/IsleOfWight.pm26
-rw-r--r--perllib/FixMyStreet/Cobrand/Lincolnshire.pm28
-rw-r--r--perllib/FixMyStreet/Cobrand/Peterborough.pm32
-rw-r--r--perllib/FixMyStreet/Roles/ConfirmOpen311.pm39
7 files changed, 58 insertions, 157 deletions
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
index 6de28bca8..743de74d5 100644
--- a/perllib/FixMyStreet/Cobrand/BathNES.pm
+++ b/perllib/FixMyStreet/Cobrand/BathNES.pm
@@ -6,6 +6,7 @@ use warnings;
use Moo;
with 'FixMyStreet::Roles::ConfirmValidation';
+with 'FixMyStreet::Roles::ConfirmOpen311';
use LWP::Simple;
use URI;
@@ -97,33 +98,6 @@ sub category_extra_hidden {
return $self->SUPER::category_extra_hidden($meta);
}
-sub open311_config {
- my ($self, $row, $h, $params) = @_;
-
- my $extra = $row->get_extra_fields;
- push @$extra,
- { name => 'report_url',
- value => $h->{url} },
- { name => 'title',
- value => $row->title },
- { name => 'description',
- value => $row->detail };
-
- # Reports made via FMS.com or the app probably won't have a USRN
- # value because we don't display the adopted highways layer on those
- # frontends. Instead we'll look up the closest asset from the WFS
- # service at the point we're sending the report over Open311.
- if (!$row->get_extra_field_value('site_code')) {
- if (my $usrn = $self->lookup_usrn($row)) {
- push @$extra,
- { name => 'site_code',
- value => $usrn };
- }
- }
-
- $row->set_extra_fields(@$extra);
-}
-
sub available_permissions {
my $self = shift;
@@ -137,7 +111,7 @@ sub available_permissions {
sub report_sent_confirmation_email { 'id' }
-sub lookup_usrn {
+sub lookup_site_code {
my $self = shift;
my $row = shift;
diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
index e210e7d09..b13f4eed1 100644
--- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use Moo;
+with 'FixMyStreet::Roles::ConfirmOpen311';
with 'FixMyStreet::Roles::ConfirmValidation';
sub council_area_id { return 2217; }
@@ -43,33 +44,6 @@ sub send_questionnaires {
return 0;
}
-sub open311_config {
- my ($self, $row, $h, $params) = @_;
-
- my $extra = $row->get_extra_fields;
- push @$extra,
- { name => 'report_url',
- value => $h->{url} },
- { name => 'title',
- value => $row->title },
- { name => 'description',
- value => $row->detail };
-
- # Reports made via FMS.com or the app probably won't have a site code
- # value because we don't display the adopted highways layer on those
- # frontends. Instead we'll look up the closest asset from the WFS
- # service at the point we're sending the report over Open311.
- if (!$row->get_extra_field_value('site_code')) {
- if (my $site_code = $self->lookup_site_code($row)) {
- push @$extra,
- { name => 'site_code',
- value => $site_code };
- }
- }
-
- $row->set_extra_fields(@$extra);
-}
-
sub open311_pre_send {
my ($self, $row, $open311) = @_;
diff --git a/perllib/FixMyStreet/Cobrand/Hounslow.pm b/perllib/FixMyStreet/Cobrand/Hounslow.pm
index 2d5c2bf0f..ab131cf84 100644
--- a/perllib/FixMyStreet/Cobrand/Hounslow.pm
+++ b/perllib/FixMyStreet/Cobrand/Hounslow.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use Moo;
+with 'FixMyStreet::Roles::ConfirmOpen311';
with 'FixMyStreet::Roles::ConfirmValidation';
sub council_area_id { 2483 }
@@ -89,35 +90,12 @@ sub open311_post_send {
}
}
-sub open311_config {
- my ($self, $row, $h, $params) = @_;
-
- my $extra = $row->get_extra_fields;
- push @$extra,
- { name => 'report_url',
- value => $h->{url} },
- { name => 'title',
- value => $row->title },
- { name => 'description',
- value => $row->detail };
-
- # Reports made via FMS.com or the app probably won't have a site code
- # value because we don't display the adopted highways layer on those
- # frontends. Instead we'll look up the closest asset from the WFS
- # service at the point we're sending the report over Open311.
- if (!$row->get_extra_field_value('site_code')) {
- if (my $site_code = $self->lookup_site_code($row)) {
- push @$extra,
- { name => 'site_code',
- value => $site_code };
- }
- }
+around 'open311_config' => sub {
+ my ($orig, $self, $row, $h, $params) = @_;
- $row->set_extra_fields(@$extra);
-
- $params->{multi_photos} = 1;
$params->{upload_files} = 1;
-}
+ $self->$orig($row, $h, $params);
+};
sub open311_munge_update_params {
my ($self, $params, $comment, $body) = @_;
diff --git a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
index 26e3ba474..83431c532 100644
--- a/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
+++ b/perllib/FixMyStreet/Cobrand/IsleOfWight.pm
@@ -4,6 +4,9 @@ use parent 'FixMyStreet::Cobrand::Whitelabel';
use strict;
use warnings;
+use Moo;
+with 'FixMyStreet::Roles::ConfirmOpen311';
+
sub council_area_id { 2636 }
sub council_area { 'Isle of Wight' }
sub council_name { 'Island Roads' }
@@ -78,29 +81,6 @@ sub open311_pre_send {
}
}
-sub open311_config {
- my ($self, $row, $h, $params) = @_;
-
- my $extra = $row->get_extra_fields;
- push @$extra,
- { name => 'report_url',
- value => $h->{url} },
- { name => 'title',
- value => $row->title },
- { name => 'description',
- value => $row->detail };
-
- if (!$row->get_extra_field_value('site_code')) {
- if (my $site_code = $self->lookup_site_code($row)) {
- push @$extra,
- { name => 'site_code',
- value => $site_code };
- }
- }
-
- $row->set_extra_fields(@$extra);
-}
-
# Make sure fetched report description isn't shown.
sub filter_report_description { "" }
diff --git a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm
index ca88f6b8e..eaed35118 100644
--- a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm
@@ -10,6 +10,7 @@ use Try::Tiny;
use JSON::MaybeXS;
use Moo;
+with 'FixMyStreet::Roles::ConfirmOpen311';
with 'FixMyStreet::Roles::ConfirmValidation';
sub council_area_id { return 2232; }
@@ -41,33 +42,6 @@ sub disambiguate_location {
}
-sub open311_config {
- my ($self, $row, $h, $params) = @_;
-
- my $extra = $row->get_extra_fields;
- push @$extra,
- { name => 'report_url',
- value => $h->{url} },
- { name => 'title',
- value => $row->title },
- { name => 'description',
- value => $row->detail };
-
- # Reports made via FMS.com or the app probably won't have a site code
- # value because we don't display the adopted highways layer on those
- # frontends. Instead we'll look up the closest asset from the WFS
- # service at the point we're sending the report over Open311.
- if (!$row->get_extra_field_value('site_code')) {
- if (my $site_code = $self->lookup_site_code($row)) {
- push @$extra,
- { name => 'site_code',
- value => $site_code };
- }
- }
-
- $row->set_extra_fields(@$extra);
-}
-
sub lookup_site_code_config { {
buffer => 200, # metres
url => "https://tilma.mysociety.org/mapserver/lincs",
diff --git a/perllib/FixMyStreet/Cobrand/Peterborough.pm b/perllib/FixMyStreet/Cobrand/Peterborough.pm
index 9aa807cda..dd9bb0670 100644
--- a/perllib/FixMyStreet/Cobrand/Peterborough.pm
+++ b/perllib/FixMyStreet/Cobrand/Peterborough.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use Moo;
+with 'FixMyStreet::Roles::ConfirmOpen311';
with 'FixMyStreet::Roles::ConfirmValidation';
sub council_area_id { 2566 }
@@ -34,35 +35,16 @@ sub geocoder_munge_results {
sub admin_user_domain { "peterborough.gov.uk" }
-sub open311_config {
- my ($self, $row, $h, $params) = @_;
-
- my $extra = $row->get_extra_fields;
- push @$extra,
- { name => 'report_url',
- value => $h->{url} },
- { name => 'title',
- value => $row->title },
- { name => 'description',
- value => $row->detail };
+around 'open311_config' => sub {
+ my ($orig, $self, $row, $h, $params) = @_;
# remove the emergency category which is informational only
+ my $extra = $row->get_extra_fields;
@$extra = grep { $_->{name} ne 'emergency' } @$extra;
-
- # Reports made via FMS.com or the app probably won't have a site code
- # value because we don't display the adopted highways layer on those
- # frontends. Instead we'll look up the closest asset from the WFS
- # service at the point we're sending the report over Open311.
- if (!$row->get_extra_field_value('site_code')) {
- if (my $site_code = $self->lookup_site_code($row)) {
- push @$extra,
- { name => 'site_code',
- value => $site_code };
- }
- }
-
$row->set_extra_fields(@$extra);
-}
+
+ $self->$orig($row, $h, $params);
+};
sub lookup_site_code_config { {
buffer => 50, # metres
diff --git a/perllib/FixMyStreet/Roles/ConfirmOpen311.pm b/perllib/FixMyStreet/Roles/ConfirmOpen311.pm
new file mode 100644
index 000000000..b9e424d4f
--- /dev/null
+++ b/perllib/FixMyStreet/Roles/ConfirmOpen311.pm
@@ -0,0 +1,39 @@
+package FixMyStreet::Roles::ConfirmOpen311;
+use Moo::Role;
+
+=head1 NAME
+
+FixMyStreet::Roles::ConfirmOpen311 - role for adding various Open311 things specific to Confirm
+
+=cut
+
+sub open311_config {
+ my ($self, $row, $h, $params) = @_;
+
+ $params->{multi_photos} = 1;
+
+ my $extra = $row->get_extra_fields;
+ push @$extra,
+ { name => 'report_url',
+ value => $h->{url} },
+ { name => 'title',
+ value => $row->title },
+ { name => 'description',
+ value => $row->detail };
+
+ # Reports made via FMS.com or the app probably won't have a USRN
+ # value because we don't display the adopted highways layer on those
+ # frontends. Instead we'll look up the closest asset from the WFS
+ # service at the point we're sending the report over Open311.
+ if (!$row->get_extra_field_value('site_code')) {
+ if (my $site_code = $self->lookup_site_code($row)) {
+ push @$extra,
+ { name => 'site_code',
+ value => $site_code };
+ }
+ }
+
+ $row->set_extra_fields(@$extra);
+}
+
+1;