diff options
Diffstat (limited to 'perllib/FixMyStreet')
-rw-r--r-- | perllib/FixMyStreet/Cobrand/Buckinghamshire.pm | 71 | ||||
-rw-r--r-- | perllib/FixMyStreet/Cobrand/TfL.pm | 60 | ||||
-rw-r--r-- | perllib/FixMyStreet/Roles/BoroughEmails.pm | 68 |
3 files changed, 100 insertions, 99 deletions
diff --git a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm index b13f4eed1..188a503c1 100644 --- a/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm +++ b/perllib/FixMyStreet/Cobrand/Buckinghamshire.pm @@ -7,10 +7,11 @@ use warnings; use Moo; with 'FixMyStreet::Roles::ConfirmOpen311'; with 'FixMyStreet::Roles::ConfirmValidation'; +with 'FixMyStreet::Roles::BoroughEmails'; sub council_area_id { return 2217; } sub council_area { return 'Buckinghamshire'; } -sub council_name { return 'Buckinghamshire County Council'; } +sub council_name { return 'Buckinghamshire Council'; } sub council_url { return 'buckinghamshire'; } sub disambiguate_location { @@ -98,41 +99,15 @@ sub open311_contact_meta_override { } if $service->{service_name} eq 'Flytipping'; } -sub process_open311_extras { - my ($self, $c, $body, $extra) = @_; - - return unless $c->stash->{report}; # Don't care about updates - - $self->flytipping_body_fix( - $c->stash->{report}, - $c->get_param('road-placement'), - $c->stash->{field_errors}, - ); -} - -sub flytipping_body_fix { - my ($self, $report, $road_placement, $errors) = @_; +sub report_new_munge_before_insert { + my ($self, $report) = @_; return unless $report->category eq 'Flytipping'; - if ($report->bodies_str =~ /,/) { - # Sent to both councils in the area - my @bodies = values %{$report->bodies}; - my $county = (grep { $_->name =~ /^Buckinghamshire/ } @bodies)[0]; - my $district = (grep { $_->name !~ /^Buckinghamshire/ } @bodies)[0]; - # Decide which to send to based upon the answer to the extra question: - if ($road_placement eq 'road') { - $report->bodies_str($county->id); - } elsif ($road_placement eq 'off-road') { - $report->bodies_str($district->id); - } - } else { - # If the report is only being sent to the district, we do - # not care about the road question, if it is missing - if (!$report->to_body_named('Buckinghamshire')) { - delete $errors->{'xroad-placement'}; - } - } + my $placement = $self->{c}->get_param('road-placement'); + return unless $placement && $placement eq 'off-road'; + + $report->category('Flytipping (off-road)'); } sub filter_report_description { @@ -409,15 +384,8 @@ sub get_geocoder { 'OSM' } sub categories_restriction { my ($self, $rs) = @_; - # Buckinghamshire is a two-tier council, but mostly want to display - # county-level categories on their cobrand. - return $rs->search( - [ - { 'body_areas.area_id' => 2217 }, - { category => [ 'Flytipping', 'Car Parks' ] }, - ], - { join => { body => 'body_areas' } } - ); + + return $rs->search( { category => { '!=', 'Flytipping (off-road)'} } ); } sub lookup_site_code_config { { @@ -438,4 +406,23 @@ sub lookup_site_code_config { { } } } +around 'munge_sendreport_params' => sub { + my ($orig, $self, $row, $h, $params) = @_; + + # The district areas don't exist in MapIt past generation 36, so look up + # what district this report would have been in and temporarily override + # the areas column so BoroughEmails::munge_sendreport_params can do its + # thing. + my ($lat, $lon) = ($row->latitude, $row->longitude); + my $district = FixMyStreet::MapIt::call( 'point', "4326/$lon,$lat", type => 'DIS', generation => 36 ); + ($district) = keys %$district; + + my $original_areas = $row->areas; + $row->areas(",$district,"); + + $self->$orig($row, $h, $params); + + $row->areas($original_areas); +}; + 1; diff --git a/perllib/FixMyStreet/Cobrand/TfL.pm b/perllib/FixMyStreet/Cobrand/TfL.pm index 40c2a5257..72d1dbc86 100644 --- a/perllib/FixMyStreet/Cobrand/TfL.pm +++ b/perllib/FixMyStreet/Cobrand/TfL.pm @@ -4,6 +4,9 @@ use parent 'FixMyStreet::Cobrand::Whitelabel'; use strict; use warnings; +use Moo; +with 'FixMyStreet::Roles::BoroughEmails'; + use POSIX qw(strcoll); use FixMyStreet::MapIt; @@ -391,63 +394,6 @@ sub report_new_munge_before_insert { $report->set_extra_fields(@$extra); } -=head2 munge_sendreport_params - -TfL want reports made in certain categories sent to different email addresses -depending on what London Borough they were made in. To achieve this we have -some config in COBRAND_FEATURES that specifies what address to direct reports -to based on the MapIt area IDs it's in. - -Contacts that use this technique have a short code in their email field, -which is looked up in the `borough_email_addresses` hash. - -For example, if you wanted Pothole reports in Bromley and Barnet to be sent to -one email address, and Pothole reports in Hounslow to be sent to another, -create a contact with category = "Potholes" and email = "BOROUGHPOTHOLES" and -use the following config in general.yml: - -COBRAND_FEATURES: - borough_email_addresses: - tfl: - BOROUGHPOTHOLES: - - email: bromleybarnetpotholes@example.org - areas: - - 2482 # Bromley - - 2489 # Barnet - - email: hounslowpotholes@example.org - areas: - - 2483 # Hounslow - -=cut - -sub munge_sendreport_params { - my ($self, $row, $h, $params) = @_; - - my $addresses = $self->feature('borough_email_addresses'); - return unless $addresses; - - my @report_areas = grep { $_ } split ',', $row->areas; - - my $to = $params->{To}; - my @munged_to = (); - for my $recip ( @$to ) { - my ($email, $name) = @$recip; - if (my $teams = $addresses->{$email}) { - for my $team (@$teams) { - my %team_area_ids = map { $_ => 1 } @{ $team->{areas} }; - if ( grep { $team_area_ids{$_} } @report_areas ) { - $recip = [ - $team->{email}, - $name - ]; - } - } - } - push @munged_to, $recip; - } - $params->{To} = \@munged_to; -} - sub report_new_is_on_tlrn { my ( $self ) = @_; diff --git a/perllib/FixMyStreet/Roles/BoroughEmails.pm b/perllib/FixMyStreet/Roles/BoroughEmails.pm new file mode 100644 index 000000000..ba941f64f --- /dev/null +++ b/perllib/FixMyStreet/Roles/BoroughEmails.pm @@ -0,0 +1,68 @@ +package FixMyStreet::Roles::BoroughEmails; +use Moo::Role; + +=head1 NAME + +FixMyStreet::Roles::BoroughEmails - role for directing reports according to the +borough_email_addresses COBRAND_FEATURE + +=cut + +=head2 munge_sendreport_params + +TfL want reports made in certain categories sent to different email addresses +depending on what London Borough they were made in. To achieve this we have +some config in COBRAND_FEATURES that specifies what address to direct reports +to based on the MapIt area IDs it's in. + +Contacts that use this technique have a short code in their email field, +which is looked up in the `borough_email_addresses` hash. + +For example, if you wanted Pothole reports in Bromley and Barnet to be sent to +one email address, and Pothole reports in Hounslow to be sent to another, +create a contact with category = "Potholes" and email = "BOROUGHPOTHOLES" and +use the following config in general.yml: + +COBRAND_FEATURES: + borough_email_addresses: + tfl: + BOROUGHPOTHOLES: + - email: bromleybarnetpotholes@example.org + areas: + - 2482 # Bromley + - 2489 # Barnet + - email: hounslowpotholes@example.org + areas: + - 2483 # Hounslow + +=cut + +sub munge_sendreport_params { + my ($self, $row, $h, $params) = @_; + + my $addresses = $self->feature('borough_email_addresses'); + return unless $addresses; + + my @report_areas = grep { $_ } split ',', $row->areas; + + my $to = $params->{To}; + my @munged_to = (); + for my $recip ( @$to ) { + my ($email, $name) = @$recip; + if (my $teams = $addresses->{$email}) { + for my $team (@$teams) { + my %team_area_ids = map { $_ => 1 } @{ $team->{areas} }; + if ( grep { $team_area_ids{$_} } @report_areas ) { + $recip = [ + $team->{email}, + $name + ]; + } + } + } + push @munged_to, $recip; + } + $params->{To} = \@munged_to; +} + +1; |