Skip to content

Commit

Permalink
[Northumberland] Send updates to assigned user to Alloy
Browse files Browse the repository at this point in the history
  • Loading branch information
nephila-nacrea committed Sep 4, 2024
1 parent ab27f46 commit a6bcecc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
53 changes: 51 additions & 2 deletions perllib/Open311/Endpoint/Integration/UK/NorthumberlandAlloy.pm
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ Adds an update for the status attribute given by C<update_status_attribute_id>,
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}
Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion perllib/Open311/Endpoint/Role/mySociety.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
};

Expand Down

0 comments on commit a6bcecc

Please sign in to comment.