From e4ecf7f10bc98870e4c402b0202e3c5e267e649a 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 | 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 52914723cba..b779f8372c1 100644 --- a/Koha/REST/V1/Tickets.pm +++ b/Koha/REST/V1/Tickets.pm @@ -116,12 +116,25 @@ 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), ); - } - 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($_); }; } @@ -197,7 +210,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 +239,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 59792e24bfc..836259485a0 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 dad68226f0a..6ea262997aa 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 651a12a6e74..47c366bb784 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 7e956643123..7851b4a69df 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 b28dc4fca01..a76239c66f4 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 5b3068d7854..556f827ec06 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.44.0