diff options
author | Struan Donald <struan@exo.org.uk> | 2019-04-03 12:11:49 +0100 |
---|---|---|
committer | Struan Donald <struan@exo.org.uk> | 2019-04-09 09:54:47 +0100 |
commit | 0e46602ffb3fa6f1b86474449972bd7d5572af61 (patch) | |
tree | fb91f7b4867205505b21249f20fbf50b5a9e9a6a | |
parent | 15c5006fa25799cd65ee4edd032b49b90513c839 (diff) |
[Northamptonshire] restrict title to 120 characters
Prevent people from using very long titles.
Fixes mysociety/fixmystreet-commercial#1344
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Northamptonshire.pm | 8 | ||||
-rw-r--r-- | t/Mock/MapIt.pm | 1 | ||||
-rw-r--r-- | t/app/controller/report_new.t | 28 | ||||
-rw-r--r-- | templates/web/base/js/translation_strings.html | 5 | ||||
-rw-r--r-- | web/cobrands/fixmystreet-uk-councils/council_validation_rules.js | 6 |
5 files changed, 46 insertions, 2 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm index 945a1ac0d..683dc059c 100644 --- a/perllib/FixMyStreet/Cobrand/Northamptonshire.pm +++ b/perllib/FixMyStreet/Cobrand/Northamptonshire.pm @@ -94,4 +94,12 @@ sub open311_config { # sending updates not part of initial phase sub should_skip_sending_update { 1; } +sub report_validation { + my ($self, $report, $errors) = @_; + + if ( length( $report->title ) > 120 ) { + $errors->{title} = sprintf( _('Summaries are limited to %s characters in length. Please shorten your summary'), 120 ); + } +} + 1; diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index 11fa4200c..ea1f5b259 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -37,6 +37,7 @@ my @PLACES = ( [ 'LE15 0GJ', 52.670447, -0.727877, 2600, 'Rutland County Council', 'CTY'], [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], [ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ], + [ 'NN1 1NS', 52.236251, 0.892052, 2234, 'Northamptonshire County Council', 'CTY' ], [ '?', 50.78301, -0.646929 ], [ 'TA1 1QP', 51.023569, -3.099055, 2239, 'Somerset County Council', 'CTY', 2429, 'Taunton Deane Borough Council', 'DIS' ], [ 'GU51 4AE', 51.279456, -0.846216, 2333, 'Hart District Council', 'DIS', 2227, 'Hampshire County Council', 'CTY' ], diff --git a/t/app/controller/report_new.t b/t/app/controller/report_new.t index d9fae5fbc..af18c39b9 100644 --- a/t/app/controller/report_new.t +++ b/t/app/controller/report_new.t @@ -51,6 +51,7 @@ for my $body ( { area_id => 2232, name => 'Lincolnshire County Council' }, { area_id => 2237, name => 'Oxfordshire County Council' }, { area_id => 2600, name => 'Rutland County Council' }, + { area_id => 2234, name => 'Northamptonshire County Council' }, ) { my $body_obj = $mech->create_body_ok($body->{area_id}, $body->{name}); push @bodies, $body_obj; @@ -133,6 +134,11 @@ my $contact15 = $mech->create_contact_ok( category => 'Trees', email => 'trees-2600@example.com', ); +my $contact16 = $mech->create_contact_ok( + body_id => $body_ids{2234}, # Northamptonshire + category => 'Trees', + email => 'trees-2234@example.com', +); # test that the various bit of form get filled in and errors correctly # generated. @@ -614,6 +620,26 @@ foreach my $test ( changes => { }, errors => [ 'Please enter a subject', 'Please enter some details', 'Emails are limited to 50 characters in length.', 'Phone numbers are limited to 20 characters in length.', 'Names are limited to 50 characters in length.'], }, + { + msg => 'Northamptonshire validation', + pc => 'NN1 1NS', + fields => { + title => 'This is a very long title that should fail the validation as it is really much too long to pass the validation of 120 characters', + detail => '', + photo1 => '', + photo2 => '', + photo3 => '', + name => 'A User', + may_show_name => '1', + username => 'user@example.org', + phone => '', + category => 'Trees', + password_sign_in => '', + password_register => '', + }, + changes => { }, + errors => [ 'Summaries are limited to 120 characters in length. Please shorten your summary', 'Please enter some details'], + }, ) { subtest "check form errors where $test->{msg}" => sub { @@ -621,7 +647,7 @@ foreach my $test ( # submit initial pc form FixMyStreet::override_config { - ALLOWED_COBRANDS => [ { fixmystreet => '.' }, 'bromley', 'oxfordshire', 'rutland', 'lincolnshire', 'buckinghamshire' ], + ALLOWED_COBRANDS => [ { fixmystreet => '.' }, 'bromley', 'oxfordshire', 'rutland', 'lincolnshire', 'buckinghamshire', 'northamptonshire' ], MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->submit_form_ok( { with_fields => { pc => $test->{pc} } }, diff --git a/templates/web/base/js/translation_strings.html b/templates/web/base/js/translation_strings.html index 9747773d9..881f6ecb9 100644 --- a/templates/web/base/js/translation_strings.html +++ b/templates/web/base/js/translation_strings.html @@ -4,7 +4,10 @@ fixmystreet.password_minimum_length = [% c.cobrand.password_minimum_length %]; translation_strings = { update: '[% loc('Please enter a message') | replace("'", "\\'") %]', - title: '[% loc('Please enter a subject') | replace("'", "\\'") %]', + title: { + required: '[% loc('Please enter a subject') | replace("'", "\\'") %]', + maxlength: '[% loc('Summaries are limited to {0} characters in length. Please shorten your summary') | replace("'", "\\'") %]' + }, detail: { required: '[% loc('Please enter some details') | replace("'", "\\'") %]', maxlength: '[% loc('Reports are limited to {0} characters in length. Please shorten your report') | replace("'", "\\'") %]', diff --git a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js index 9f50f1055..ee3dfde88 100644 --- a/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js +++ b/web/cobrands/fixmystreet-uk-councils/council_validation_rules.js @@ -43,5 +43,11 @@ body_validation_rules = { email: { maxlength: 50 } + }, + 'Northamptonshire County Council': { + title: { + required: true, + maxlength: 120 + } } }; |