From a6bceccceba9b00419774cd983f5aa5b5e168d20 Mon Sep 17 00:00:00 2001 From: Victoria Mihell-Hale Date: Wed, 4 Sep 2024 16:57:33 +0100 Subject: [PATCH] [Northumberland] Send updates to assigned user to Alloy --- .../Integration/UK/NorthumberlandAlloy.pm | 53 ++++++++++++++++++- perllib/Open311/Endpoint/Role/mySociety.pm | 1 - 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm b/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm index 7c6c64273..de7e299c6 100644 --- a/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm +++ b/perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm @@ -90,12 +90,14 @@ Adds an update for the status attribute given by C, Adds an update for 'extra_details' field ('FMS Extra Details' on Alloy end). +Adds an update for the assigned user ('Assigned to' on Alloy end). + =cut sub update_additional_attributes { my ($self, $args) = @_; - return [ + my $attr = [ { attributeCode => $self->config->{update_status_attribute_id}, value => [ $self->config->{update_status_mapping} @@ -104,9 +106,56 @@ sub update_additional_attributes { }, { attributeCode => $self->config->{inspection_attribute_mapping}{extra_details}, - value => $args->{extra_details}, + value => $args->{attributes}{extra_details}, }, ]; + + if ( $args->{attributes}{assigned_to_user_email} ) { + # Search for existing user + my $mapping = $self->config->{assigned_to_user_mapping}; + + my $res = $self->alloy->search( + { properties => { + dodiCode => $mapping->{design}, + collectionCode => 'Live', + attributes => [ + $mapping->{username_attribute}, + $mapping->{email_attribute}, + ], + }, + children => [ + { type => "Equals", + children => [ + { type => 'Attribute', + properties => { + attributeCode => + $mapping->{email_attribute} + }, + }, + { type => 'String', + properties => { + value => + [ $args->{attributes}{assigned_to_user_email} ] + }, + } + ], + }, + ], + }, + ); + + # We don't update if user does not exist in Alloy + if (@$res) { + push @$attr, { + attributeCode => + $self->config->{inspection_attribute_mapping} + {assigned_to_user}, + value => [ $res->[0]{itemId} ], + }; + } + } + + return $attr; } =head2 get_assigned_to_users diff --git a/perllib/Open311/Endpoint/Role/mySociety.pm b/perllib/Open311/Endpoint/Role/mySociety.pm index 4fe8f3a53..cd2fe18fb 100644 --- a/perllib/Open311/Endpoint/Role/mySociety.pm +++ b/perllib/Open311/Endpoint/Role/mySociety.pm @@ -185,7 +185,6 @@ sub POST_Service_Request_Update_input_schema { public_anonymity_required => Open311::Endpoint::Schema->enum('//str', 'TRUE', 'FALSE'), email_alerts_requested => Open311::Endpoint::Schema->enum('//str', 'TRUE', 'FALSE'), service_code => $self->get_identifier_type('service_code'), - extra_details => '//str', } };