diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 22 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/BathNES.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Hounslow.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/IsleOfWight.pm | 26 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Lincolnshire.pm | 28 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Peterborough.pm | 32 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/ConfirmOpen311.pm | 39 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/ConfirmValidation.pm | 2 | ||||
-rw-r--r-- | t/app/controller/auth_profile.t | 10 | ||||
-rw-r--r-- | t/cobrand/fixmystreet.t | 4 | ||||
-rw-r--r-- | t/cobrand/isleofwight.t | 12 | ||||
-rw-r--r-- | t/cobrand/westminster.t | 2 |
13 files changed, 100 insertions, 169 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 03623259c..907834b3a 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 ); } diff --git a/t/app/controller/auth_profile.t b/t/app/controller/auth_profile.t index 815098caa..2f0ef6a11 100644 --- a/t/app/controller/auth_profile.t +++ b/t/app/controller/auth_profile.t @@ -1,6 +1,10 @@ +use Test::MockModule; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +my $resolver = Test::MockModule->new('Email::Valid'); +$resolver->mock('address', sub { $_[1] }); + use t::Mock::Twilio; my $twilio = t::Mock::Twilio->new; @@ -10,10 +14,6 @@ my $test_email = 'test@example.com'; my $test_email2 = 'test@example.net'; my $test_password = 'foobar123'; -END { - done_testing(); -} - # get a sign in email and change password subtest "Test change password page" => sub { $mech->clear_emails_ok; @@ -449,3 +449,5 @@ subtest "Test two-factor authentication admin" => sub { $mech->submit_form_ok({ button => 'toggle_2fa' }, "submit 2FA deactivation"); $mech->content_contains('has been deactivated', "2FA deactivated"); }; + +done_testing(); diff --git a/t/cobrand/fixmystreet.t b/t/cobrand/fixmystreet.t index 6095aee2a..a4d00d032 100644 --- a/t/cobrand/fixmystreet.t +++ b/t/cobrand/fixmystreet.t @@ -1,9 +1,13 @@ use utf8; use FixMyStreet::Script::UpdateAllReports; +use Test::MockModule; use FixMyStreet::TestMech; my $mech = FixMyStreet::TestMech->new; +my $resolver = Test::MockModule->new('Email::Valid'); +$resolver->mock('address', sub { $_[1] }); + my $body = $mech->create_body_ok( 2514, 'Birmingham' ); my $contact = $mech->create_contact_ok( diff --git a/t/cobrand/isleofwight.t b/t/cobrand/isleofwight.t index fd08ce455..f945dc924 100644 --- a/t/cobrand/isleofwight.t +++ b/t/cobrand/isleofwight.t @@ -1,5 +1,6 @@ use CGI::Simple; use DateTime; +use Test::MockModule; use FixMyStreet::TestMech; use Open311; use Open311::GetServiceRequests; @@ -8,6 +9,16 @@ use Open311::PostServiceRequestUpdates; use FixMyStreet::Script::Alerts; use FixMyStreet::Script::Reports; +# disable info logs for this test run +FixMyStreet::App->log->disable('info'); +END { FixMyStreet::App->log->enable('info'); } + +my $cobrand = Test::MockModule->new('FixMyStreet::Cobrand::IsleOfWight'); +$cobrand->mock('lookup_site_code', sub { + my ($self, $row) = @_; + return "Road ID" if $row->latitude == 50.7108; +}); + ok( my $mech = FixMyStreet::TestMech->new, 'Created mech object' ); my $params = { @@ -290,6 +301,7 @@ subtest 'Check special Open311 request handling', sub { my $req = $test_data->{test_req_used}; my $c = CGI::Simple->new($req->content); is $c->param('attribute[urgent]'), undef, 'no urgent param sent'; + is $c->param('attribute[site_code]'), 'Road ID', 'road ID set'; $mech->email_count_is(1); my $email = $mech->get_email; diff --git a/t/cobrand/westminster.t b/t/cobrand/westminster.t index 84def0917..54de5a160 100644 --- a/t/cobrand/westminster.t +++ b/t/cobrand/westminster.t @@ -79,7 +79,7 @@ FixMyStreet::override_config { $mech->content_contains($comment3->text); }; - subtest 'Reports don’t show updates from fixmystreet.com cobrand' => sub { + subtest "Reports don't show updates from fixmystreet.com cobrand" => sub { $mech->get_ok('/report/' . $report->id); $mech->content_lacks($comment2->text); }; |