Skip to content

Commit

Permalink
Merge branch 'he-area-fallback-fms'
Browse files Browse the repository at this point in the history
  • Loading branch information
dracos committed Jun 15, 2021
2 parents 07ab4f1 + acbcee1 commit 3893e2b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 28 deletions.
26 changes: 0 additions & 26 deletions perllib/FixMyStreet/Cobrand/HighwaysEngland.pm
Original file line number Diff line number Diff line change
Expand Up @@ -158,32 +158,6 @@ sub munge_report_new_contacts {
}
}

sub munge_sendreport_params {
my ($self, $row, $h, $params) = @_;

if (!$row->get_extra_field_value('area_name')) {
my $cfg = $self->lookup_site_code_config;
my ($x, $y) = $row->local_coords;
my $ukc = FixMyStreet::Cobrand::UKCouncils->new;
my $features = $ukc->_fetch_features($cfg, $x, $y);
my $nearest = $ukc->_nearest_feature($cfg, $x, $y, $features);
if ($nearest) {
my $attr = $nearest->{properties};
$row->update_extra_field({ name => 'road_name', value => $attr->{ROA_NUMBER}, description => 'Road name' });
$row->update_extra_field({ name => 'area_name', value => $attr->{area_name}, description => 'Area name' });
$row->update_extra_field({ name => 'sect_label', value => $attr->{sect_label}, description => 'Road sector' });
}
}
}

sub lookup_site_code_config { {
buffer => 15, # metres
url => "https://tilma.mysociety.org/mapserver/highways",
srsname => "urn:ogc:def:crs:EPSG::27700",
typename => "Highways",
accept_feature => sub { 1 }
} }

sub report_new_is_on_he_road {
my ( $self ) = @_;

Expand Down
28 changes: 27 additions & 1 deletion perllib/FixMyStreet/SendReport/Email/Highways.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ extends 'FixMyStreet::SendReport::Email';
sub build_recipient_list {
my ( $self, $row, $h ) = @_;

# Try and make sure we have road details if they're missing
my $area_name = $row->get_extra_field_value('area_name') || _lookup_site_code($row) || '';

return unless @{$self->bodies} == 1;
my $body = $self->bodies->[0];

my $contact = $self->fetch_category($body, $row) or return;
my $email = $contact->email;
my $area_name = $row->get_extra_field_value('area_name') || '';

# config is read-only, so must step through one-by-one to prevent
# vivification
Expand All @@ -25,4 +27,28 @@ sub build_recipient_list {
return 1;
}

sub _lookup_site_code_config { {
buffer => 15, # metres
url => "https://tilma.mysociety.org/mapserver/highways",
srsname => "urn:ogc:def:crs:EPSG::27700",
typename => "Highways",
accept_feature => sub { 1 }
} }

sub _lookup_site_code {
my $row = shift;
my $cfg = _lookup_site_code_config();
my ($x, $y) = $row->local_coords;
my $ukc = FixMyStreet::Cobrand::UKCouncils->new;
my $features = $ukc->_fetch_features($cfg, $x, $y);
my $nearest = $ukc->_nearest_feature($cfg, $x, $y, $features);
return unless $nearest;

my $attr = $nearest->{properties};
$row->update_extra_field({ name => 'road_name', value => $attr->{ROA_NUMBER}, description => 'Road name' });
$row->update_extra_field({ name => 'area_name', value => $attr->{area_name}, description => 'Area name' });
$row->update_extra_field({ name => 'sect_label', value => $attr->{sect_label}, description => 'Road sector' });
return $attr->{area_name};
}

1;
2 changes: 1 addition & 1 deletion t/cobrand/highwaysengland.t
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ $r = $he->geocode_postcode('m1');
ok $r->{error}, "searching for lowecase road only generates error";

my $mech = FixMyStreet::TestMech->new;
my $highways = $mech->create_body_ok(2234, 'Highways England');
my $highways = $mech->create_body_ok(2234, 'Highways England', { send_method => 'Email::Highways' });

$mech->create_contact_ok(email => 'highways@example.com', body_id => $highways->id, category => 'Pothole', group => 'Highways England');

Expand Down
1 change: 1 addition & 0 deletions t/sendreport/email/highways.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ my $row = FixMyStreet::DB->resultset('Problem')->new( {
bodies_str => '1000',
category => 'Pothole',
cobrand => '',
extra => { _fields => [ { name => 'area_name', value => 'Area 8' } ] },
} );

my $e = FixMyStreet::SendReport::Email::Highways->new;
Expand Down

0 comments on commit 3893e2b

Please sign in to comment.