aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/FixMyStreet
diff options
context:
space:
mode:
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r--perllib/FixMyStreet/App/Controller/Report/New.pm22
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm32
-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
-rw-r--r--perllib/FixMyStreet/Roles/ConfirmValidation.pm2
9 files changed, 77 insertions, 164 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm
index cac50e34d..612c76c0c 100644
--- a/perllib/FixMyStreet/App/Controller/Report/New.pm
+++ b/perllib/FixMyStreet/App/Controller/Report/New.pm
@@ -1699,12 +1699,24 @@ sub generate_category_extra_json : Private {
my $false = JSON->false;
my @fields = map {
- {
- %$_,
- required => ($_->{required} || '') eq "true" ? $true : $false,
- variable => ($_->{variable} || '') eq "true" ? $true : $false,
- order => int($_->{order} || 0),
+ my %data = %$_;
+
+ # Mobile app still looks in datatype_description
+ if (($_->{variable} || '') eq 'true' && @{$_->{values} || []}) {
+ foreach my $opt (@{$_->{values}}) {
+ if ($opt->{disable}) {
+ my $message = $opt->{disable_message} || $_->{datatype_description};
+ $data{datatype_description} = $message;
+ }
+ }
}
+
+ # Remove unneeded
+ delete $data{$_} for qw(datatype protected variable order disable_form);
+ delete $data{datatype_description} unless $data{datatype_description};
+
+ $data{required} = ($_->{required} || '') eq "true" ? $true : $false;
+ \%data;
} @{ $c->stash->{category_extras}->{$c->stash->{category}} };
return \@fields;
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
index 6de28bca8..dd1b93764 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;
@@ -34,7 +35,7 @@ sub contact_extra_fields_validation {
return unless $contact->get_extra_metadata('display_name');
my @contacts = $contact->body->contacts->not_deleted->search({ id => { '!=', $contact->id } });
- my %display_names = map { $_->get_extra_metadata('display_name') => 1 } @contacts;
+ my %display_names = map { ($_->get_extra_metadata('display_name') || '') => 1 } @contacts;
if ($display_names{$contact->get_extra_metadata('display_name')}) {
$errors->{display_name} = 'That display name is already in use';
}
@@ -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;
diff --git a/perllib/FixMyStreet/Roles/ConfirmValidation.pm b/perllib/FixMyStreet/Roles/ConfirmValidation.pm
index 776230287..6474c94d1 100644
--- a/perllib/FixMyStreet/Roles/ConfirmValidation.pm
+++ b/perllib/FixMyStreet/Roles/ConfirmValidation.pm
@@ -24,7 +24,7 @@ sub report_validation {
$errors->{name} = sprintf( _('Names are limited to %d characters in length.'), 50 );
}
- if ( length( $report->user->phone ) > 20 ) {
+ if ( $report->user->phone && length( $report->user->phone ) > 20 ) {
$errors->{phone} = sprintf( _('Phone numbers are limited to %s characters in length.'), 20 );
}