From 34cdc3d64e80484478d83ab996bdf6313febcf3c Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Tue, 21 Jun 2022 15:45:55 +0100 Subject: [PATCH] Bug 30719: Batch statuses This commits adds the following provision for batch statuses: - Database updates - Object definitions - CRUD REST API - Unit tests - UI adding support for batch statuses in batch UI - Admin UI for managing batch statuses Signed-off-by: Pedro Amorim --- Koha/Illbatch.pm | 16 + Koha/IllbatchStatus.pm | 162 ++++++++ Koha/IllbatchStatuses.pm | 61 +++ Koha/REST/V1/IllbatchStatuses.pm | 167 +++++++++ Koha/REST/V1/Illbatches.pm | 34 +- admin/ill_batch_statuses.pl | 102 +++++ api/v1/swagger/definitions/illbatch.yaml | 11 +- .../swagger/definitions/illbatchstatus.yaml | 20 + .../swagger/definitions/illbatchstatuses.yaml | 5 + api/v1/swagger/definitions/illrequest.yaml | 5 + api/v1/swagger/paths/illbatchstatuses.yaml | 232 ++++++++++++ api/v1/swagger/swagger.yaml | 17 + ill/ill-requests.pl | 6 +- .../atomicupdate/bug_30719_add_ill_batches.pl | 18 +- installer/data/mysql/kohastructure.sql | 16 +- .../mysql/mandatory/illbatch_statuses.sql | 5 + .../prog/en/includes/admin-menu.inc | 3 + .../en/includes/ill-batch-modal-strings.inc | 1 + .../prog/en/includes/ill-batch-modal.inc | 4 + .../prog/en/includes/ill-batch.inc | 3 +- .../prog/en/includes/ill-toolbar.inc | 2 +- .../prog/en/modules/admin/admin-home.tt | 4 + .../en/modules/admin/ill_batch_statuses.tt | 168 +++++++++ .../prog/en/modules/ill/ill-requests.tt | 6 +- .../intranet-tmpl/prog/js/ill-batch-modal.js | 78 +++- .../intranet-tmpl/prog/js/ill-batch-table.js | 14 +- t/db_dependent/IllbatchStatuses.t | 176 +++++++++ t/db_dependent/api/v1/illbatchstatuses.t | 352 ++++++++++++++++++ 28 files changed, 1660 insertions(+), 28 deletions(-) create mode 100644 Koha/IllbatchStatus.pm create mode 100644 Koha/IllbatchStatuses.pm create mode 100644 Koha/REST/V1/IllbatchStatuses.pm create mode 100755 admin/ill_batch_statuses.pl create mode 100644 api/v1/swagger/definitions/illbatchstatus.yaml create mode 100644 api/v1/swagger/definitions/illbatchstatuses.yaml create mode 100644 api/v1/swagger/paths/illbatchstatuses.yaml create mode 100644 installer/data/mysql/mandatory/illbatch_statuses.sql create mode 100644 koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt create mode 100755 t/db_dependent/IllbatchStatuses.t create mode 100755 t/db_dependent/api/v1/illbatchstatuses.t diff --git a/Koha/Illbatch.pm b/Koha/Illbatch.pm index c604661617..f0e427eec9 100644 --- a/Koha/Illbatch.pm +++ b/Koha/Illbatch.pm @@ -20,6 +20,7 @@ package Koha::Illbatch; use Modern::Perl; use Koha::Database; use Koha::Illrequest::Logger; +use Koha::IllbatchStatus; use JSON qw( to_json ); use base qw(Koha::Object); @@ -29,6 +30,21 @@ Koha::Illbatch - Koha Illbatch Object class =head2 Class methods +=head3 status + + my $status = Koha::Illbatch->status; + +Return the status object associated with this batch + +=cut + +sub status { + my ( $self ) = @_; + return Koha::IllbatchStatus->_new_from_dbic( + scalar $self->_result->statuscode + ); +} + =head3 patron my $patron = Koha::Illbatch->patron; diff --git a/Koha/IllbatchStatus.pm b/Koha/IllbatchStatus.pm new file mode 100644 index 0000000000..c49ec48703 --- /dev/null +++ b/Koha/IllbatchStatus.pm @@ -0,0 +1,162 @@ +package Koha::IllbatchStatus; + +# Copyright PTFS Europe 2022 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Koha::Database; +use Koha::Illrequest::Logger; +use Koha::Illbatch; +use JSON qw( to_json ); +use base qw(Koha::Object); + +=head1 NAME + +Koha::IllbatchStatus - Koha IllbatchStatus Object class + +=head2 Class methods + +=head3 create_and_log + + $status->create_and_log; + +Log batch status creation following storage + +=cut + +sub create_and_log { + my ( $self ) = @_; + + # Ensure code is uppercase and contains only word characters + my $fixed_code = uc $self->code; + $fixed_code =~ s/\W/_/; + + # Ensure this status doesn't already exist + my $status = Koha::IllbatchStatuses->find({ code => $fixed_code }); + if ($status) { + return { + error => "Duplicate status found" + }; + } + + # Ensure system statuses can't be created + $self->set({ + code => $fixed_code, + is_system => 0 + })->store; + + my $logger = Koha::Illrequest::Logger->new; + + $logger->log_something({ + modulename => 'ILL', + actionname => 'batch_status_create', + objectnumber => $self->id, + infos => to_json({}) + }); +} + +=head3 update_and_log + + $status->update_and_log; + +Log batch status update following storage + +=cut + +sub update_and_log { + my ( $self, $params ) = @_; + + my $before = { + name => $self->name + }; + + # Ensure only the name can be changed + $self->set({ + name => $params->{name} + }); + my $update = $self->store; + + my $after = { + name => $self->name + }; + + my $logger = Koha::Illrequest::Logger->new; + + $logger->log_something({ + modulename => 'ILL', + actionname => 'batch_status_update', + objectnumber => $self->id, + infos => to_json({ + before => $before, + after => $after + }) + }); +} + +=head3 delete_and_log + + $batch->delete_and_log; + +Log batch status delete + +=cut + +sub delete_and_log { + my ( $self ) = @_; + + # Don't permit deletion of system statuses + if ($self->is_system) { + return; + } + + # Update all batches that use this status to have status UNKNOWN + my $affected = Koha::Illbatches->search({ statuscode => $self->code }); + $affected->update({ statuscode => 'UNKNOWN'}); + + my $logger = Koha::Illrequest::Logger->new; + + $logger->log_something({ + modulename => 'ILL', + actionname => 'batch_status_delete', + objectnumber => $self->id, + infos => to_json({}) + }); + + $self->delete; +} + +=head2 Internal methods + +=head3 _type + + my $type = Koha::IllbatchStatus->_type; + +Return this object's type + +=cut + +sub _type { + return 'IllbatchStatus'; +} + +=head1 AUTHOR + +Andrew Isherwood + +=cut + +1; diff --git a/Koha/IllbatchStatuses.pm b/Koha/IllbatchStatuses.pm new file mode 100644 index 0000000000..1cbeedbd03 --- /dev/null +++ b/Koha/IllbatchStatuses.pm @@ -0,0 +1,61 @@ +package Koha::IllbatchStatuses; + +# Copyright PTFS Europe 2022 +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use Koha::Database; +use Koha::IllbatchStatus; +use base qw(Koha::Objects); + +=head1 NAME + +Koha::IllbatchStatuses - Koha IllbatchStatuses Object class + +=head2 Internal methods + +=head3 _type + + my $type = Koha::IllbatchStatuses->_type; + +Return this object's type + +=cut + +sub _type { + return 'IllbatchStatus'; +} + +=head3 object_class + + my $class = Koha::IllbatchStatuses->object_class; + +Return this object's class name + +=cut + +sub object_class { + return 'Koha::IllbatchStatus'; +} + +=head1 AUTHOR + +Andrew Isherwood + +=cut + +1; diff --git a/Koha/REST/V1/IllbatchStatuses.pm b/Koha/REST/V1/IllbatchStatuses.pm new file mode 100644 index 0000000000..28f398efb1 --- /dev/null +++ b/Koha/REST/V1/IllbatchStatuses.pm @@ -0,0 +1,167 @@ +package Koha::REST::V1::IllbatchStatuses; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Mojo::Base 'Mojolicious::Controller'; + +use Koha::IllbatchStatuses; + +=head1 NAME + +Koha::REST::V1::IllbatchStatuses + +=head2 Operations + +=head3 list + +Return a list of available ILL batch statuses + +=cut + +sub list { + my $c = shift->openapi->valid_input; + + my @statuses = Koha::IllbatchStatuses->search()->as_list; + + return $c->render( status => 200, openapi => \@statuses ); +} + +=head3 get + +Get one batch statuses + +=cut + +sub get { + my $c = shift->openapi->valid_input; + + my $status_code = $c->validation->param('illbatchstatus_code'); + + my $status = Koha::IllbatchStatuses->find({ code => $status_code }); + + if (not defined $status) { + return $c->render( + status => 404, + openapi => { error => "ILL batch status not found" } + ); + } + + return $c->render( + status => 200, + openapi => { + %{$status->unblessed} + } + ); +} + +=head3 add + +Add a new batch status + +=cut + +sub add { + my $c = shift->openapi->valid_input or return; + + my $body = $c->validation->param('body'); + + my $status = Koha::IllbatchStatus->new( $body ); + + return try { + my $return = $status->create_and_log; + if ($return && $return->{error}) { + return $c->render( + status => 500, + openapi => $return + ); + } else { + return $c->render( + status => 201, + openapi => $status + ); + } + } + catch { + $c->unhandled_exception($_); + }; +} + +=head3 update + +Update a batch status + +=cut + +sub update { + my $c = shift->openapi->valid_input or return; + + my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param('illbatchstatus_code') }); + + if ( not defined $status ) { + return $c->render( + status => 404, + openapi => { error => "ILL batch status not found" } + ); + } + + my $params = $c->req->json; + + return try { + # Only permit updating of name + $status->update_and_log({ name => $params->{name} }); + + return $c->render( + status => 200, + openapi => $status + ); + } + catch { + $c->unhandled_exception($_); + }; +} + +=head3 delete + +Delete a batch status + +=cut + +sub delete { + + my $c = shift->openapi->valid_input or return; + + my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param( 'illbatchstatus_code' ) }); + + if ( not defined $status ) { + return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } ); + } + + if ( $status->is_system) { + return $c->render( status => 400, openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] } ); + } + + return try { + $status->delete_and_log; + return $c->render( status => 204, openapi => ''); + } + catch { + $c->unhandled_exception($_); + }; +} + +1; diff --git a/Koha/REST/V1/Illbatches.pm b/Koha/REST/V1/Illbatches.pm index e2b175e241..f75eba5f78 100644 --- a/Koha/REST/V1/Illbatches.pm +++ b/Koha/REST/V1/Illbatches.pm @@ -20,6 +20,7 @@ use Modern::Perl; use Mojo::Base 'Mojolicious::Controller'; use Koha::Illbatches; +use Koha::IllbatchStatuses; use Koha::Illrequests; =head1 NAME @@ -63,15 +64,29 @@ sub list { branchcode => { -in => \@branchcodes } }); + # Get all batch statuses associated with all our batches + # in one go + my $statuses = {}; + foreach my $batch(@batches) { + my $code = $batch->statuscode; + $statuses->{$code} = 1 + }; + my @statuscodes = keys %{$statuses}; + my $status_results = Koha::IllbatchStatuses->search({ + code => { -in => \@statuscodes } + }); + # Populate the response my @to_return = (); foreach my $it_batch(@batches) { my $patron = $patron_results->find({ borrowernumber => $it_batch->borrowernumber}); my $branch = $branch_results->find({ branchcode => $it_batch->branchcode }); + my $status = $status_results->find({ code => $it_batch->statuscode }); push @to_return, { %{$it_batch->unblessed}, - patron => $patron, - branch => $branch, + patron => $patron, + branch => $branch, + status => $status, requests_count => $it_batch->requests_count }; } @@ -103,8 +118,9 @@ sub get { status => 200, openapi => { %{$batch->unblessed}, - patron => $batch->patron->unblessed, - branch => $batch->branch->unblessed, + patron => $batch->patron->unblessed, + branch => $batch->branch->unblessed, + status => $batch->status->unblessed, requests_count => $batch->requests_count } ); @@ -134,8 +150,9 @@ sub add { my $ret = { %{$batch->unblessed}, - patron => $batch->patron->unblessed, - branch => $batch->branch->unblessed, + patron => $batch->patron->unblessed, + branch => $batch->branch->unblessed, + status => $batch->status->unblessed, requests_count => 0 }; @@ -175,8 +192,9 @@ sub update { my $ret = { %{$batch->unblessed}, - patron => $batch->patron->unblessed, - branch => $batch->branch->unblessed, + patron => $batch->patron->unblessed, + branch => $batch->branch->unblessed, + status => $batch->status->unblessed, requests_count => $batch->requests_count }; diff --git a/admin/ill_batch_statuses.pl b/admin/ill_batch_statuses.pl new file mode 100755 index 0000000000..bf16b06ded --- /dev/null +++ b/admin/ill_batch_statuses.pl @@ -0,0 +1,102 @@ +#! /usr/bin/perl + +# Copyright 2019 Koha Development Team +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; +use CGI qw ( -utf8 ); +use Try::Tiny qw( catch try ); + +use C4::Context; +use C4::Auth qw( get_template_and_user ); +use C4::Output qw( output_html_with_http_headers ); + +use Koha::IllbatchStatus; +use Koha::IllbatchStatuses; + +my $input = CGI->new; +my $code = $input->param('code'); +my $op = $input->param('op') || 'list'; +my @messages; + +my ( $template, $loggedinuser, $cookie ) = get_template_and_user( + { + template_name => "admin/ill_batch_statuses.tt", + query => $input, + type => "intranet", + flagsrequired => { parameters => 'ill' }, + } +); + +my $status; +if ($code) { + $status = Koha::IllbatchStatuses->find({ code => $code }); +} + +if ( $op eq 'add_form' ) { + if ($status) { + $template->param( + status => $status + ); + } +} +elsif ( $op eq 'add_validate' ) { + my $name = $input->param('name'); + my $code = $input->param('code'); + + if ( not defined $status ) { + $status = Koha::IllbatchStatus->new( { + name => $name, + code => $code + } ); + } + + try { + if ($status->id) { + $status->update_and_log({ name => $name }); + } else { + $status->create_and_log; + } + push @messages, { type => 'message', code => 'success_on_saving' }; + } + catch { + push @messages, { type => 'error', code => 'error_on_saving' }; + }; + $op = 'list'; +} +elsif ( $op eq 'delete' ) { + try { + $status->delete_and_log; + push @messages, { code => 'success_on_delete', type => 'message' }; + } + catch { + push @messages, { code => 'error_on_delete', type => 'alert' }; + + }; + $op = 'list'; +} +if ( $op eq 'list' ) { + my $statuses = Koha::IllbatchStatuses->search(); + $template->param( statuses => $statuses ); +} + +$template->param( + messages => \@messages, + op => $op, +); + +output_html_with_http_headers $input, $cookie, $template->output; diff --git a/api/v1/swagger/definitions/illbatch.yaml b/api/v1/swagger/definitions/illbatch.yaml index 2248beae54..d3146a3303 100644 --- a/api/v1/swagger/definitions/illbatch.yaml +++ b/api/v1/swagger/definitions/illbatch.yaml @@ -29,6 +29,14 @@ properties: - object - "null" description: The branch associated with the batch + statuscode: + type: string + description: Code of the status of the ILL batch + status: + type: + - object + - "null" + description: The status associated with the batch requests_count: type: string description: The number of requests in this batch @@ -36,4 +44,5 @@ additionalProperties: false required: - name - backend - - branchcode \ No newline at end of file + - branchcode + - statuscode \ No newline at end of file diff --git a/api/v1/swagger/definitions/illbatchstatus.yaml b/api/v1/swagger/definitions/illbatchstatus.yaml new file mode 100644 index 0000000000..42b2452551 --- /dev/null +++ b/api/v1/swagger/definitions/illbatchstatus.yaml @@ -0,0 +1,20 @@ +--- +type: object +properties: + id: + type: string + description: Internal ILL batch status identifier + name: + type: string + description: Status name + code: + type: string + description: Unique, immutable status code + is_system: + type: string + description: Is this status required for system operation +additionalProperties: false +required: + - name + - code + - is_system diff --git a/api/v1/swagger/definitions/illbatchstatuses.yaml b/api/v1/swagger/definitions/illbatchstatuses.yaml new file mode 100644 index 0000000000..5eb4b53400 --- /dev/null +++ b/api/v1/swagger/definitions/illbatchstatuses.yaml @@ -0,0 +1,5 @@ +--- +type: array +items: + $ref: "illbatchstatus.yaml" +additionalProperties: false diff --git a/api/v1/swagger/definitions/illrequest.yaml b/api/v1/swagger/definitions/illrequest.yaml index 1d7be94537..c37f7a30d3 100644 --- a/api/v1/swagger/definitions/illrequest.yaml +++ b/api/v1/swagger/definitions/illrequest.yaml @@ -141,4 +141,9 @@ properties: - string - "null" description: The timestamp the request was last updated (formatted for display) + due_date: + type: + - string + - "null" + description: The hard due date of an ILL request additionalProperties: false \ No newline at end of file diff --git a/api/v1/swagger/paths/illbatchstatuses.yaml b/api/v1/swagger/paths/illbatchstatuses.yaml new file mode 100644 index 0000000000..f211b2b62d --- /dev/null +++ b/api/v1/swagger/paths/illbatchstatuses.yaml @@ -0,0 +1,232 @@ +--- +/illbatchstatuses: + get: + x-mojo-to: IllbatchStatuses#list + operationId: listIllbatchstatuses + tags: + - illbatchstatuses + summary: List ILL batch statuses + parameters: [] + produces: + - application/json + responses: + "200": + description: A list of ILL batch statuses + schema: + $ref: "../swagger.yaml#/definitions/illbatchstatuses" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: ILL batch statuses not found + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + ill: "1" + post: + x-mojo-to: IllbatchStatuses#add + operationId: addIllbatchstatus + tags: + - illbatchstatuses + summary: Add ILL batch status + parameters: + - name: body + in: body + description: A JSON object containing informations about the new batch status + required: true + schema: + $ref: "../swagger.yaml#/definitions/illbatchstatus" + produces: + - application/json + responses: + "201": + description: Batch status added + schema: + $ref: "../swagger.yaml#/definitions/illbatchstatus" + "400": + description: Bad request + schema: + $ref: "../swagger.yaml#/definitions/error" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "409": + description: Conflict in creating resource + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + ill: "1" +"/illbatchstatuses/{illbatchstatus_code}": + get: + x-mojo-to: IllbatchStatuses#get + operationId: getIllbatchstatuses + tags: + - illbatchstatuses + summary: Get ILL batch status + parameters: + - name: illbatchstatus_code + in: path + description: ILL batch status + required: true + type: string + produces: + - application/json + responses: + "200": + description: An ILL batch status + schema: + $ref: "../swagger.yaml#/definitions/illbatchstatus" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: ILL batch status not found + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + ill: "1" + put: + x-mojo-to: IllbatchStatuses#update + operationId: updateIllBatchstatus + tags: + - illbatchstatuses + summary: Update batch status + parameters: + - $ref: "../swagger.yaml#/parameters/illbatchstatus_code_pp" + - name: body + in: body + description: A JSON object containing information on the batch status + required: true + schema: + $ref: "../swagger.yaml#/definitions/illbatchstatus" + consumes: + - application/json + produces: + - application/json + responses: + "200": + description: An ILL batch status + schema: + $ref: "../swagger.yaml#/definitions/illbatchstatus" + "400": + description: Bad request + schema: + $ref: "../swagger.yaml#/definitions/error" + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: ILL batch status not found + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + ill: "1" + delete: + x-mojo-to: IllbatchStatuses#delete + operationId: deleteBatchstatus + tags: + - illbatchstatuses + summary: Delete ILL batch status + parameters: + - $ref: "../swagger.yaml#/parameters/illbatchstatus_code_pp" + produces: + - application/json + responses: + "204": + description: ILL batch status deleted + schema: + type: string + "401": + description: Authentication required + schema: + $ref: "../swagger.yaml#/definitions/error" + "403": + description: Access forbidden + schema: + $ref: "../swagger.yaml#/definitions/error" + "404": + description: ILL batch status not found + schema: + $ref: "../swagger.yaml#/definitions/error" + "500": + description: | + Internal server error. Possible `error_code` attribute values: + + * `internal_server_error` + schema: + $ref: "../swagger.yaml#/definitions/error" + "503": + description: Under maintenance + schema: + $ref: "../swagger.yaml#/definitions/error" + x-koha-authorization: + permissions: + ill: "1" diff --git a/api/v1/swagger/swagger.yaml b/api/v1/swagger/swagger.yaml index 7a860a71bd..d3de4b1c7e 100644 --- a/api/v1/swagger/swagger.yaml +++ b/api/v1/swagger/swagger.yaml @@ -52,6 +52,10 @@ definitions: $ref: ./definitions/illbatch.yaml illbatches: $ref: ./definitions/illbatches.yaml + illbatchstatus: + $ref: ./definitions/illbatchstatus.yaml + illbatchstatuses: + $ref: ./definitions/illbatchstatuses.yaml illrequest: $ref: ./definitions/illrequest.yaml illrequests: @@ -237,6 +241,10 @@ paths: $ref: ./paths/illbatches.yaml#/~1illbatches "/illbatches/{illbatch_id}": $ref: "./paths/illbatches.yaml#/~1illbatches~1{illbatch_id}" + /illbatchstatuses: + $ref: ./paths/illbatchstatuses.yaml#/~1illbatchstatuses + "/illbatchstatuses/{illbatchstatus_code}": + $ref: "./paths/illbatchstatuses.yaml#/~1illbatchstatuses~1{illbatchstatus_code}" /illrequests: $ref: ./paths/illrequests.yaml#/~1illrequests "/import_batches/{import_batch_id}/records/{import_record_id}/matches/chosen": @@ -438,6 +446,12 @@ parameters: name: illbatch_id required: true type: integer + illbatchstatus_code_pp: + description: Internal ILL batch status identifier + in: path + name: illbatchstatus_code + required: true + type: string import_batch_profile_id_pp: description: Internal profile identifier in: path @@ -734,6 +748,9 @@ tags: - description: "Manage ILL module batches\n" name: illbatches x-displayName: ILL batches + - description: "Manage ILL module batch statuses\n" + name: illbatchstatuses + x-displayName: ILL batch statuses - description: "Manage ILL requests\n" name: illrequests x-displayName: ILL requests diff --git a/ill/ill-requests.pl b/ill/ill-requests.pl index 62601aadb6..136a8c4eb4 100755 --- a/ill/ill-requests.pl +++ b/ill/ill-requests.pl @@ -28,6 +28,7 @@ use Koha::AuthorisedValues; use Koha::Illcomment; use Koha::Illrequests; use Koha::Illbatches; +use Koha::IllbatchStatuses; use Koha::Illrequest::Availability; use Koha::Libraries; use Koha::Token; @@ -454,8 +455,9 @@ if ( $backends_available ) { ); exit; } elsif ( $op eq "batch_list" ) { + # Do not remove, it prevents us falling through to the 'else' } elsif ( $op eq "batch_create" ) { - # Batch create + # Do not remove, it prevents us falling through to the 'else' } else { my $request = Koha::Illrequests->find($params->{illrequest_id}); my $backend_result = $request->custom_capability($op, $params); @@ -567,4 +569,4 @@ sub get_ill_availability { return $availability->get_services({ ui_context => 'staff' }); -} \ No newline at end of file +} diff --git a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl b/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl index 0d8846c694..fa6dc47e43 100755 --- a/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl +++ b/installer/data/mysql/atomicupdate/bug_30719_add_ill_batches.pl @@ -7,16 +7,27 @@ return { my ($args) = @_; my ($dbh, $out) = @$args{qw(dbh out)}; $dbh->do(q{ - CREATE TABLE `illbatches` ( + CREATE TABLE IF NOT EXISTS `illbatches` ( `id` int(11) NOT NULL auto_increment, -- Batch ID `name` varchar(100) NOT NULL, -- Unique name of batch `backend` varchar(20) NOT NULL, -- Name of batch backend `borrowernumber` int(11), -- Patron associated with batch `branchcode` varchar(50), -- Branch associated with batch + `statuscode` varchar(20), -- Status of batch PRIMARY KEY (`id`), UNIQUE KEY `u_illbatches__name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci }); + $dbh->do(q{ + CREATE TABLE IF NOT EXISTS `illbatch_statuses` ( + `id` int(11) NOT NULL auto_increment, -- Status ID + `name` varchar(100) NOT NULL, -- Name of status + `code` varchar(20) NOT NULL, -- Unique, immutable code for status + `is_system` int(1), -- Is this status required for system operation + PRIMARY KEY (`id`), + UNIQUE KEY `u_illbatchstatuses__code` (`code`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci + }); $dbh->do(q{ ALTER TABLE `illrequests` ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to @@ -33,6 +44,11 @@ return { ALTER TABLE `illbatches` ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE }); + $dbh->do(q{ + ALTER TABLE `illbatches` + ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE + }); + say $out "Bug 30719: Add ILL batches completed" }, }; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index ad05b24458..9d85ed5280 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -3226,6 +3226,18 @@ CREATE TABLE `illrequestattributes` ( CONSTRAINT `illrequestattributes_ifk` FOREIGN KEY (`illrequest_id`) REFERENCES `illrequests` (`illrequest_id`) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `illbatch_statuses` +-- +DROP TABLE IF EXISTS `illbatch_statuses`; +CREATE TABLE `illbatch_statuses` ( + `id` int(11) NOT NULL auto_increment, -- Status ID + `name` varchar(100) NOT NULL, -- Name of status + `code` varchar(20) NOT NULL, -- Unique, immutable code for status + `is_system` int(1), -- Is this status required for system operation + PRIMARY KEY (`id`), + UNIQUE KEY `u_illbatchstatuses__code` (`code`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- -- Table structure for table `illbatches` @@ -3237,10 +3249,12 @@ CREATE TABLE `illbatches` ( `backend` varchar(20) NOT NULL, -- Name of batch backend `borrowernumber` int(11), -- Patron associated with batch `branchcode` varchar(50), -- Branch associated with batch + `statuscode` varchar(20), -- Status of batch PRIMARY KEY (`id`), UNIQUE KEY `u_illbatches__name` (`name`), CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE, - CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE + CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE, + CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -- diff --git a/installer/data/mysql/mandatory/illbatch_statuses.sql b/installer/data/mysql/mandatory/illbatch_statuses.sql new file mode 100644 index 0000000000..8c6288eb8b --- /dev/null +++ b/installer/data/mysql/mandatory/illbatch_statuses.sql @@ -0,0 +1,5 @@ +INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES +('New', 'NEW', 1), +('In progress', 'IN_PROGRESS', 1), +('Completed', 'COMPLETED', 1), +('Unknown', 'UNKNOWN', 1); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc index 9c9a24c545..b98ce7e37e 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/admin-menu.inc @@ -177,6 +177,9 @@ [% IF ( Koha.Preference('EnableAdvancedCatalogingEditor') && CAN_user_parameters_manage_keyboard_shortcuts ) %]
  • Keyboard shortcuts
  • [% END %] + [% IF Koha.Preference('ILLModule ') && CAN_user_ill %] +
  • Interlibrary Loan batch statuses
  • + [% END %] [% END %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc index 070ffaffc4..98d48daaea 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal-strings.inc @@ -5,6 +5,7 @@ var ill_batch_none = _("None"); var ill_batch_retrieving_metadata = _("Retrieving metadata"); var ill_batch_api_fail = _("Unable to retrieve batch details"); + var ill_batch_statuses_api_fail = _("Unable to retrieve batch statuses"); var ill_batch_api_request_fail = _("Unable to create local request"); var ill_batch_requests_api_fail = _("Unable to retrieve batch requests"); var ill_batch_unknown = _("Unknown"); diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal.inc index c3556fb06b..f0abfa8a64 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch-modal.inc @@ -28,6 +28,10 @@ [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode ) %] +