diff options
Diffstat (limited to 'perllib')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Bromley.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Lincolnshire.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Rutland.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/UK.pm | 10 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/ConfirmValidation.pm | 39 |
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; |