From 8b08ec8b3ffb9eba6b0bd976347b85af52c33881 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 Signed-off-by: Marcel de Rooy Signed-off-by: Katrin Fischer --- Koha/REST/V1/Tickets.pm | 27 ++++++++++++++++--- 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, 69 insertions(+), 5 deletions(-) diff --git a/Koha/REST/V1/Tickets.pm b/Koha/REST/V1/Tickets.pm index 17512a86d4..5fca8e443b 100644 --- a/Koha/REST/V1/Tickets.pm +++ b/Koha/REST/V1/Tickets.pm @@ -108,12 +108,25 @@ sub update { return $c->render_resource_not_found("Ticket") unless $ticket; + 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), ); - } - catch { + + # 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, + message => '' + }; + Koha::Ticket::Update->new($update)->store(); + } + return $c->render( status => 200, openapi => $c->objects->to_api($ticket) ); + } catch { $c->unhandled_exception($_); }; } @@ -179,7 +192,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 @@ -208,6 +221,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 651a12a6e7..47c366bb78 100644 --- a/api/v1/swagger/definitions/ticket.yaml +++ b/api/v1/swagger/definitions/ticket.yaml @@ -46,6 +46,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 5b3068d785..556f827ec0 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/cataloguing/concerns.tt @@ -104,6 +104,7 @@ "url": tickets_url }, "embed": [ + "assignee", "reporter", "resolver", "biblio", @@ -162,7 +163,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.39.5