diff options
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Bodies.pm | 11 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Admin/Users.pm | 3 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Council.pm | 13 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Open311.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Report/New.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/App/Controller/Reports.pm | 18 | ||||
-rwxr-xr-x | perllib/FixMyStreet/App/Controller/Rss.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Default.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Factories.pm | 4 | ||||
-rw-r--r-- | perllib/FixMyStreet/DB/Result/Body.pm | 8 | ||||
-rw-r--r-- | perllib/FixMyStreet/MapIt.pm | 18 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Alerts.pm | 6 | ||||
-rw-r--r-- | perllib/FixMyStreet/Script/Reports.pm | 1 | ||||
-rw-r--r-- | perllib/FixMyStreet/SendReport/Email.pm | 20 | ||||
-rw-r--r-- | perllib/Open311/GetServiceRequests.pm | 8 | ||||
-rw-r--r-- | t/Mock/MapIt.pm | 10 | ||||
-rw-r--r-- | t/app/controller/around.t | 6 | ||||
-rw-r--r-- | t/app/sendreport/email.t | 17 |
18 files changed, 99 insertions, 58 deletions
diff --git a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm index 1f8840bcb..0e47d2238 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Bodies.pm @@ -6,6 +6,7 @@ BEGIN { extends 'Catalyst::Controller'; } use POSIX qw(strcoll); use mySociety::EmailUtil qw(is_valid_email_list); +use FixMyStreet::MapIt; use FixMyStreet::SendReport; =head1 NAME @@ -104,7 +105,7 @@ sub body : Chained('/') : PathPart('admin/body') : CaptureArgs(1) { $c->stash->{body} = $body; if ($body->body_areas->first) { - my $example_postcode = mySociety::MaPit::call('area/example_postcode', $body->body_areas->first->area_id); + my $example_postcode = FixMyStreet::MapIt::call('area/example_postcode', $body->body_areas->first->area_id); if ($example_postcode && ! ref $example_postcode) { $c->stash->{example_pc} = $example_postcode; } @@ -187,14 +188,10 @@ sub body_form_dropdowns : Private { my $areas; my $whitelist = $c->config->{MAPIT_ID_WHITELIST}; - my %params; - $params{generation} = $c->config->{MAPIT_GENERATION} - if $c->config->{MAPIT_GENERATION}; - if ( $whitelist && ref $whitelist eq 'ARRAY' && @$whitelist ) { - $areas = mySociety::MaPit::call('areas', $whitelist, %params); + $areas = FixMyStreet::MapIt::call('areas', $whitelist); } else { - $areas = mySociety::MaPit::call('areas', $c->cobrand->area_types, %params); + $areas = FixMyStreet::MapIt::call('areas', $c->cobrand->area_types); } # Some cobrands may want to add extra areas at runtime beyond those diff --git a/perllib/FixMyStreet/App/Controller/Admin/Users.pm b/perllib/FixMyStreet/App/Controller/Admin/Users.pm index 11a6d9962..bcbc808ed 100644 --- a/perllib/FixMyStreet/App/Controller/Admin/Users.pm +++ b/perllib/FixMyStreet/App/Controller/Admin/Users.pm @@ -8,6 +8,7 @@ use POSIX qw(strcoll); use mySociety::EmailUtil qw(is_valid_email); use Text::CSV; +use FixMyStreet::MapIt; use FixMyStreet::SMS; use Utils; @@ -450,7 +451,7 @@ sub user_alert_details : Private { } if (@wards) { - $c->stash->{alert_areas} = mySociety::MaPit::call('areas', join(',', @wards) ); + $c->stash->{alert_areas} = FixMyStreet::MapIt::call('areas', join(',', @wards) ); } my %body_names = map { $_->{id} => $_->{name} } @{ $c->stash->{bodies} }; diff --git a/perllib/FixMyStreet/App/Controller/Council.pm b/perllib/FixMyStreet/App/Controller/Council.pm index 2e2dce0f7..4acaba903 100644 --- a/perllib/FixMyStreet/App/Controller/Council.pm +++ b/perllib/FixMyStreet/App/Controller/Council.pm @@ -2,6 +2,8 @@ package FixMyStreet::App::Controller::Council; use Moose; use namespace::autoclean; +use FixMyStreet::MapIt; + BEGIN {extends 'Catalyst::Controller'; } =head1 NAME @@ -59,10 +61,6 @@ sub load_and_check_areas : Private { my $all_areas; - my %params; - $params{generation} = $c->config->{MAPIT_GENERATION} - if $c->config->{MAPIT_GENERATION}; - if ($prefetched_all_areas) { $all_areas = { map { $_ => { id => $_ } } @@ -71,8 +69,7 @@ sub load_and_check_areas : Private { } elsif ( $c->stash->{fetch_all_areas} ) { my %area_types = map { $_ => 1 } @$area_types; $all_areas = - mySociety::MaPit::call( 'point', - "4326/$longitude,$latitude", %params ); + FixMyStreet::MapIt::call('point', "4326/$longitude,$latitude"); $c->stash->{all_areas_mapit} = $all_areas; $all_areas = { map { $_ => $all_areas->{$_} } @@ -81,9 +78,7 @@ sub load_and_check_areas : Private { }; } else { $all_areas = - mySociety::MaPit::call( 'point', - "4326/$longitude,$latitude", %params, - type => $area_types ); + FixMyStreet::MapIt::call('point', "4326/$longitude,$latitude", type => $area_types); } if ($all_areas->{error}) { $c->stash->{location_error_mapit_error} = 1; diff --git a/perllib/FixMyStreet/App/Controller/Open311.pm b/perllib/FixMyStreet/App/Controller/Open311.pm index 5d7ec63d6..97e1a782a 100644 --- a/perllib/FixMyStreet/App/Controller/Open311.pm +++ b/perllib/FixMyStreet/App/Controller/Open311.pm @@ -7,6 +7,7 @@ use namespace::autoclean; use JSON::MaybeXS; use XML::Simple; use DateTime::Format::W3CDTF; +use FixMyStreet::MapIt; BEGIN { extends 'Catalyst::Controller'; } @@ -164,12 +165,7 @@ sub get_services : Private { if ($lat || $lon) { my $area_types = $c->cobrand->area_types; - my %params = ( type => $area_types ); - $params{generation} = $c->config->{MAPIT_GENERATION} - if $c->config->{MAPIT_GENERATION}; - my $all_areas = mySociety::MaPit::call('point', - "4326/$lon,$lat", - %params); + my $all_areas = FixMyStreet::MapIt::call('point', "4326/$lon,$lat", type => $area_types); $categories = $categories->search( { 'body_areas.area_id' => [ keys %$all_areas ], }, { join => { 'body' => 'body_areas' } } ); diff --git a/perllib/FixMyStreet/App/Controller/Report/New.pm b/perllib/FixMyStreet/App/Controller/Report/New.pm index 063226f18..83d0f8572 100644 --- a/perllib/FixMyStreet/App/Controller/Report/New.pm +++ b/perllib/FixMyStreet/App/Controller/Report/New.pm @@ -9,7 +9,6 @@ use List::MoreUtils qw(uniq); use List::Util 'first'; use POSIX 'strcoll'; use HTML::Entities; -use mySociety::MaPit; use Path::Class; use Utils; use mySociety::EmailUtil; diff --git a/perllib/FixMyStreet/App/Controller/Reports.pm b/perllib/FixMyStreet/App/Controller/Reports.pm index 751870bd4..49bdce379 100644 --- a/perllib/FixMyStreet/App/Controller/Reports.pm +++ b/perllib/FixMyStreet/App/Controller/Reports.pm @@ -6,7 +6,7 @@ use JSON::MaybeXS; use List::MoreUtils qw(any); use Path::Tiny; use RABX; -use mySociety::MaPit; +use FixMyStreet::MapIt; BEGIN { extends 'Catalyst::Controller'; } @@ -219,12 +219,10 @@ sub rss_area_ward : Path('/rss/area') : Args(2) { # We're checking an area here, but this function is currently doing that. return if $c->cobrand->reports_body_check( $c, $area ); - my %params = ( type => $c->cobrand->area_types ); - $params{generation} = $c->config->{MAPIT_GENERATION} - if $c->config->{MAPIT_GENERATION}; - # We must now have a string to check on mapit - my $areas = mySociety::MaPit::call( 'areas', $area, %params ); + my $areas = FixMyStreet::MapIt::call( 'areas', $area, + type => $c->cobrand->area_types, + ); if (keys %$areas == 1) { ($c->stash->{area}) = values %$areas; @@ -393,11 +391,9 @@ sub ward_check : Private { $parent_id = $c->stash->{area}->{id}; } - my %params = ( type => $c->cobrand->area_types_children ); - $params{generation} = $c->config->{MAPIT_GENERATION} - if $c->config->{MAPIT_GENERATION}; - - my $qw = mySociety::MaPit::call('area/children', [ $parent_id ], %params); + my $qw = FixMyStreet::MapIt::call('area/children', [ $parent_id ], + type => $c->cobrand->area_types_children, + ); my %names = map { $c->cobrand->short_name({ name => $_ }) => 1 } @wards; my @areas; foreach my $area (sort { $a->{name} cmp $b->{name} } values %$qw) { diff --git a/perllib/FixMyStreet/App/Controller/Rss.pm b/perllib/FixMyStreet/App/Controller/Rss.pm index e1da4445d..443e45b93 100755 --- a/perllib/FixMyStreet/App/Controller/Rss.pm +++ b/perllib/FixMyStreet/App/Controller/Rss.pm @@ -11,7 +11,7 @@ use FixMyStreet::App::Model::PhotoSet; use FixMyStreet::Gaze; use mySociety::Locale; -use mySociety::MaPit; +use FixMyStreet::MapIt; use Lingua::EN::Inflect qw(ORD); BEGIN { extends 'Catalyst::Controller'; } @@ -66,7 +66,7 @@ sub reports_in_area : LocalRegex('^area/(\d+)$') { my ( $self, $c ) = @_; my $id = $c->req->captures->[0]; - my $area = mySociety::MaPit::call('area', $id); + my $area = FixMyStreet::MapIt::call('area', $id); $c->stash->{type} = 'area_problems'; $c->stash->{qs} = '/' . $id; $c->stash->{db_params} = [ $id ]; diff --git a/perllib/FixMyStreet/Cobrand/Default.pm b/perllib/FixMyStreet/Cobrand/Default.pm index ed15dbf05..a8146128e 100644 --- a/perllib/FixMyStreet/Cobrand/Default.pm +++ b/perllib/FixMyStreet/Cobrand/Default.pm @@ -13,7 +13,6 @@ use URI; use Digest::MD5 qw(md5_hex); use Carp; -use mySociety::MaPit; use mySociety::PostcodeUtil; =head1 The default cobrand diff --git a/perllib/FixMyStreet/DB/Factories.pm b/perllib/FixMyStreet/DB/Factories.pm index 4cbab4753..5af9ed38f 100644 --- a/perllib/FixMyStreet/DB/Factories.pm +++ b/perllib/FixMyStreet/DB/Factories.pm @@ -199,7 +199,7 @@ sub create_problem { package FixMyStreet::DB::Factory::Body; use parent -norequire, "FixMyStreet::DB::Factory::Base"; -use mySociety::MaPit; +use FixMyStreet::MapIt; __PACKAGE__->resultset(FixMyStreet::DB->resultset("Body")); @@ -208,7 +208,7 @@ __PACKAGE__->exclude(['area_id', 'categories']); __PACKAGE__->fields({ name => __PACKAGE__->callback(sub { my $area_id = shift->get('area_id'); - my $area = mySociety::MaPit::call('area', $area_id); + my $area = FixMyStreet::MapIt::call('area', $area_id); $area->{name}; }), body_areas => __PACKAGE__->callback(sub { diff --git a/perllib/FixMyStreet/DB/Result/Body.pm b/perllib/FixMyStreet/DB/Result/Body.pm index c04c117ae..37164c990 100644 --- a/perllib/FixMyStreet/DB/Result/Body.pm +++ b/perllib/FixMyStreet/DB/Result/Body.pm @@ -134,6 +134,7 @@ __PACKAGE__->rabx_column('extra'); use Moo; use namespace::clean; +use FixMyStreet::MapIt; with 'FixMyStreet::Roles::Translatable', 'FixMyStreet::Roles::Extra'; @@ -182,10 +183,9 @@ sub first_area_children { my $cobrand = $self->result_source->schema->cobrand; - my %params = ( type => $cobrand->area_types_children ); - $params{generation} = FixMyStreet->config('MAPIT_GENERATION') - if FixMyStreet->config('MAPIT_GENERATION'); - my $children = mySociety::MaPit::call('area/children', $body_area->area_id, %params); + my $children = FixMyStreet::MapIt::call('area/children', $body_area->area_id, + type => $cobrand->area_types_children, + ); return $children; } diff --git a/perllib/FixMyStreet/MapIt.pm b/perllib/FixMyStreet/MapIt.pm new file mode 100644 index 000000000..d0a5f4760 --- /dev/null +++ b/perllib/FixMyStreet/MapIt.pm @@ -0,0 +1,18 @@ +package FixMyStreet::MapIt; + +use FixMyStreet; +use mySociety::MaPit; + +sub call { + my ($url, $params, %opts) = @_; + + # 'area' always returns the ID you provide, no matter its generation, so no + # point in specifying it for that. 'areas' similarly if given IDs, but we + # might be looking up types or names, so might as well specify it then. + $opts{generation} = FixMyStreet->config('MAPIT_GENERATION') + if $url ne 'area' && FixMyStreet->config('MAPIT_GENERATION'); + + return mySociety::MaPit::call($url, $params, %opts); +} + +1; diff --git a/perllib/FixMyStreet/Script/Alerts.pm b/perllib/FixMyStreet/Script/Alerts.pm index a0c25a8fc..55f4b3db5 100644 --- a/perllib/FixMyStreet/Script/Alerts.pm +++ b/perllib/FixMyStreet/Script/Alerts.pm @@ -8,7 +8,7 @@ use IO::String; use FixMyStreet::Gaze; use mySociety::Locale; -use mySociety::MaPit; +use FixMyStreet::MapIt; use RABX; use FixMyStreet::Cobrand; @@ -186,14 +186,14 @@ sub send() { $data{report} = $schema->resultset('Problem')->find({ id => $row->{id} }); } if ($ref eq 'area_problems') { - my $va_info = mySociety::MaPit::call('area', $row->{alert_parameter}); + my $va_info = FixMyStreet::MapIt::call('area', $row->{alert_parameter}); $data{area_name} = $va_info->{name}; } elsif ($ref eq 'council_problems' || $ref eq 'ward_problems') { my $body = FixMyStreet::DB->resultset('Body')->find({ id => $row->{alert_parameter} }); $data{area_name} = $body->name; } if ($ref eq 'ward_problems') { - my $va_info = mySociety::MaPit::call('area', $row->{alert_parameter2}); + my $va_info = FixMyStreet::MapIt::call('area', $row->{alert_parameter2}); $data{ward_name} = $va_info->{name}; } } diff --git a/perllib/FixMyStreet/Script/Reports.pm b/perllib/FixMyStreet/Script/Reports.pm index 1fef6fe08..ecd461cd9 100644 --- a/perllib/FixMyStreet/Script/Reports.pm +++ b/perllib/FixMyStreet/Script/Reports.pm @@ -8,7 +8,6 @@ use DateTime::Format::Pg; use Utils; use Utils::OpenStreetMap; -use mySociety::MaPit; use FixMyStreet; use FixMyStreet::Cobrand; diff --git a/perllib/FixMyStreet/SendReport/Email.pm b/perllib/FixMyStreet/SendReport/Email.pm index ae1243fdb..cd697fa0f 100644 --- a/perllib/FixMyStreet/SendReport/Email.pm +++ b/perllib/FixMyStreet/SendReport/Email.pm @@ -19,6 +19,9 @@ sub build_recipient_list { my ($body_email, $state, $note) = ( $contact->email, $contact->state, $contact->note ); + $body_email = swandt_contact($row->latitude, $row->longitude) + if ($body->areas->{2427} || $body->areas->{2429}) && $body_email eq 'SPECIAL'; + unless ($state eq 'confirmed') { $all_confirmed = 0; $note = 'Body ' . $row->bodies_str . ' deleted' @@ -111,4 +114,21 @@ sub send { return $result; } +# SW&T has different contact addresses depending upon the old district +sub swandt_contact { + my $district = _get_district_for_contact(@_); + my $email; + $email = ['customerservices', 'westsomerset'] if $district == 2427; + $email = ['enquiries', 'tauntondeane'] if $district == 2429; + return join('@', $email->[0], $email->[1] . '.gov.uk'); +} + +sub _get_district_for_contact { + my ( $lat, $lon ) = @_; + my $district = + FixMyStreet::MapIt::call( 'point', "4326/$lon,$lat", type => 'DIS' ); + ($district) = keys %$district; + return $district; +} + 1; diff --git a/perllib/Open311/GetServiceRequests.pm b/perllib/Open311/GetServiceRequests.pm index 8a48cc6f4..215361a10 100644 --- a/perllib/Open311/GetServiceRequests.pm +++ b/perllib/Open311/GetServiceRequests.pm @@ -3,6 +3,7 @@ package Open311::GetServiceRequests; use Moo; use Open311; use FixMyStreet::DB; +use FixMyStreet::MapIt; use FixMyStreet::App::Model::PhotoSet; use DateTime::Format::W3CDTF; @@ -89,18 +90,13 @@ sub create_problems { } my $request_id = $request->{service_request_id}; - my %params; - $params{generation} = mySociety::Config::get('MAPIT_GENERATION') - if mySociety::Config::get('MAPIT_GENERATION'); - my ($latitude, $longitude) = ( $request->{lat}, $request->{long} ); ($latitude, $longitude) = Utils::convert_en_to_latlon_truncated( $longitude, $latitude ) if $self->convert_latlong; my $all_areas = - mySociety::MaPit::call( 'point', - "4326/$longitude,$latitude", %params ); + FixMyStreet::MapIt::call('point', "4326/$longitude,$latitude"); # skip if it doesn't look like it's for this body my @areas = grep { $all_areas->{$_->area_id} } $body->body_areas; diff --git a/t/Mock/MapIt.pm b/t/Mock/MapIt.pm index d5b73641a..11fa4200c 100644 --- a/t/Mock/MapIt.pm +++ b/t/Mock/MapIt.pm @@ -30,7 +30,6 @@ my @PLACES = ( [ 'SL9 0NX', 51.615559, -0.556903, 2217, 'Buckinghamshire County Council', 'CTY', 2257, 'Chiltern District Council', 'DIS' ], [ 'SW1A 1AA', 51.501009, -0.141588, 2504, 'Westminster City Council', 'LBO' ], [ 'GL50 2PR', 51.896268, -2.093063, 2226, 'Gloucestershire County Council', 'CTY', 2326, 'Cheltenham Borough Council', 'DIS', 4544, 'Lansdown', 'DIW', 143641, 'Lansdown and Park', 'CED' ], - [ '?', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'OX20 1SZ', 51.754926, -1.256179, 2237, 'Oxfordshire County Council', 'CTY', 2421, 'Oxford City Council', 'DIS' ], [ 'OX16 9UP', 52.038712, -1.346397, 2237, 'Oxfordshire County Council', 'CTY', 2419, 'Cherwell District Council', 'DIS', 151767, "Banbury, Calthorpe & Easington", "DIW" ], [ 'RG9 6TL', 51.561705, -0.868388, 2217, 'Buckinghamshire County Council', 'CTY'], @@ -39,6 +38,7 @@ my @PLACES = ( [ 'BR1 3UH', 51.4021, 0.01578, 2482, 'Bromley Council', 'LBO' ], [ 'BR1 3UH', 51.402096, 0.015784, 2482, 'Bromley Council', 'LBO' ], [ '?', 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' ], [ 'WS1 4NH', 52.563074, -1.991032, 2535, 'Sandwell Borough Council', 'MTD' ], [ 'OX28 4DS', 51.784721, -1.494453 ], @@ -72,14 +72,18 @@ sub dispatch_request { return $self->output($response); }, - sub (GET + /point/**.*) { - my ($self, $point) = @_; + sub (GET + /point/**.* + ?*) { + my ($self, $point, $query) = @_; foreach (@PLACES) { if ($point eq "4326/$_->[2],$_->[1]") { my %out; for (my $i=3; $i<@$_; $i+=3) { $out{"$_->[$i]"} = { id => $_->[$i], name => $_->[$i+1], type => $_->[$i+2] }; } + if ($query->{type}) { + my %types = map { $_ => 1 } split ',', $query->{type}; + %out = map { $_ => $out{$_} } grep { $types{$out{$_}{type}} } keys %out; + } return $self->output(\%out); } } diff --git a/t/app/controller/around.t b/t/app/controller/around.t index 3f0fff666..b123692fa 100644 --- a/t/app/controller/around.t +++ b/t/app/controller/around.t @@ -228,6 +228,7 @@ subtest 'check category, status and extra filtering works on /around' => sub { # Regression test for filter_category in /around URL FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', MAPIT_URL => 'http://mapit.uk/', }, sub { $mech->get_ok( '/around?filter_category=Pothole&bbox=' . $bbox ); @@ -331,15 +332,17 @@ subtest 'check skip_around skips around page' => sub { FixMyStreet::override_config { MAPIT_URL => 'http://mapit.uk/', + MAPIT_TYPES => ['CTY', 'DIS'], }, sub { $mech->get('/around?latitude=51.754926&longitude=-1.256179'); - is $mech->res->code, 302, "around page is a redirect"; + is $mech->res->previous->code, 302, "around page is a redirect"; is $mech->uri->path, '/report/new', "and redirects to /report/new"; }; }; subtest 'check map zoom level customisation' => sub { FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', MAPIT_URL => 'http://mapit.uk/', MAP_TYPE => 'OSM', }, sub { @@ -350,6 +353,7 @@ subtest 'check map zoom level customisation' => sub { FixMyStreet::override_config { + ALLOWED_COBRANDS => 'fixmystreet', MAPIT_URL => 'http://mapit.uk/', MAP_TYPE => 'Tester', }, sub { diff --git a/t/app/sendreport/email.t b/t/app/sendreport/email.t index 6b292725b..3e6db4f67 100644 --- a/t/app/sendreport/email.t +++ b/t/app/sendreport/email.t @@ -20,6 +20,8 @@ my $contact = $mech->create_contact_ok( ); my $row = FixMyStreet::DB->resultset('Problem')->new( { + latitude => 51.023569, + longitude => -3.099055, bodies_str => '1000', category => 'category', cobrand => '', @@ -67,4 +69,19 @@ foreach my $test ( { }; } +$body->body_areas->delete; +$body->body_areas->create({ area_id => 2429 }); + +subtest 'Test special behaviour' => sub { + my $e = FixMyStreet::SendReport::Email->new; + $contact->update( { state => 'confirmed', email => 'SPECIAL' } ); + $e->add_body( $body ); + FixMyStreet::override_config { + MAPIT_URL => 'http://mapit.uk/' + }, sub { + my ($e) = $e->build_recipient_list( $row, {} ); + like $e->[0], qr/tauntondeane/, 'correct recipient'; + }; +}; + done_testing(); |