From 17bd24f015a984bff210bf3b92256508d953ee8c Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 28 Dec 2023 15:03:36 +0000 Subject: [PATCH] Bug 35657: Add support for assignee_id to ticket_updates endpoint This patch adds support for cross-synced ticket.assignee_id updates. The API allows you to set assignee directly on a ticket or via a ticket_update. In both cases we store a ticket_update with the fine details of when and who set the assigee. Signed-off-by: Paul Derscheid --- Koha/REST/V1/Tickets.pm | 19 +++++++++++++++++-- Koha/Ticket.pm | 13 +++++++++++++ Koha/Ticket/Update.pm | 13 +++++++++++++ api/v1/swagger/definitions/ticket.yaml | 8 ++++++++ api/v1/swagger/definitions/ticket_update.yaml | 8 ++++++++ api/v1/swagger/paths/tickets.yaml | 2 ++ .../prog/en/modules/cataloguing/concerns.tt | 3 ++- 7 files changed, 63 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1/Tickets.pm b/Koha/REST/V1/Tickets.pm index 52914723cb..7589da938b 100644 --- a/Koha/REST/V1/Tickets.pm +++ b/Koha/REST/V1/Tickets.pm @@ -116,10 +116,19 @@ sub update { ); } + my $assignee_before = $ticket->assignee_id; return try { $ticket->set_from_api( $c->req->json ); $ticket->store(); - return $c->render( status => 200, openapi => $c->objects->to_api($ticket), ); + + # Create update if assignee changed + if ( $assignee_before ne $ticket->assignee_id ) { + my $patron = $c->stash('koha.user'); + my $update = + { user_id => $patron->id, ticket_id => $ticket->id, public => 0, assignee_id => $ticket->assignee_id }; + Koha::Ticket::Updates->new($update)->store(); + } + return $c->render( status => 200, openapi => $c->objects->to_api($ticket) ); } catch { $c->unhandled_exception($_); @@ -197,7 +206,7 @@ sub add_update { ); } - # Set reporter from session + # Set user from session $ticket_update->{user_id} = $patron->id; # FIXME: We should allow impersonation at a later date to # allow an API user to submit on behalf of a user @@ -226,6 +235,12 @@ sub add_update { $ticket->set( { status => $ticket_update->{status} } )->store; } + # Update ticket assignee if needed + if ( $ticket_update->{assignee_id} ) { + my $ticket = $update->ticket; + $ticket->set( { assignee_id => $ticket_update->{assignee_id} } )->store; + } + # Optionally add to message_queue here to notify reporter if ( $update->public ) { my $notice = diff --git a/Koha/Ticket.pm b/Koha/Ticket.pm index 59792e24bf..836259485a 100644 --- a/Koha/Ticket.pm +++ b/Koha/Ticket.pm @@ -47,6 +47,19 @@ sub reporter { return Koha::Patron->_new_from_dbic($rs); } +=head3 assignee + +Return the patron who submitted this ticket + +=cut + +sub assignee { + my ($self) = @_; + my $rs = $self->_result->assignee; + return unless $rs; + return Koha::Patron->_new_from_dbic($rs); +} + =head3 resolver Return the user who resolved this ticket diff --git a/Koha/Ticket/Update.pm b/Koha/Ticket/Update.pm index dad68226f0..6ea262997a 100644 --- a/Koha/Ticket/Update.pm +++ b/Koha/Ticket/Update.pm @@ -55,6 +55,19 @@ sub user { return Koha::Patron->_new_from_dbic($rs); } +=head3 assignee + +Return the patron who is assigned at this update + +=cut + +sub assignee { + my ($self) = @_; + my $rs = $self->_result->assignee; + return unless $rs; + return Koha::Patron->_new_from_dbic($rs); +} + =head2 Internal methods =head3 to_api_mapping diff --git a/api/v1/swagger/definitions/ticket.yaml b/api/v1/swagger/definitions/ticket.yaml index 8699e455f4..7089891866 100644 --- a/api/v1/swagger/definitions/ticket.yaml +++ b/api/v1/swagger/definitions/ticket.yaml @@ -42,6 +42,14 @@ properties: reporter_id: type: integer description: Internal identifier for the patron who reported the ticket + assignee: + type: + - object + - "null" + assignee_id: + type: + - integer + - "null" resolver: type: - object diff --git a/api/v1/swagger/definitions/ticket_update.yaml b/api/v1/swagger/definitions/ticket_update.yaml index 7e95664312..7851b4a69d 100644 --- a/api/v1/swagger/definitions/ticket_update.yaml +++ b/api/v1/swagger/definitions/ticket_update.yaml @@ -18,6 +18,14 @@ properties: user_id: type: integer description: Internal identifier for the patron who added the update + assignee: + type: + - object + - "null" + assignee_id: + type: + - integer + - "null" date: type: - string diff --git a/api/v1/swagger/paths/tickets.yaml b/api/v1/swagger/paths/tickets.yaml index b28dc4fca0..a76239c66f 100644 --- a/api/v1/swagger/paths/tickets.yaml +++ b/api/v1/swagger/paths/tickets.yaml @@ -24,6 +24,7 @@ items: type: string enum: + - assignee - reporter - resolver - biblio @@ -237,6 +238,7 @@ items: type: string enum: + - assignee - user - +strings collectionFormat: csv diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt index 5255593a4e..5826fe2cee 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt @@ -103,6 +103,7 @@ "url": tickets_url }, "embed": [ + "assignee", "reporter", "resolver", "biblio", @@ -161,7 +162,7 @@ "orderable": true }, { - "data": "resolver.firstname:resolver.surname:resolved_date:status", + "data": "assignee.firstname:assignee.surname:resolver.firstname:resolver.surname:resolved_date:status", "render": function(data, type, row, meta) { let result = ''; if (row.resolved_date) { -- 2.44.0