From 7990f0ffff5dff588ea554cfd911b3eec554de5e Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 4 Dec 2024 17:29:14 +0000 Subject: [PATCH] [Surrey] Add maximum detail length. --- perllib/FixMyStreet/Cobrand/Surrey.pm | 7 ++++++- t/Mock/MapIt.pm | 2 +- t/app/controller/report_new_errors.t | 21 ++++++++++++++++++++- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Surrey.pm b/perllib/FixMyStreet/Cobrand/Surrey.pm index 624a3273bbe..17d27abfeb0 100644 --- a/perllib/FixMyStreet/Cobrand/Surrey.pm +++ b/perllib/FixMyStreet/Cobrand/Surrey.pm @@ -134,7 +134,7 @@ sub reopening_disallowed { 1 } sub allow_anonymous_reports { 'button' } -=item * Do not allow email addresses in title or detail +=item * Do not allow email addresses in title or detail, with detail maximum length =back @@ -149,6 +149,11 @@ sub report_validation { $errors->{detail} = 'Please remove any email addresses and other personal information from your report'; } + my $max_report_length = 1000; + if ( length( $report->detail ) > $max_report_length ) { + $errors->{detail} = sprintf('Reports are limited to %s characters in length. Please shorten your report', $max_report_length ); + } + return $errors; } diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 1efc82eca88..8b12938b0fd 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -112,7 +112,7 @@ my @PLACES = ( [ '?', 51.558568, -0.207702, 2489, 'Barnet Borough Council', 'DIS' ], [ '?', 51.418776, 0.005357, 2492, 'Lewisham Borough Council', 'DIS' ], [ '?', 52.956196, -1.151204, 2412, 'Gedling Borough Council', 'DIS', 2236, 'Nottinghamshire County Council', 'CTY' ], - [ '?', 51.293415, -0.441269, 2242, 'Surrey County Council', 'DIS'], + [ 'KT11 1LZ', 51.293415, -0.441269, 2242, 'Surrey County Council', 'DIS'], ); sub dispatch_request { diff --git a/t/app/controller/report_new_errors.t b/t/app/controller/report_new_errors.t index ff29157bee2..a46629a987f 100644 --- a/t/app/controller/report_new_errors.t +++ b/t/app/controller/report_new_errors.t @@ -44,6 +44,7 @@ for my $body ( { area_id => 164186, name => 'Northamptonshire Highways', cobrand => 'northamptonshire' }, { area_id => 2566, name => 'Peterborough City Council', cobrand => 'peterborough' }, { area_id => 2508, name => 'Hackney Council', cobrand => 'hackney' }, + { area_id => 2242, name => 'Surrey Council', cobrand => 'surrey' }, ) { my $extra = { cobrand => $body->{cobrand} } if $body->{cobrand}; my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name}, $extra); @@ -86,6 +87,11 @@ $mech->create_contact_ok( category => 'Trees', email => 'trees-2247@example.com', ); +$mech->create_contact_ok( + body_id => $body_ids{2242}, # Surrey + category => 'Trees', + email => 'trees-2242@example.com', +); $mech->create_contact_ok( body_id => $body_ids{2600}, # Rutland category => 'Trees', @@ -393,6 +399,19 @@ foreach my $test ( }, errors => [ 'Please make sure you are not including an email address', ], }, + { + msg => 'Surrey long detail', + pc => 'KT11 1LZ', + fields => { + %shared, + detail => 'X' . 'x' x 1001, + name => 'Bob Example', + username_register => 'bob@example.com', + category => 'Trees', + }, + changes => { }, + errors => [ 'Please enter a subject', 'Reports are limited to 1000 characters in length. Please shorten your report' ], + }, { msg => 'Bromley long detail', pc => 'BR1 3UH', @@ -587,7 +606,7 @@ foreach my $test ( # submit initial pc form FixMyStreet::override_config { - ALLOWED_COBRANDS => [ { fixmystreet => '.' }, 'bromley', 'oxfordshire', 'rutland', 'lincolnshire', 'buckinghamshire', 'northamptonshire', 'peterborough', 'hackney' ], + ALLOWED_COBRANDS => [ { fixmystreet => '.' }, 'bromley', 'oxfordshire', 'rutland', 'lincolnshire', 'buckinghamshire', 'northamptonshire', 'peterborough', 'hackney', 'surrey' ], MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } },