From 64544fbee60ce62a5808254733c677c9c759350e Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Wed, 13 Sep 2023 16:50:45 +0100 Subject: [PATCH 1/2] [UK] Include group when sending to Alloy. --- perllib/FixMyStreet/Cobrand/Hackney.pm | 47 ++++++++----------- perllib/FixMyStreet/Cobrand/Northumberland.pm | 17 ------- perllib/FixMyStreet/Cobrand/Oxfordshire.pm | 2 + perllib/FixMyStreet/Roles/Open311Alloy.pm | 2 + t/sendreport/open311.t | 1 + 5 files changed, 25 insertions(+), 44 deletions(-) diff --git a/perllib/FixMyStreet/Cobrand/Hackney.pm b/perllib/FixMyStreet/Cobrand/Hackney.pm index c0159e74cab..f476b7b052f 100644 --- a/perllib/FixMyStreet/Cobrand/Hackney.pm +++ b/perllib/FixMyStreet/Cobrand/Hackney.pm @@ -102,33 +102,6 @@ sub geocoder_munge_results { $result->{display_name} =~ s/, London Borough of Hackney//; } -=item * When sending via Open311, make sure closest address is included - -=cut - -around open311_extra_data_include => sub { - my ($orig, $self) = (shift, shift); - my $open311_only = $self->$orig(@_); - - my ($row, $h, $contact) = @_; - - # Make sure contact 'email' set correctly for Open311 - if (my $split_match = $row->get_extra_metadata('split_match')) { - $row->unset_extra_metadata('split_match'); - my $code = $split_match->{$contact->email}; - $contact->email($code) if $code; - } - - if (my $address = $row->nearest_address) { - push @$open311_only, ( - { name => 'closest_address', value => $address } - ); - $h->{closest_address} = ''; - } - - return $open311_only; -}; - =item * Hackney use OSM maps =cut @@ -260,6 +233,10 @@ sub munge_sendreport_params { } } +=item * When sending via Open311, make sure closest address is included + +=cut + sub open311_extra_data_include { my ($self, $row, $h, $contact) = @_; @@ -270,6 +247,8 @@ sub open311_extra_data_include { value => $row->detail }, { name => 'category', value => $row->category }, + { name => 'group', + value => $row->get_extra_metadata('group') }, ]; my $title = $row->title; @@ -292,6 +271,20 @@ sub open311_extra_data_include { } push @$open311_only, { name => 'title', value => $title }; + # Make sure contact 'email' set correctly for Open311 + if (my $split_match = $row->get_extra_metadata('split_match')) { + $row->unset_extra_metadata('split_match'); + my $code = $split_match->{$contact->email}; + $contact->email($code) if $code; + } + + if (my $address = $row->nearest_address) { + push @$open311_only, ( + { name => 'closest_address', value => $address } + ); + $h->{closest_address} = ''; + } + return $open311_only; } diff --git a/perllib/FixMyStreet/Cobrand/Northumberland.pm b/perllib/FixMyStreet/Cobrand/Northumberland.pm index 560ad75f6dd..7601aac2448 100644 --- a/perllib/FixMyStreet/Cobrand/Northumberland.pm +++ b/perllib/FixMyStreet/Cobrand/Northumberland.pm @@ -58,23 +58,6 @@ sub munge_report_new_contacts { } } -sub open311_extra_data_include { - my ($self, $row, $h) = @_; - - my $open311_only = [ - { name => 'report_url', - value => $h->{url} }, - { name => 'title', - value => $row->title }, - { name => 'description', - value => $row->detail }, - { name => 'category', - value => $row->category }, - ]; - - return $open311_only; -} - sub open311_title_fetched_report { my ($self, $request) = @_; my ($group, $category) = split(/_/, $request->{service_name}); diff --git a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm index be2c7c5dbfa..e30b4087803 100644 --- a/perllib/FixMyStreet/Cobrand/Oxfordshire.pm +++ b/perllib/FixMyStreet/Cobrand/Oxfordshire.pm @@ -142,6 +142,8 @@ sub open311_extra_data_include { value => $row->detail }, { name => 'category', value => $row->category }, + { name => 'group', + value => $row->get_extra_metadata('group') }, ]; push @$extra, { name => 'staff_role', value => $roles } if $roles; return $extra; diff --git a/perllib/FixMyStreet/Roles/Open311Alloy.pm b/perllib/FixMyStreet/Roles/Open311Alloy.pm index 4b121afb362..8836952daec 100644 --- a/perllib/FixMyStreet/Roles/Open311Alloy.pm +++ b/perllib/FixMyStreet/Roles/Open311Alloy.pm @@ -26,6 +26,8 @@ sub open311_extra_data_include { value => $row->detail }, { name => 'category', value => $row->category }, + { name => 'group', + value => $row->get_extra_metadata('group') }, ]; return $open311_only; diff --git a/t/sendreport/open311.t b/t/sendreport/open311.t index 7bab9293417..b72428ea0d7 100644 --- a/t/sendreport/open311.t +++ b/t/sendreport/open311.t @@ -173,6 +173,7 @@ test_overrides hackney => { name => 'title', value => 'Problem' }, { name => 'description', value => 'A big problem' }, { name => 'category', value => 'ZZ' }, + { name => 'group', value => undef }, { name => 'closest_address', value => '1 Test Street, Testville, TE57 1AB' }, ), }); From 40eae00ba747717f0032413cb4fde1728d05d6cd Mon Sep 17 00:00:00 2001 From: Matthew Somerville Date: Thu, 14 Sep 2023 15:03:54 +0100 Subject: [PATCH 2/2] [Open311] Make sure empty group stored as string. --- perllib/Open311/PopulateServiceList.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/perllib/Open311/PopulateServiceList.pm b/perllib/Open311/PopulateServiceList.pm index ed7ae4000e4..2404a6946dc 100644 --- a/perllib/Open311/PopulateServiceList.pm +++ b/perllib/Open311/PopulateServiceList.pm @@ -356,12 +356,12 @@ sub _get_new_groups { return [] unless $self->_current_body_cobrand && $self->_current_body_cobrand->enable_category_groups; my $groups = $self->_current_service->{groups} || []; - my @groups = map { Utils::trim_text($_) } @$groups; + my @groups = map { Utils::trim_text($_ || '') } @$groups; return \@groups if @groups; my $group = $self->_current_service->{group} || []; $group = [] if @$group == 1 && !$group->[0]; # becomes [undef]... - @groups = map { Utils::trim_text($_) } @$group; + @groups = map { Utils::trim_text($_ || '') } @$group; return \@groups; }