diff options
author | Chris Mytton <self@hecticjeff.net> | 2013-10-21 18:29:58 +0100 |
---|---|---|
committer | Chris Mytton <self@hecticjeff.net> | 2013-10-21 18:29:58 +0100 |
commit | 47cbcc8b99766bbbfa4a3348868c4f61ede0cdb1 (patch) | |
tree | b04cff7879f3d4211136e4ae087a706924e57f6c | |
parent | 82e247e310420a46ae47a7a920309c654b8a6e5d (diff) |
[Zurich] Remove phone number requirement for mobile app reports
The phone number was made mandatory in #541. To make this change
compatible with older versions of the mobile app I've had to drop
server side validation of the phone number for requests that come in
from mobile apps.
To determine if it's a mobile request I'm checking the 'service'
parameter in the request, which is only set in requests from the mobile
apps [1].
The phone validation will still happen client side for the newer
versions of the app, and the web app will continue to work with the
server side validations.
[1] https://github.com/mysociety/zurich_mobile/blob/1fec2bc21dad9326819105cdbf5d47183e7503ba/www/js/models.js#L75
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 6 | ||||
-rw-r--r-- | t/cobrand/zurich.t | 23 |
2 files changed, 28 insertions, 1 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 6018dfa80..59d38a6cf 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -956,7 +956,11 @@ sub check_for_errors : Private { delete $field_errors{name}; my $report = $c->stash->{report}; $report->title( Utils::cleanup_text( substr($report->detail, 0, 25) ) ); - if ( ! $c->req->param('phone') ) { + + # We only want to validate the phone number web requests (where the + # service parameter is blank) because previous versions of the mobile + # apps don't validate the presence of a phone number. + if ( ! $c->req->param('phone') and ! $c->req->param('service') ) { $field_errors{phone} = _("This information is required"); } } diff --git a/t/cobrand/zurich.t b/t/cobrand/zurich.t index 88d1f6365..5b20f50e5 100644 --- a/t/cobrand/zurich.t +++ b/t/cobrand/zurich.t @@ -5,6 +5,7 @@ use strict; use warnings; use DateTime; use Test::More; +use JSON; plan skip_all => 'Skipping Zurich test without Zurich cobrand' unless FixMyStreet::Cobrand->exists('zurich'); @@ -338,6 +339,28 @@ subtest "phone number is mandatory" => sub { }; }; +subtest "phone number is not mandatory for reports from mobile apps" => sub { + FixMyStreet::override_config { + MAPIT_TYPES => [ 'O08' ], + MAPIT_URL => 'http://global.mapit.mysociety.org/', + }, sub { + $mech->post_ok( '/report/new/mobile?lat=47.381817&lon=8.529156' , { + service => 'iPhone', + detail => 'Problem-Bericht', + lat => 47.381817, + lon => 8.529156, + email => 'user@example.org', + pc => '', + name => '', + }); + my $res = $mech->response; + ok $res->header('Content-Type') =~ m{^application/json\b}, 'response should be json'; + unlike $res->content, qr/Diese Information wird benötigt/, 'response should not contain phone error'; + # Clear out the mailq + $mech->clear_emails_ok; + }; +}; + subtest "problems can't be assigned to deleted bodies" => sub { $user = $mech->log_in_ok( 'dm1@example.org' ); $user->from_body( 1 ); |