From c9ab42d7e13fbb8cb570c72875f4ce9c602fb419 Mon Sep 17 00:00:00 2001 From: Moray Jones Date: Wed, 13 May 2026 16:19:15 +0100 Subject: [PATCH] [Dumfries] Add Inspector notes to report with update Adapts current adding of specific alloy attributes to extra->{detailed_information} to allow multiple attributes to be added as suggests there are in request. Test for non array attribute config is in northumberland.t https://github.com/mysociety/societyworks/issues/5477 --- .../Open311/Endpoint/Integration/AlloyV2.pm | 36 ++++++++++++++++--- t/open311/endpoint/dumfries_alloy.t | 2 ++ t/open311/endpoint/dumfries_alloy.yml | 3 ++ .../dumfries/defect_updates_search.json | 8 +++++ 4 files changed, 45 insertions(+), 4 deletions(-) diff --git a/perllib/Open311/Endpoint/Integration/AlloyV2.pm b/perllib/Open311/Endpoint/Integration/AlloyV2.pm index d25b1f5ad..2e52f6e18 100644 --- a/perllib/Open311/Endpoint/Integration/AlloyV2.pm +++ b/perllib/Open311/Endpoint/Integration/AlloyV2.pm @@ -833,10 +833,7 @@ sub _get_inspection_updates_design { $args{extras} = { %{$args{extras}}, %$assigned_to_user } if $assigned_to_user; - if ( my $extra_details_code = $mapping->{extra_details} ) { - $args{extras}{detailed_information} - = $attributes->{$extra_details_code} // ''; - } + $self->_add_extra_details($mapping->{extra_details}, $attributes, $args{extras}) if $mapping->{extra_details}; } $self->_apply_extra_attributes($mapping->{extra_attributes}, $attributes, $args{extras}); @@ -848,6 +845,36 @@ sub _get_inspection_updates_design { return (\@updates, \%items_by_id); } +=head2 _add_extra_details + +Adds a 'detailed_information' key to the 'extra' hash of an update which +will be passed to FMS for the value to be added to the +detailed_information on the report for staff only visiblility + +=cut + +sub _add_extra_details { + my ($self, $extra_details_code, $attributes, $extras) = @_; + + my @fields; + if (ref $extra_details_code eq 'ARRAY') { + @fields = @{$extra_details_code}; + } else { + push @fields, $extra_details_code; + } + + $extras->{detailed_information} = ''; + my $loop; + for my $field (@fields) { + if ($loop && $attributes->{$field}) { + $extras->{detailed_information} .= "\n" . $attributes->{$field}; + } elsif ($attributes->{$field}) { + $extras->{detailed_information} = $attributes->{$field}; + }; + $loop++; + } +} + sub _skip_inspection_update { } sub get_assigned_to_users { @@ -976,6 +1003,7 @@ sub _get_defect_updates_resource { extras => { latest_data_only => 1 }, ); + $self->_add_extra_details($mapping->{extra_details}, $attributes, $args{extras}) if $mapping->{extra_details}; $self->_apply_extra_attributes($extra_mapping, $attributes, $args{extras}); push @updates, Open311::Endpoint::Service::Request::Update::mySociety->new( %args ); diff --git a/t/open311/endpoint/dumfries_alloy.t b/t/open311/endpoint/dumfries_alloy.t index 2e95f0ac9..6d4c311b9 100644 --- a/t/open311/endpoint/dumfries_alloy.t +++ b/t/open311/endpoint/dumfries_alloy.t @@ -448,6 +448,8 @@ subtest 'defect updates include priority from extra_attributes' => sub { is $defect_update->{status}, 'planned', 'Defect status is planned'; is $defect_update->{extras}{priority}, '3 - 60 Working Days', 'Defect update includes priority from extra_attributes'; is $defect_update->{extras}{latest_data_only}, 1, 'latest_data_only flag present'; + is $defect_update->{extras}{detailed_information}, 'Inspector notes pothole in large category +Outcome notes fixed after a delay due to flooding of road', 'detailed_information added'; }; # See also t/open311/endpoint/alloy_deferred_work.t for async inspection upload tests. diff --git a/t/open311/endpoint/dumfries_alloy.yml b/t/open311/endpoint/dumfries_alloy.yml index fadceeeba..f1ae626fc 100644 --- a/t/open311/endpoint/dumfries_alloy.yml +++ b/t/open311/endpoint/dumfries_alloy.yml @@ -158,6 +158,9 @@ defect_resource_name: defect_attribute_mapping: requested_datetime: attributes_defectsReportedDate status: attributes_defectsStatus + extra_details: + - attributes_defectsInspectorsNotes + - attributes_defectsOutcomeNotes extra_attributes: priority: - root.attributes_defectTriagePriority.attributes_itemsTitle diff --git a/t/open311/endpoint/json/alloyv2/dumfries/defect_updates_search.json b/t/open311/endpoint/json/alloyv2/dumfries/defect_updates_search.json index dabd94865..b710a05a7 100644 --- a/t/open311/endpoint/json/alloyv2/dumfries/defect_updates_search.json +++ b/t/open311/endpoint/json/alloyv2/dumfries/defect_updates_search.json @@ -41,6 +41,14 @@ { "attributeCode": "attributes_defectsReportedDate", "value": "2025-12-25T10:00:00.000Z" + }, + { + "attributeCode": "attributes_defectsInspectorsNotes", + "value": "Inspector notes pothole in large category" + }, + { + "attributeCode": "attributes_defectsOutcomeNotes", + "value": "Outcome notes fixed after a delay due to flooding of road" } ], "signature": "sig123"