Bugzilla – Attachment 144288 Details for
Bug 30719
ILL should provide the ability to create batch requests
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30719: Batch statuses
0001-Bug-30719-Batch-statuses.patch (text/plain), 72.10 KB, created by
Pedro Amorim
on 2022-11-28 15:52:31 UTC
(
hide
)
Description:
Bug 30719: Batch statuses
Filename:
MIME Type:
Creator:
Pedro Amorim
Created:
2022-11-28 15:52:31 UTC
Size:
72.10 KB
patch
obsolete
>From 374cd1d83d32b21e63ce9fff1f4352c8bf2b9c00 Mon Sep 17 00:00:00 2001 >From: Andrew Isherwood <andrew.isherwood@ptfs-europe.com> >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 >--- > 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 <http://www.gnu.org/licenses>. >+ >+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 <andrew.isherwood@ptfs-europe.com> >+ >+=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 <http://www.gnu.org/licenses>. >+ >+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 <andrew.isherwood@ptfs-europe.com> >+ >+=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 <http://www.gnu.org/licenses>. >+ >+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 <http://www.gnu.org/licenses>. >+ >+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 ) %] > <li><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></li> > [% END %] >+ [% IF Koha.Preference('ILLModule ') && CAN_user_ill %] >+ <li><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></li> >+ [% END %] > </ul> > [% END %] > </div> >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 ) %] > </select> > </li> >+ <li id="batch_statuscode" style="display:none"> >+ <label class="required" for="statuscode">Status:</label> >+ <select id="statuscode" name="statuscode"></select> >+ </li> > </ol> > </fieldset> > <fieldset id="add_batch_items" class="rows" style="display:none"> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch.inc >index 429de84596..8c0ca21e74 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-batch.inc >@@ -6,6 +6,7 @@ > <th scope="col">Batch ID</th> > <th scope="col">Name</th> > <th scope="col">Number of requests</th> >+ <th scope="col">Status</th> > <th scope="col">Patron</th> > <th scope="col">Branch</th> > <th scope="col"></th> >@@ -15,6 +16,4 @@ > </tbody> > </table> > </div> >-[% ELSIF query_type == "batch_create" %] >- > [% END %] >\ No newline at end of file >diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc >index 94e45c4e65..ffc6055071 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc >+++ b/koha-tmpl/intranet-tmpl/prog/en/includes/ill-toolbar.inc >@@ -1,5 +1,5 @@ > [% USE Koha %] >-[% IF Koha.Preference('ILLModule ') && CAN_user_ill %] >+[% IF Koha.Preference('ILLModule') && CAN_user_ill %] > <div id="toolbar" class="btn-toolbar ill-toolbar"> > [% IF backends_available %] > [% IF backends.size > 1 %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >index 0e83b36721..399b99d8e2 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt >@@ -287,6 +287,10 @@ > <dt><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></dt> > <dd>Define which keys trigger actions in the advanced cataloging editor</dd> > [% END %] >+ [% IF Koha.Preference('ILLModule') && CAN_user_ill %] >+ <dt><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></dt> >+ <dd>Manage the statuses that can be assigned to Interlibrary Loan batches</dd> >+ [% END %] > </dl> > [% END %] > </div> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt >new file mode 100644 >index 0000000000..0bf6e5f53d >--- /dev/null >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/ill_batch_statuses.tt >@@ -0,0 +1,168 @@ >+[% USE raw %] >+[% USE Asset %] >+[% USE Branches %] >+[% USE Price %] >+[% SET footerjs = 1 %] >+[% INCLUDE 'doc-head-open.inc' %] >+<title> >+ [% IF op =='add_form' %] >+ [% IF status.id %] >+ Modify batch status >+ [% ELSE %] >+ New batch status >+ [% END %] › [% END %] >+ Interlibrary Loan batch statuses › Administration › Koha >+</title> >+[% INCLUDE 'doc-head-close.inc' %] >+</head> >+ >+<body id="admin_ill_batch_statuses" class="admin"> >+[% INCLUDE 'header.inc' %] >+[% INCLUDE 'prefs-admin-search.inc' %] >+ >+<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb"> >+ <ol> >+ <li> >+ <a href="/cgi-bin/koha/mainpage.pl">Home</a> >+ </li> >+ <li> >+ <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a> >+ </li> >+ >+ [% IF op == 'add_form' %] >+ <li> >+ <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a> >+ </li> >+ <li> >+ <a href="#" aria-current="page"> >+ [% IF status.id %] >+ Modify >+ [% ELSE %] >+ New >+ [% END %] batch status >+ </a> >+ </li> >+ >+ [% ELSE %] >+ <li> >+ <a href="#" aria-current="page"> >+ Interlibrary Loan batch statuses >+ </a> >+ </li> >+ [% END %] >+ </ol> >+</nav> >+ >+<div class="main container-fluid"> >+ <div class="row"> >+ <div class="col-sm-10 col-sm-push-2"> >+ <main> >+ >+ [% FOREACH m IN messages %] >+ <div class="dialog [% m.type | html %]"> >+ [% SWITCH m.code %] >+ [% CASE 'success_on_saving' %] >+ <span>Batch status saved successfully</span> >+ [% CASE 'success_on_delete' %] >+ <span>Batch status deleted successfully</span> >+ [% CASE 'error_on_saving' %] >+ <span>An error occurred when saving this batch status</span> >+ [% CASE 'error_on_delete' %] >+ <span>An error occurred when deleting this batch status</span> >+ [% CASE %] >+ <span>[% m.code | html %]</span> >+ [% END %] >+ </div> >+ [% END %] >+ >+ [% IF op == 'add_form' %] >+ [% IF status %] >+ <h1>Modify a batch status</h1> >+ [% ELSE %] >+ <h1>New batch status</h1> >+ [% END %] >+ >+ <form action="/cgi-bin/koha/admin/ill_batch_statuses.pl" name="Aform" method="post" class="validated"> >+ <input type="hidden" name="op" value="add_validate" /> >+ <fieldset class="rows"> >+ <ol> >+ <li> >+ <label for="name" class="required">Name: </label> >+ <input type="text" name="name" id="name" size="80" maxlength="100" class="required focus" required="required" value="[% status.name | html %]"><span class="required">Required. Maximum length is 100 letters</span> >+ </li> >+ <li> >+ <label for="code">Code: </label> >+ [% IF status %] >+ <strong>[% status.code | html %]</strong> >+ <input type="hidden" name="code" value="[% status.code | html %]" /> >+ [% ELSE %] >+ <input type="text" name="code" id="code" size="80" maxlength="20" class="required" required="required" value="[% status.code | html %]"><span class="required">Required, specify UPPERCASE LETTERS. Maximum length is 20 letters</span> >+ [% END %] >+ </li> >+ <li> >+ <label for="is_system">Is a system status: </label> >+ <strong>[% status.is_system ? "Yes" : "No" | html %]</strong> >+ <input type="hidden" name="is_system" value="[% status.is_system | html %]" /> >+ </li> >+ </ol> >+ </fieldset> >+ >+ <fieldset class="action"> >+ <button id="save_batch_status" class="btn btn-default">Save</button> >+ <a class="cancel" href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Cancel</a> >+ </fieldset> >+ </form> >+ [% END %] >+ >+ [% IF op == 'list' %] >+ <div id="toolbar" class="btn-toolbar"> >+ <a class="btn btn-default" id="newillbatchstatus" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form"><i class="fa fa-plus"></i> New batch status</a> >+ </div> >+ >+ <h1>Interlibrary Loan batch statuses</h1> >+ [% IF statuses.count %] >+ <table id="table_batch_statuses"> >+ <thead> >+ <th>Name</th> >+ <th>Code</th> >+ <th>Is system</th> >+ <th class="noExport">Actions</th> >+ </thead> >+ <tbody> >+ [% FOREACH status IN statuses %] >+ <tr> >+ <td>[% status.name | html %]</td> >+ <td>[% name.code | html %]</td> >+ <td>[% status.is_system ? "Yes" : "No" | html %]</td> >+ <td class="actions"> >+ <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form&code=[% status.code | uri %]"><i class="fa fa-pencil"></i> Edit</a> >+ [% IF !status.is_system %] >+ <a class="btn btn-default btn-xs" href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=delete&code=[% status.code | uri %]"><i class="fa fa-delete"></i> Delete</a> >+ [% END %] >+ </td> >+ </tr> >+ [% END %] >+ </tbody> >+ </table> >+ [% ELSE %] >+ <div class="dialog message"> >+ There are no batch statuses defined. <a href="/cgi-bin/koha/admin/debit_types.pl?op=add_form">Create new batch status</a> >+ </div> >+ [% END %] >+ [% END %] >+ </main> >+ </div> <!-- /.col-sm-10.col-sm-push-2 --> >+ >+ <div class="col-sm-2 col-sm-pull-10"> >+ <aside> >+ [% INCLUDE 'admin-menu.inc' %] >+ </aside> >+ </div> <!-- /.col-sm-2.col-sm-pull-10 --> >+ </div> <!-- /.row --> >+ >+[% MACRO jsinclude BLOCK %] >+ [% Asset.js("js/admin-menu.js") | $raw %] >+ [% INCLUDE 'datatables.inc' %] >+[% END %] >+ >+[% INCLUDE 'intranet-bottom.inc' %] >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >index 7ceeb7722a..64feb460ac 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/ill/ill-requests.tt >@@ -877,10 +877,12 @@ > <script> > var metadata_enrichment_services = [% metadata_enrichment_services | $raw %]; > </script> >- [% END %] >- [% IF batch_availability_services %] > <script> >+ [% IF batch_availability_services %] > var batch_availability_services = [% batch_availability_services | $raw %]; >+ [% ELSE %] >+ var batch_availability_services = []; >+ [% END %] > </script> > [% END %] > <script> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js b/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js >index d09d660915..70f9e29c5a 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/ill-batch-modal.js >@@ -19,6 +19,7 @@ > var createProgressBar = document.getElementById("processed_progress_bar"); > var identifierTable = document.getElementById('identifier-table'); > var createRequestsButton = document.getElementById('create-requests-button'); >+ var statusesSelect = document.getElementById('statuscode'); > > > // We need a data structure keyed on identifier type, which tells us how to parse that >@@ -40,7 +41,8 @@ > name: '', > backend: null, > cardnumber: '', >- branchcode: '' >+ branchcode: '', >+ statuscode: 'NEW' > }; > > // The object that holds the batch we're working with >@@ -59,6 +61,7 @@ > setFinishButton(); > disableCardnumberInput(); > displayPatronName(); >+ updateStatusesSelect(); > } > } > ); >@@ -82,6 +85,22 @@ > } > ); > >+ // The object that holds the contents of the table >+ // It's a proxy so we can update portions of the UI >+ // upon changes >+ var statuses = new Proxy( >+ { data: [] }, >+ { >+ get: function (obj, prop) { >+ return obj[prop]; >+ }, >+ set: function (obj, prop, value) { >+ obj[prop] = value; >+ updateStatusesSelect(); >+ } >+ } >+ ); >+ > var progressTotals = new Proxy( > { > data: {} >@@ -105,6 +124,9 @@ > // so we don't duplicate them > var availabilitySent = {}; > >+ // Are we updating an existing batch >+ var isUpdate = false; >+ > // The datatable > var table; > var tableEl = document.getElementById('identifier-table'); >@@ -155,11 +177,13 @@ > }; > if (batchId) { > fetchBatch(); >- setModalHeading(true); >+ isUpdate = true; >+ setModalHeading(); > } else { > batch.data = emptyBatch; > setModalHeading(); > } >+ fetchStatuses(); > finishButtonEventListener(); > processButtonEventListener(); > identifierTextareaEventListener(); >@@ -178,7 +202,7 @@ > } > }; > >- function setModalHeading(isUpdate) { >+ function setModalHeading() { > var heading = document.getElementById('ill-batch-modal-label'); > heading.textContent = isUpdate ? ill_batch_update : ill_batch_add; > } >@@ -323,6 +347,24 @@ > } > }; > >+ function updateStatusesSelect() { >+ while (statusesSelect.options.length > 0) { >+ statusesSelect.remove(0); >+ } >+ statuses.data.forEach(function (status) { >+ var option = document.createElement('option') >+ option.value = status.code; >+ option.text = status.name; >+ if (batch.data.id && batch.data.statuscode === status.code) { >+ option.selected = true; >+ } >+ statusesSelect.add(option); >+ }); >+ if (isUpdate) { >+ statusesSelect.parentElement.style.display = 'block'; >+ } >+ }; >+ > function removeEventListeners() { > textarea.removeEventListener('paste', processButtonState); > textarea.removeEventListener('keyup', processButtonState); >@@ -414,6 +456,20 @@ > }); > }; > >+ // Get all batch statuses >+ function fetchStatuses() { >+ window.doApiRequest('/api/v1/illbatchstatuses') >+ .then(function (response) { >+ return response.json(); >+ }) >+ .then(function (jsoned) { >+ statuses.data = jsoned; >+ }) >+ .catch(function (e) { >+ window.handleApiError(ill_batch_statuses_api_fail); >+ }); >+ }; >+ > // Get the batch > function fetchBatch() { > window.doBatchApiRequest("/" + batchId) >@@ -426,7 +482,8 @@ > name: jsoned.name, > backend: jsoned.backend, > cardnumber: jsoned.cardnumber, >- branchcode: jsoned.branchcode >+ branchcode: jsoned.branchcode, >+ statuscode: jsoned.statuscode > } > return jsoned; > }) >@@ -436,11 +493,11 @@ > .catch(function () { > window.handleApiError(ill_batch_api_fail); > }); >- > }; > > function createBatch() { > var selectedBranchcode = branchcodeSelect.selectedOptions[0].value; >+ var selectedStatuscode = statusesSelect.selectedOptions[0].value; > return doBatchApiRequest('', { > method: 'POST', > headers: { >@@ -450,7 +507,8 @@ > name: nameInput.value, > backend: backend, > cardnumber: cardnumberInput.value, >- branchcode: selectedBranchcode >+ branchcode: selectedBranchcode, >+ statuscode: selectedStatuscode > }) > }) > .then(function (response) { >@@ -464,7 +522,9 @@ > backend: body.backend, > cardnumber: body.patron.cardnumber, > branchcode: body.branchcode, >- patron: body.patron >+ statuscode: body.statuscode, >+ patron: body.patron, >+ status: body.status > }; > initPostCreate(); > }) >@@ -475,6 +535,7 @@ > > function updateBatch() { > var selectedBranchcode = branchcodeSelect.selectedOptions[0].value; >+ var selectedStatuscode = statusesSelect.selectedOptions[0].value; > return doBatchApiRequest('/' + batch.data.id, { > method: 'PUT', > headers: { >@@ -484,7 +545,8 @@ > name: nameInput.value, > backend: batch.data.backend, > cardnumber: batch.data.patron.cardnumber, >- branchcode: selectedBranchcode >+ branchcode: selectedBranchcode, >+ statuscode: selectedStatuscode > }) > }) > .catch(function () { >diff --git a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-table.js b/koha-tmpl/intranet-tmpl/prog/js/ill-batch-table.js >index 502965677f..b6a12e32ee 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/ill-batch-table.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/ill-batch-table.js >@@ -57,10 +57,15 @@ > data: 'requests_count', > width: '10%' > }, >+ { >+ data: 'status', >+ render: createStatus, >+ width: '10%' >+ }, > { > data: 'patron', > render: createPatronLink, >- width: '20%' >+ width: '10%' > }, > { > data: 'branch', >@@ -82,7 +87,7 @@ > // A render function for branch name > var createBranch = function (data) { > return data.branchname; >- } >+ }; > > // A render function for batch name > var createName = function (x, y, data) { >@@ -93,6 +98,11 @@ > return a.outerHTML; > }; > >+ // A render function for batch status >+ var createStatus = function (x, y, data) { >+ return data.status.name; >+ }; >+ > // A render function for our patron link > var createPatronLink = function (data) { > var link = document.createElement('a'); >diff --git a/t/db_dependent/IllbatchStatuses.t b/t/db_dependent/IllbatchStatuses.t >new file mode 100755 >index 0000000000..a0378e0279 >--- /dev/null >+++ b/t/db_dependent/IllbatchStatuses.t >@@ -0,0 +1,176 @@ >+#s!/usr/bin/perl >+ >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use File::Basename qw/basename/; >+use Koha::Database; >+use Koha::IllbatchStatus; >+use Koha::IllbatchStatuses; >+use Koha::Patrons; >+use Koha::Libraries; >+use t::lib::Mocks; >+use t::lib::TestBuilder; >+use Test::MockObject; >+use Test::MockModule; >+ >+use Test::More tests => 12; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+use_ok('Koha::IllbatchStatus'); >+use_ok('Koha::IllbatchStatuses'); >+ >+$schema->storage->txn_begin; >+ >+Koha::IllbatchStatuses->search->delete; >+ >+# Keep track of whether our CRUD logging side-effects are happening >+my $effects = { >+ batch_status_create => 0, >+ batch_status_update => 0, >+ batch_status_delete => 0 >+}; >+ >+# Mock a logger so we can check it is called >+my $logger = Test::MockModule->new('Koha::Illrequest::Logger'); >+$logger->mock('log_something', sub { >+ my ($self, $to_log ) = @_; >+ $effects->{$to_log->{actionname}} ++; >+}); >+ >+# Create a batch status >+my $status = $builder->build({ >+ source => 'IllbatchStatus', >+ value => { >+ name => "Feeling the call to the Dark Side", >+ code => "OH_NO", >+ is_system => 1 >+ } >+}); >+ >+my $status_obj = Koha::IllbatchStatuses->find({ code => $status->{code} }); >+isa_ok( $status_obj, 'Koha::IllbatchStatus' ); >+ >+# Try to delete the status, it's a system status, so this should fail >+$status_obj->delete_and_log; >+my $status_obj_del = Koha::IllbatchStatuses->find({ code => $status->{code} }); >+isa_ok( $status_obj_del, 'Koha::IllbatchStatus' ); >+ >+## Status create >+ >+# Try creating a duplicate status >+my $status2 = Koha::IllbatchStatus->new({ >+ name => "Obi-wan", >+ code => $status->{code}, >+ is_system => 0 >+}); >+is_deeply( >+ $status2->create_and_log, >+ { error => "Duplicate status found" }, >+ "Creation of statuses with duplicate codes prevented" >+); >+ >+# Create a non-duplicate status and ensure that the logger is called >+my $status3 = Koha::IllbatchStatus->new({ >+ name => "Kylo", >+ code => "DARK_SIDE", >+ is_system => 0 >+}); >+$status3->create_and_log; >+is( >+ $effects->{'batch_status_create'}, >+ 1, >+ "Creation of status calls log_something" >+); >+ >+## Status update >+ >+# Ensure only name can be updated >+$status3->update_and_log({ >+ name => "Rey", >+ code => "LIGHT_SIDE", >+ is_system => 1 >+}); >+# Get our updated status, if we can get it by it's code, we know that hasn't changed >+my $not_updated = Koha::IllbatchStatuses->find({ code => "DARK_SIDE" })->unblessed; >+is($not_updated->{is_system}, 0, "is_system cannot be changed"); >+is($not_updated->{name}, "Rey", "name can be changed"); >+# Ensure the logger is called >+is( >+ $effects->{'batch_status_update'}, >+ 1, >+ "Update of status calls log_something" >+); >+ >+## Status delete >+ >+# Prevent deletion of system statuses >+my $cannot_delete = Koha::IllbatchStatus->new({ >+ name => "Palapatine", >+ code => "SITH", >+ is_system => 1 >+}); >+my $can_delete = Koha::IllbatchStatus->new({ >+ name => "Windu", >+ code => "JEDI", >+ is_system => 0 >+}); >+$cannot_delete->create_and_log; >+$cannot_delete->delete_and_log; >+my $not_deleted = Koha::IllbatchStatuses->find({ code => "SITH" }); >+isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" ); >+$can_delete->create_and_log; >+$can_delete->delete_and_log; >+# Ensure the logger is called following a successful delete >+is( >+ $effects->{'batch_status_delete'}, >+ 1, >+ "Delete of status calls log_something" >+); >+ >+# Create a system "UNKNOWN" status >+my $status_unknown = Koha::IllbatchStatus->new({ >+ name => "Unknown", >+ code => "UNKNOWN", >+ is_system => 1 >+}); >+$status_unknown->create_and_log; >+# Create a batch and assign it a status >+my $patron = $builder->build_object({ class => 'Koha::Patrons' }); >+my $library = $builder->build_object({ class => 'Koha::Libraries' }); >+my $status5 = Koha::IllbatchStatus->new({ >+ name => "Plagueis", >+ code => "DEAD_SITH", >+ is_system => 0 >+}); >+$status5->create_and_log; >+my $batch = Koha::Illbatch->new({ >+ name => "My test batch", >+ borrowernumber => $patron->borrowernumber, >+ branchcode => $library->branchcode, >+ backend => "TEST", >+ statuscode => $status5->code >+}); >+$batch->create_and_log; >+# Delete the batch status and ensure the batch's status has been changed >+# to UNKNOWN >+$status5->delete_and_log; >+my $updated_code = Koha::Illbatches->find({ statuscode => "UNKNOWN" }); >+is($updated_code->statuscode, "UNKNOWN", "batches attached to deleted status have status changed to UNKNOWN"); >+ >+$schema->storage->txn_rollback; >\ No newline at end of file >diff --git a/t/db_dependent/api/v1/illbatchstatuses.t b/t/db_dependent/api/v1/illbatchstatuses.t >new file mode 100755 >index 0000000000..335b4365a3 >--- /dev/null >+++ b/t/db_dependent/api/v1/illbatchstatuses.t >@@ -0,0 +1,352 @@ >+#!/usr/bin/env perl >+ >+# 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 <http://www.gnu.org/licenses>. >+ >+use Modern::Perl; >+ >+use Test::More tests => 5; >+use Test::Mojo; >+ >+use t::lib::TestBuilder; >+use t::lib::Mocks; >+ >+use Koha::IllbatchStatus; >+use Koha::IllbatchStatuses; >+use Koha::Database; >+ >+my $schema = Koha::Database->new->schema; >+my $builder = t::lib::TestBuilder->new; >+ >+my $t = Test::Mojo->new('Koha::REST::V1'); >+t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 ); >+ >+subtest 'list() tests' => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ Koha::IllbatchStatuses->search->delete; >+ >+ # Create an admin user >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { >+ flags => 2 ** 22 # 22 => ill >+ } >+ } >+ ); >+ my $password = 'yoda4ever!'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ ## Authorized user tests >+ # No statuses, so empty array should be returned >+ $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses") >+ ->status_is(200) >+ ->json_is( [] ); >+ >+ my $status = $builder->build_object({ >+ class => 'Koha::IllbatchStatuses', >+ value => { >+ name => "Han Solo", >+ code => "SOLO", >+ is_system => 0 >+ } >+ }); >+ >+ # One batch created, should get returned >+ $t->get_ok("//$userid:$password@/api/v1/illbatchstatuses") >+ ->status_is(200) >+ ->json_has( '/0/id', 'ID' ) >+ ->json_has( '/0/name', 'Name' ) >+ ->json_has( '/0/code', 'Code' ) >+ ->json_has( '/0/is_system', 'is_system' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'get() tests' => sub { >+ >+ plan tests => 11; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**22 } # 22 => ill >+ } >+ ); >+ my $password = 'Rebelz4DaWin'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $status = $builder->build_object({ >+ class => 'Koha::IllbatchStatuses', >+ value => { >+ name => "Han Solo", >+ code => "SOLO", >+ is_system => 0 >+ } >+ }); >+ >+ # Unauthorised user >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code ) >+ ->status_is(200) >+ ->json_has( '/id', 'ID' ) >+ ->json_has( '/name', 'Name' ) >+ ->json_has( '/code', 'Code' ) >+ ->json_has( '/is_system', 'is_system' ); >+ >+ $t->get_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $status->id ) >+ ->status_is(403); >+ >+ my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' }); >+ my $non_existent_code = $status_to_delete->code; >+ $status_to_delete->delete; >+ >+ $t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" ) >+ ->status_is(404) >+ ->json_is( '/error' => 'ILL batch status not found' ); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'add() tests' => sub { >+ >+ plan tests =>14; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**22 } # 22 => ill >+ } >+ ); >+ my $password = '3poRox'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ my $status_metadata = { >+ name => "In a bacta tank", >+ code => "BACTA", >+ is_system => 0 >+ }; >+ >+ # Unauthorized attempt to write >+ $t->post_ok("//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata) >+ ->status_is(403); >+ >+ # Authorized attempt to write invalid data >+ my $status_with_invalid_field = { >+ %{$status_metadata}, >+ doh => 1 >+ }; >+ >+ $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field ) >+ ->status_is(400) >+ ->json_is( >+ "/errors" => [ >+ { >+ message => "Properties not allowed: doh.", >+ path => "/body" >+ } >+ ] >+ ); >+ >+ # Authorized attempt to write >+ my $status_id = >+ $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata ) >+ ->status_is( 201 ) >+ ->json_has( '/id', 'ID' ) >+ ->json_has( '/name', 'Name' ) >+ ->json_has( '/code', 'Code' ) >+ ->json_has( '/is_system', 'is_system' ); >+ >+ # Authorized attempt to create with null id >+ $status_metadata->{id} = undef; >+ $t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata ) >+ ->status_is(400) >+ ->json_has('/errors'); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'update() tests' => sub { >+ >+ plan tests => 13; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**22 } # 22 => ill >+ } >+ ); >+ my $password = 'aw3s0m3y0d41z'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ my $status_code = $builder->build_object({ class => 'Koha::IllbatchStatuses' } )->code; >+ >+ # Unauthorized attempt to update >+ $t->put_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/$status_code" => json => { name => 'These are not the droids you are looking for' } ) >+ ->status_is(403); >+ >+ # Attempt partial update on a PUT >+ my $status_with_missing_field = { >+ code => $status_code, >+ is_system => 0 >+ }; >+ >+ $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field ) >+ ->status_is(400) >+ ->json_is( "/errors" => >+ [ { message => "Missing property.", path => "/body/name" } ] >+ ); >+ >+ # Full object update on PUT >+ my $status_with_updated_field = { >+ name => "Master Ploo Koon", >+ code => $status_code, >+ is_system => 0 >+ }; >+ >+ $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field ) >+ ->status_is(200) >+ ->json_is( '/name' => 'Master Ploo Koon' ); >+ >+ # Authorized attempt to write invalid data >+ my $status_with_invalid_field = { >+ doh => 1, >+ name => "Master Mace Windu", >+ code => $status_code >+ }; >+ >+ $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field ) >+ ->status_is(400) >+ ->json_is( >+ "/errors" => [ >+ { >+ message => "Properties not allowed: doh.", >+ path => "/body" >+ } >+ ] >+ ); >+ >+ my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' }); >+ my $non_existent_code = $status_to_delete->code; >+ $status_to_delete->delete; >+ >+ $t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field ) >+ ->status_is(404); >+ >+ $schema->storage->txn_rollback; >+}; >+ >+subtest 'delete() tests' => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ my $librarian = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 2**22 } # 22 => ill >+ } >+ ); >+ my $password = 's1th43v3r!'; >+ $librarian->set_password( { password => $password, skip_validation => 1 } ); >+ my $userid = $librarian->userid; >+ >+ my $patron = $builder->build_object( >+ { >+ class => 'Koha::Patrons', >+ value => { flags => 0 } >+ } >+ ); >+ >+ $patron->set_password( { password => $password, skip_validation => 1 } ); >+ my $unauth_userid = $patron->userid; >+ >+ my $non_system_status = $builder->build_object({ >+ class => 'Koha::IllbatchStatuses', >+ value => { >+ is_system => 0 >+ } >+ }); >+ >+ my $system_status = $builder->build_object({ >+ class => 'Koha::IllbatchStatuses', >+ value => { >+ is_system => 1 >+ } >+ }); >+ >+ # Unauthorized attempt to delete >+ $t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code ) >+ ->status_is(403); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code ) >+ ->status_is(204); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code ) >+ ->status_is(404); >+ >+ $t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code ) >+ ->status_is(400) >+ ->json_is( >+ "/errors" => [ >+ { >+ message => "ILL batch status cannot be deleted" >+ } >+ ] >+ ); >+ >+ $schema->storage->txn_rollback; >+}; >-- >2.25.1 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30719
:
144281
|
144285
|
144286
|
144287
|
144288
|
144289
|
144290
|
144291
|
144292
|
144293
|
144294
|
144295
|
144296
|
144297
|
144298
|
144299
|
144300
|
144301
|
144302
|
145760
|
145869
|
145870
|
145876
|
145934
|
146152
|
147658
|
147929
|
147930
|
147931
|
147932
|
147933
|
147934
|
147952
|
147953
|
147954
|
147955
|
147956
|
151152
|
151153
|
151154
|
151155
|
151156
|
151284
|
151285
|
151286
|
151287
|
151288
|
151303
|
151304
|
151305
|
151306
|
151307
|
151308
|
151309
|
151310
|
151311
|
151312
|
151513
|
151514
|
151515
|
151516
|
151517
|
151519
|
151520
|
151521
|
151522
|
151523
|
151571
|
151572
|
151573
|
151574
|
151575
|
151611
|
151612
|
151613
|
151614
|
151615
|
151804
|
151805
|
151806
|
151807
|
151808
|
151809
|
154046
|
154047
|
154048
|
154049
|
154050
|
154051
|
154052
|
155421
|
155422
|
155423
|
155424
|
155425
|
155426
|
155427
|
155428
|
155429
|
155430
|
155431
|
155432
|
155433
|
155434
|
155435
|
156556
|
156748
|
156749
|
156752
|
156783
|
156785
|
156811
|
156812
|
156827
|
156828