aboutsummaryrefslogtreecommitdiffstats
path: root/perllib
diff options
context:
space:
mode:
authorStruan Donald <struan@exo.org.uk>2018-10-18 14:24:31 +0100
committerStruan Donald <struan@exo.org.uk>2018-11-26 09:43:10 +0000
commitcd34f8336f9fe5b3f334d350027948dbddc04345 (patch)
tree78d0bda1681fd670d9e63971ee917b06ab069152 /perllib
parentd191b211cc25c60d2a1464711ff4212f4d4a5e6e (diff)
[UK] server side cobrand specific validation
`report_check_for_errors` now fetches the cobrand for the current report and, if present, runs `report_validation` method from cobrand over the report.
Diffstat (limited to 'perllib')
-rw-r--r--perllib/FixMyStreet/Cobrand/BathNES.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/Bromley.pm10
-rw-r--r--perllib/FixMyStreet/Cobrand/Buckinghamshire.pm4
-rw-r--r--perllib/FixMyStreet/Cobrand/Lincolnshire.pm3
-rw-r--r--perllib/FixMyStreet/Cobrand/Oxfordshire.pm10
-rw-r--r--perllib/FixMyStreet/Cobrand/Rutland.pm10
-rw-r--r--perllib/FixMyStreet/Cobrand/UK.pm10
-rw-r--r--perllib/FixMyStreet/Roles/ConfirmValidation.pm39
8 files changed, 82 insertions, 7 deletions
diff --git a/perllib/FixMyStreet/Cobrand/BathNES.pm b/perllib/FixMyStreet/Cobrand/BathNES.pm
index 187c2afbb..025648591 100644
--- a/perllib/FixMyStreet/Cobrand/BathNES.pm
+++ b/perllib/FixMyStreet/Cobrand/BathNES.pm
@@ -4,6 +4,9 @@ use parent 'FixMyStreet::Cobrand::Whitelabel';
use strict;
use warnings;
+use Moo;
+with 'FixMyStreet::Roles::ConfirmValidation';
+
use LWP::Simple;
use URI;
use Try::Tiny;
diff --git a/perllib/FixMyStreet/Cobrand/Bromley.pm b/perllib/FixMyStreet/Cobrand/Bromley.pm
index 53fb9010c..11c685c91 100644
--- a/perllib/FixMyStreet/Cobrand/Bromley.pm
+++ b/perllib/FixMyStreet/Cobrand/Bromley.pm
@@ -10,6 +10,16 @@ sub council_area { return 'Bromley'; }
sub council_name { return 'Bromley Council'; }
sub council_url { return 'bromley'; }
+sub report_validation {
+ my ($self, $report, $errors) = @_;
+
+ if ( length( $report->detail ) > 1750 ) {
+ $errors->{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1750 );
+ }
+
+ return $errors;
+}
+
sub base_url {
my $self = shift;
return $self->next::method() if FixMyStreet->config('STAGING_SITE');
diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
index fb074da85..1b437b2c5 100644
--- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm
@@ -4,11 +4,15 @@ use parent 'FixMyStreet::Cobrand::UKCouncils';
use strict;
use warnings;
+use Moo;
+with 'FixMyStreet::Roles::ConfirmValidation';
+
sub council_area_id { return 2217; }
sub council_area { return 'Buckinghamshire'; }
sub council_name { return 'Buckinghamshire County Council'; }
sub council_url { return 'buckinghamshire'; }
+
sub example_places {
return ( 'HP19 7QF', "Walton Road" );
}
diff --git a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm
index 431314333..a4cee8a03 100644
--- a/perllib/FixMyStreet/Cobrand/Lincolnshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Lincolnshire.pm
@@ -9,6 +9,9 @@ use URI;
use Try::Tiny;
use JSON::MaybeXS;
+use Moo;
+with 'FixMyStreet::Roles::ConfirmValidation';
+
sub council_area_id { return 2232; }
sub council_area { return 'Lincolnshire'; }
sub council_name { return 'Lincolnshire County Council'; }
diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
index 4d627c756..9c1e541d4 100644
--- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
+++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm
@@ -10,6 +10,16 @@ sub council_name { return 'Oxfordshire County Council'; }
sub council_url { return 'oxfordshire'; }
sub is_two_tier { return 1; }
+sub report_validation {
+ my ($self, $report, $errors) = @_;
+
+ if ( length( $report->detail ) > 1700 ) {
+ $errors->{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 );
+ }
+
+ return $errors;
+}
+
sub is_council_with_case_management {
# XXX Change this to return 1 when OCC FMSfC goes live.
return FixMyStreet->config('STAGING_SITE');
diff --git a/perllib/FixMyStreet/Cobrand/Rutland.pm b/perllib/FixMyStreet/Cobrand/Rutland.pm
index 6993b0964..af635ac59 100644
--- a/perllib/FixMyStreet/Cobrand/Rutland.pm
+++ b/perllib/FixMyStreet/Cobrand/Rutland.pm
@@ -9,6 +9,16 @@ sub council_area { return 'Rutland'; }
sub council_name { return 'Rutland County Council'; }
sub council_url { return 'rutland'; }
+sub report_validation {
+ my ($self, $report, $errors) = @_;
+
+ if ( length( $report->name ) > 40 ) {
+ $errors->{name} = sprintf( _('Names are limited to %d characters in length.'), 40 );
+ }
+
+ return $errors;
+}
+
sub open311_config {
my ($self, $row, $h, $params) = @_;
diff --git a/perllib/FixMyStreet/Cobrand/UK.pm b/perllib/FixMyStreet/Cobrand/UK.pm
index ebedf8711..1202d48a4 100644
--- a/perllib/FixMyStreet/Cobrand/UK.pm
+++ b/perllib/FixMyStreet/Cobrand/UK.pm
@@ -328,13 +328,9 @@ sub report_check_for_errors {
);
}
- if ( $report->bodies_str && $report->detail ) {
- # Custom character limit:
- if ( $report->to_body_named('Bromley') && length($report->detail) > 1750 ) {
- $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1750 );
- } elsif ( $report->to_body_named('Oxfordshire') && length($report->detail) > 1700 ) {
- $errors{detail} = sprintf( _('Reports are limited to %s characters in length. Please shorten your report'), 1700 );
- }
+ my $cobrand = $self->get_body_handler_for_problem($report);
+ if ( $cobrand->can('report_validation') ) {
+ $cobrand->report_validation( $report, \%errors );
}
return %errors;
diff --git a/perllib/FixMyStreet/Roles/ConfirmValidation.pm b/perllib/FixMyStreet/Roles/ConfirmValidation.pm
new file mode 100644
index 000000000..5d407af6d
--- /dev/null
+++ b/perllib/FixMyStreet/Roles/ConfirmValidation.pm
@@ -0,0 +1,39 @@
+package FixMyStreet::Roles::ConfirmValidation;
+use Moo::Role;
+
+=head1 NAME
+
+FixMyStreet::Roles::ConfirmValidation - role for adding standard confirm validation
+
+=head1 SYNOPSIS
+
+This is applied to a Cobrand class to add validation of reports using standard
+Confirm field lengths.
+
+ use Moo;
+ with 'FixMyStreet::Roles::ConfirmValidation';
+
+=cut
+
+has max_report_length => ( is => 'ro', default => 2000 );
+
+sub report_validation {
+ my ($self, $report, $errors) = @_;
+
+ if ( length( $report->name ) > 50 ) {
+ $errors->{name} = sprintf( _('Names are limited to %d characters in length.'), 50 );
+ }
+
+ if ( length( $report->user->phone ) > 20 ) {
+ $errors->{phone} = sprintf( _('Phone numbers are limited to %s characters in length.'), 20 );
+ }
+
+ if ( length( $report->detail ) > $self->max_report_length ) {
+ $errors->{detail} = sprintf( _('Reports are limited to %s characters in
+ length. Please shorten your report'), $self->max_report_length );
+ }
+
+ return $errors;
+}
+
+1;