Bug 30719: (QA follow-up) Squash:
This is a squash of 25 QA patches located at: https://github.com/PTFS-Europe/koha/commits/new_30719 Bug 30719: (QA follow-up) Batch column should be hidden by default Bug 30719: (QA follow-up) Fix wrong tt filter type Bug 30719: (QA follow-up) Make atomicupdate idempotent Bug 30719: (QA follow-up) Use COMMENT syntax in database files Bug 30719: (QA follow-up) Fix tiny boolean is_system Bug 30719: (QA follow-up) Add missing CONSTRAINT entries from kohastructure.sql to the atomicupdate file Bug 30719: (QA follow-up) Add missing koha_object_class and koha_objects_class methods Bug 30719: (QA follow-up) Swap search to find Bug 30719: (QA follow-up) Fix tests Bug 30719: (QA follow-up) API terminology - id -> batch_id Bug 30719: (QA follow-up) API terminology - borrowernumber -> patron_id Bug 30719: (QA follow-up) API terminology - branchcode -> library_id Bug 30719: (QA follow-up) Make mandatory illbatch_statuses translatable Bug 30719: (QA follow-up) Improve translatability Bug 30719: (QA follow-up) Fix capitalization of Interlibrary Loan Bug 30719: (QA follow-up) Change Branch to Library in ILL batches table Bug 30719: (QA follow-up) Add template WRAPPER to batch statuses breadrcrumbs Bug 30719: (QA follow-up) Utilize patron_to_html function to display patron info in batches table Bug 30719: (QA follow-up) Add mandatory batch statuses to the atomicupdate Bug 30719: (QA follow-up) Add page-section to the batch statuses list page Bug 30719: (QA follow-up) Style Save button on batch status edit page Bug 30719: (QA follow-up) Add question mark to label string, rephrase new ILL batch button Bug 30719: (QA follow-up) Add noExport class to action columns in batch list table and batch modal table Bug 30719: (QA follow-up) Add page-section and headers to ILL batch table Bug 30719: (QA follow-up) Perltidy Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
45d369aa81
commit
fc83fb3ebb
29 changed files with 847 additions and 700 deletions
|
@ -39,10 +39,8 @@ Return the status object associated with this batch
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub status {
|
sub status {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
return Koha::IllbatchStatus->_new_from_dbic(
|
return Koha::IllbatchStatus->_new_from_dbic( scalar $self->_result->statuscode );
|
||||||
scalar $self->_result->statuscode
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 patron
|
=head3 patron
|
||||||
|
@ -54,10 +52,8 @@ Return the patron object associated with this batch
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub patron {
|
sub patron {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
return Koha::Patron->_new_from_dbic(
|
return Koha::Patron->_new_from_dbic( scalar $self->_result->borrowernumber );
|
||||||
scalar $self->_result->borrowernumber
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 branch
|
=head3 branch
|
||||||
|
@ -69,10 +65,8 @@ Return the branch object associated with this batch
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub branch {
|
sub branch {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
return Koha::Library->_new_from_dbic(
|
return Koha::Library->_new_from_dbic( scalar $self->_result->branchcode );
|
||||||
scalar $self->_result->branchcode
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 requests_count
|
=head3 requests_count
|
||||||
|
@ -84,10 +78,8 @@ Return the number of requests associated with this batch
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub requests_count {
|
sub requests_count {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
return Koha::Illrequests->search({
|
return Koha::Illrequests->search( { batch_id => $self->id } )->count;
|
||||||
batch_id => $self->id
|
|
||||||
})->count;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 create_and_log
|
=head3 create_and_log
|
||||||
|
@ -99,18 +91,20 @@ Log batch creation following storage
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub create_and_log {
|
sub create_and_log {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->store;
|
$self->store;
|
||||||
|
|
||||||
my $logger = Koha::Illrequest::Logger->new;
|
my $logger = Koha::Illrequest::Logger->new;
|
||||||
|
|
||||||
$logger->log_something({
|
$logger->log_something(
|
||||||
modulename => 'ILL',
|
{
|
||||||
actionname => 'batch_create',
|
modulename => 'ILL',
|
||||||
objectnumber => $self->id,
|
actionname => 'batch_create',
|
||||||
infos => to_json({})
|
objectnumber => $self->id,
|
||||||
});
|
infos => to_json( {} )
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 update_and_log
|
=head3 update_and_log
|
||||||
|
@ -129,7 +123,7 @@ sub update_and_log {
|
||||||
branchcode => $self->branchcode
|
branchcode => $self->branchcode
|
||||||
};
|
};
|
||||||
|
|
||||||
$self->set( $params );
|
$self->set($params);
|
||||||
my $update = $self->store;
|
my $update = $self->store;
|
||||||
|
|
||||||
my $after = {
|
my $after = {
|
||||||
|
@ -139,15 +133,19 @@ sub update_and_log {
|
||||||
|
|
||||||
my $logger = Koha::Illrequest::Logger->new;
|
my $logger = Koha::Illrequest::Logger->new;
|
||||||
|
|
||||||
$logger->log_something({
|
$logger->log_something(
|
||||||
modulename => 'ILL',
|
{
|
||||||
actionname => 'batch_update',
|
modulename => 'ILL',
|
||||||
objectnumber => $self->id,
|
actionname => 'batch_update',
|
||||||
infos => to_json({
|
objectnumber => $self->id,
|
||||||
before => $before,
|
infos => to_json(
|
||||||
after => $after
|
{
|
||||||
})
|
before => $before,
|
||||||
});
|
after => $after
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 delete_and_log
|
=head3 delete_and_log
|
||||||
|
@ -159,16 +157,18 @@ Log batch delete
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub delete_and_log {
|
sub delete_and_log {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
my $logger = Koha::Illrequest::Logger->new;
|
my $logger = Koha::Illrequest::Logger->new;
|
||||||
|
|
||||||
$logger->log_something({
|
$logger->log_something(
|
||||||
modulename => 'ILL',
|
{
|
||||||
actionname => 'batch_delete',
|
modulename => 'ILL',
|
||||||
objectnumber => $self->id,
|
actionname => 'batch_delete',
|
||||||
infos => to_json({})
|
objectnumber => $self->id,
|
||||||
});
|
infos => to_json( {} )
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$self->delete;
|
$self->delete;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,34 +39,36 @@ Log batch status creation following storage
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub create_and_log {
|
sub create_and_log {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
# Ensure code is uppercase and contains only word characters
|
# Ensure code is uppercase and contains only word characters
|
||||||
my $fixed_code = uc $self->code;
|
my $fixed_code = uc $self->code;
|
||||||
$fixed_code =~ s/\W/_/;
|
$fixed_code =~ s/\W/_/;
|
||||||
|
|
||||||
# Ensure this status doesn't already exist
|
# Ensure this status doesn't already exist
|
||||||
my $status = Koha::IllbatchStatuses->find({ code => $fixed_code });
|
my $status = Koha::IllbatchStatuses->find( { code => $fixed_code } );
|
||||||
if ($status) {
|
if ($status) {
|
||||||
return {
|
return { error => "Duplicate status found" };
|
||||||
error => "Duplicate status found"
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ensure system statuses can't be created
|
# Ensure system statuses can't be created
|
||||||
$self->set({
|
$self->set(
|
||||||
code => $fixed_code,
|
{
|
||||||
is_system => 0
|
code => $fixed_code,
|
||||||
})->store;
|
is_system => 0
|
||||||
|
}
|
||||||
|
)->store;
|
||||||
|
|
||||||
my $logger = Koha::Illrequest::Logger->new;
|
my $logger = Koha::Illrequest::Logger->new;
|
||||||
|
|
||||||
$logger->log_something({
|
$logger->log_something(
|
||||||
modulename => 'ILL',
|
{
|
||||||
actionname => 'batch_status_create',
|
modulename => 'ILL',
|
||||||
objectnumber => $self->id,
|
actionname => 'batch_status_create',
|
||||||
infos => to_json({})
|
objectnumber => $self->id,
|
||||||
});
|
infos => to_json( {} )
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 update_and_log
|
=head3 update_and_log
|
||||||
|
@ -80,31 +82,29 @@ Log batch status update following storage
|
||||||
sub update_and_log {
|
sub update_and_log {
|
||||||
my ( $self, $params ) = @_;
|
my ( $self, $params ) = @_;
|
||||||
|
|
||||||
my $before = {
|
my $before = { name => $self->name };
|
||||||
name => $self->name
|
|
||||||
};
|
|
||||||
|
|
||||||
# Ensure only the name can be changed
|
# Ensure only the name can be changed
|
||||||
$self->set({
|
$self->set( { name => $params->{name} } );
|
||||||
name => $params->{name}
|
|
||||||
});
|
|
||||||
my $update = $self->store;
|
my $update = $self->store;
|
||||||
|
|
||||||
my $after = {
|
my $after = { name => $self->name };
|
||||||
name => $self->name
|
|
||||||
};
|
|
||||||
|
|
||||||
my $logger = Koha::Illrequest::Logger->new;
|
my $logger = Koha::Illrequest::Logger->new;
|
||||||
|
|
||||||
$logger->log_something({
|
$logger->log_something(
|
||||||
modulename => 'ILL',
|
{
|
||||||
actionname => 'batch_status_update',
|
modulename => 'ILL',
|
||||||
objectnumber => $self->id,
|
actionname => 'batch_status_update',
|
||||||
infos => to_json({
|
objectnumber => $self->id,
|
||||||
before => $before,
|
infos => to_json(
|
||||||
after => $after
|
{
|
||||||
})
|
before => $before,
|
||||||
});
|
after => $after
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
=head3 delete_and_log
|
=head3 delete_and_log
|
||||||
|
@ -116,25 +116,27 @@ Log batch status delete
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
sub delete_and_log {
|
sub delete_and_log {
|
||||||
my ( $self ) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
# Don't permit deletion of system statuses
|
# Don't permit deletion of system statuses
|
||||||
if ($self->is_system) {
|
if ( $self->is_system ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update all batches that use this status to have status UNKNOWN
|
# Update all batches that use this status to have status UNKNOWN
|
||||||
my $affected = Koha::Illbatches->search({ statuscode => $self->code });
|
my $affected = Koha::Illbatches->search( { statuscode => $self->code } );
|
||||||
$affected->update({ statuscode => 'UNKNOWN'});
|
$affected->update( { statuscode => 'UNKNOWN' } );
|
||||||
|
|
||||||
my $logger = Koha::Illrequest::Logger->new;
|
my $logger = Koha::Illrequest::Logger->new;
|
||||||
|
|
||||||
$logger->log_something({
|
$logger->log_something(
|
||||||
modulename => 'ILL',
|
{
|
||||||
actionname => 'batch_status_delete',
|
modulename => 'ILL',
|
||||||
objectnumber => $self->id,
|
actionname => 'batch_status_delete',
|
||||||
infos => to_json({})
|
objectnumber => $self->id,
|
||||||
});
|
infos => to_json( {} )
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$self->delete;
|
$self->delete;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,20 +52,18 @@ sub get {
|
||||||
|
|
||||||
my $status_code = $c->validation->param('illbatchstatus_code');
|
my $status_code = $c->validation->param('illbatchstatus_code');
|
||||||
|
|
||||||
my $status = Koha::IllbatchStatuses->find({ code => $status_code });
|
my $status = Koha::IllbatchStatuses->find( { code => $status_code } );
|
||||||
|
|
||||||
if (not defined $status) {
|
if ( not defined $status ) {
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 404,
|
status => 404,
|
||||||
openapi => { error => "ILL batch status not found" }
|
openapi => { error => "ILL batch status not found" }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 200,
|
status => 200,
|
||||||
openapi => {
|
openapi => { %{ $status->unblessed } }
|
||||||
%{$status->unblessed}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +78,11 @@ sub add {
|
||||||
|
|
||||||
my $body = $c->validation->param('body');
|
my $body = $c->validation->param('body');
|
||||||
|
|
||||||
my $status = Koha::IllbatchStatus->new( $body );
|
my $status = Koha::IllbatchStatus->new($body);
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
my $return = $status->create_and_log;
|
my $return = $status->create_and_log;
|
||||||
if ($return && $return->{error}) {
|
if ( $return && $return->{error} ) {
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 500,
|
status => 500,
|
||||||
openapi => $return
|
openapi => $return
|
||||||
|
@ -95,8 +93,7 @@ sub add {
|
||||||
openapi => $status
|
openapi => $status
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
$c->unhandled_exception($_);
|
$c->unhandled_exception($_);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -110,7 +107,7 @@ Update a batch status
|
||||||
sub update {
|
sub update {
|
||||||
my $c = shift->openapi->valid_input or return;
|
my $c = shift->openapi->valid_input or return;
|
||||||
|
|
||||||
my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param('illbatchstatus_code') });
|
my $status = Koha::IllbatchStatuses->find( { code => $c->validation->param('illbatchstatus_code') } );
|
||||||
|
|
||||||
if ( not defined $status ) {
|
if ( not defined $status ) {
|
||||||
return $c->render(
|
return $c->render(
|
||||||
|
@ -122,15 +119,15 @@ sub update {
|
||||||
my $params = $c->req->json;
|
my $params = $c->req->json;
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
|
|
||||||
# Only permit updating of name
|
# Only permit updating of name
|
||||||
$status->update_and_log({ name => $params->{name} });
|
$status->update_and_log( { name => $params->{name} } );
|
||||||
|
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 200,
|
status => 200,
|
||||||
openapi => $status
|
openapi => $status
|
||||||
);
|
);
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
$c->unhandled_exception($_);
|
$c->unhandled_exception($_);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -145,21 +142,23 @@ sub delete {
|
||||||
|
|
||||||
my $c = shift->openapi->valid_input or return;
|
my $c = shift->openapi->valid_input or return;
|
||||||
|
|
||||||
my $status = Koha::IllbatchStatuses->find({ code => $c->validation->param( 'illbatchstatus_code' ) });
|
my $status = Koha::IllbatchStatuses->find( { code => $c->validation->param('illbatchstatus_code') } );
|
||||||
|
|
||||||
if ( not defined $status ) {
|
if ( not defined $status ) {
|
||||||
return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
|
return $c->render( status => 404, openapi => { errors => [ { message => "ILL batch status not found" } ] } );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $status->is_system) {
|
if ( $status->is_system ) {
|
||||||
return $c->render( status => 400, openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] } );
|
return $c->render(
|
||||||
|
status => 400,
|
||||||
|
openapi => { errors => [ { message => "ILL batch status cannot be deleted" } ] }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
$status->delete_and_log;
|
$status->delete_and_log;
|
||||||
return $c->render( status => 204, openapi => '');
|
return $c->render( status => 204, openapi => '' );
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
$c->unhandled_exception($_);
|
$c->unhandled_exception($_);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,47 +47,46 @@ sub list {
|
||||||
# Get all patrons associated with all our batches
|
# Get all patrons associated with all our batches
|
||||||
# in one go
|
# in one go
|
||||||
my $patrons = {};
|
my $patrons = {};
|
||||||
foreach my $batch(@batches) {
|
foreach my $batch (@batches) {
|
||||||
my $patron_id = $batch->borrowernumber;
|
my $patron_id = $batch->borrowernumber;
|
||||||
$patrons->{$patron_id} = 1
|
$patrons->{$patron_id} = 1;
|
||||||
};
|
}
|
||||||
my @patron_ids = keys %{$patrons};
|
my @patron_ids = keys %{$patrons};
|
||||||
my $patron_results = Koha::Patrons->search({
|
my $patron_results = Koha::Patrons->search( { borrowernumber => { -in => \@patron_ids } } );
|
||||||
borrowernumber => { -in => \@patron_ids }
|
|
||||||
});
|
|
||||||
|
|
||||||
# Get all branches associated with all our batches
|
# Get all branches associated with all our batches
|
||||||
# in one go
|
# in one go
|
||||||
my $branches = {};
|
my $branches = {};
|
||||||
foreach my $batch(@batches) {
|
foreach my $batch (@batches) {
|
||||||
my $branch_id = $batch->branchcode;
|
my $branch_id = $batch->branchcode;
|
||||||
$branches->{$branch_id} = 1
|
$branches->{$branch_id} = 1;
|
||||||
};
|
}
|
||||||
my @branchcodes = keys %{$branches};
|
my @branchcodes = keys %{$branches};
|
||||||
my $branch_results = Koha::Libraries->search({
|
my $branch_results = Koha::Libraries->search( { branchcode => { -in => \@branchcodes } } );
|
||||||
branchcode => { -in => \@branchcodes }
|
|
||||||
});
|
|
||||||
|
|
||||||
# Get all batch statuses associated with all our batches
|
# Get all batch statuses associated with all our batches
|
||||||
# in one go
|
# in one go
|
||||||
my $statuses = {};
|
my $statuses = {};
|
||||||
foreach my $batch(@batches) {
|
foreach my $batch (@batches) {
|
||||||
my $code = $batch->statuscode;
|
my $code = $batch->statuscode;
|
||||||
$statuses->{$code} = 1
|
$statuses->{$code} = 1;
|
||||||
};
|
}
|
||||||
my @statuscodes = keys %{$statuses};
|
my @statuscodes = keys %{$statuses};
|
||||||
my $status_results = Koha::IllbatchStatuses->search({
|
my $status_results = Koha::IllbatchStatuses->search( { code => { -in => \@statuscodes } } );
|
||||||
code => { -in => \@statuscodes }
|
|
||||||
});
|
|
||||||
|
|
||||||
# Populate the response
|
# Populate the response
|
||||||
my @to_return = ();
|
my @to_return = ();
|
||||||
foreach my $it_batch(@batches) {
|
foreach my $it_batch (@batches) {
|
||||||
my $patron = $patron_results->find({ borrowernumber => $it_batch->borrowernumber});
|
my $patron = $patron_results->find( { borrowernumber => $it_batch->borrowernumber } );
|
||||||
my $branch = $branch_results->find({ branchcode => $it_batch->branchcode });
|
my $branch = $branch_results->find( { branchcode => $it_batch->branchcode } );
|
||||||
my $status = $status_results->find({ code => $it_batch->statuscode });
|
my $status = $status_results->find( { code => $it_batch->statuscode } );
|
||||||
push @to_return, {
|
push @to_return, {
|
||||||
%{$it_batch->unblessed},
|
batch_id => $it_batch->id,
|
||||||
|
backend => $it_batch->backend,
|
||||||
|
library_id => $it_batch->branchcode,
|
||||||
|
name => $it_batch->name,
|
||||||
|
statuscode => $it_batch->statuscode,
|
||||||
|
patron_id => $it_batch->borrowernumber,
|
||||||
patron => $patron,
|
patron => $patron,
|
||||||
branch => $branch,
|
branch => $branch,
|
||||||
status => $status,
|
status => $status,
|
||||||
|
@ -111,17 +110,22 @@ sub get {
|
||||||
|
|
||||||
my $batch = Koha::Illbatches->find($batchid);
|
my $batch = Koha::Illbatches->find($batchid);
|
||||||
|
|
||||||
if (not defined $batch) {
|
if ( not defined $batch ) {
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 404,
|
status => 404,
|
||||||
openapi => { error => "ILL batch not found" }
|
openapi => { error => "ILL batch not found" }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 200,
|
status => 200,
|
||||||
openapi => {
|
openapi => {
|
||||||
%{$batch->unblessed},
|
batch_id => $batch->id,
|
||||||
|
backend => $batch->backend,
|
||||||
|
library_id => $batch->branchcode,
|
||||||
|
name => $batch->name,
|
||||||
|
statuscode => $batch->statuscode,
|
||||||
|
patron_id => $batch->borrowernumber,
|
||||||
patron => $batch->patron->unblessed,
|
patron => $batch->patron->unblessed,
|
||||||
branch => $batch->branch->unblessed,
|
branch => $batch->branch->unblessed,
|
||||||
status => $batch->status->unblessed,
|
status => $batch->status->unblessed,
|
||||||
|
@ -143,7 +147,7 @@ sub add {
|
||||||
|
|
||||||
# We receive cardnumber, so we need to look up the corresponding
|
# We receive cardnumber, so we need to look up the corresponding
|
||||||
# borrowernumber
|
# borrowernumber
|
||||||
my $patron = Koha::Patrons->find({ cardnumber => $body->{cardnumber} });
|
my $patron = Koha::Patrons->find( { cardnumber => $body->{cardnumber} } );
|
||||||
|
|
||||||
if ( not defined $patron ) {
|
if ( not defined $patron ) {
|
||||||
return $c->render(
|
return $c->render(
|
||||||
|
@ -154,26 +158,31 @@ sub add {
|
||||||
|
|
||||||
delete $body->{cardnumber};
|
delete $body->{cardnumber};
|
||||||
$body->{borrowernumber} = $patron->borrowernumber;
|
$body->{borrowernumber} = $patron->borrowernumber;
|
||||||
|
$body->{branchcode} = delete $body->{library_id};
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
my $batch = Koha::Illbatch->new( $body );
|
my $batch = Koha::Illbatch->new($body);
|
||||||
$batch->create_and_log;
|
$batch->create_and_log;
|
||||||
$c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
|
$c->res->headers->location( $c->req->url->to_string . '/' . $batch->id );
|
||||||
|
|
||||||
my $ret = {
|
my $ret = {
|
||||||
%{$batch->unblessed},
|
batch_id => $batch->id,
|
||||||
patron => $batch->patron->unblessed,
|
backend => $batch->backend,
|
||||||
branch => $batch->branch->unblessed,
|
library_id => $batch->branchcode,
|
||||||
status => $batch->status->unblessed,
|
name => $batch->name,
|
||||||
requests_count => 0
|
statuscode => $batch->statuscode,
|
||||||
|
patron_id => $batch->borrowernumber,
|
||||||
|
patron => $batch->patron->unblessed,
|
||||||
|
branch => $batch->branch->unblessed,
|
||||||
|
status => $batch->status->unblessed,
|
||||||
|
requests_count => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 201,
|
status => 201,
|
||||||
openapi => $ret
|
openapi => $ret
|
||||||
);
|
);
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
if ( blessed $_ ) {
|
if ( blessed $_ ) {
|
||||||
if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
|
if ( $_->isa('Koha::Exceptions::Object::DuplicateID') ) {
|
||||||
return $c->render(
|
return $c->render(
|
||||||
|
@ -206,12 +215,19 @@ sub update {
|
||||||
|
|
||||||
my $params = $c->req->json;
|
my $params = $c->req->json;
|
||||||
delete $params->{cardnumber};
|
delete $params->{cardnumber};
|
||||||
|
$params->{borrowernumber} = delete $params->{patron_id} if $params->{patron_id};
|
||||||
|
$params->{branchcode} = delete $params->{library_id} if $params->{library_id};
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
$batch->update_and_log( $params );
|
$batch->update_and_log($params);
|
||||||
|
|
||||||
my $ret = {
|
my $ret = {
|
||||||
%{$batch->unblessed},
|
batch_id => $batch->id,
|
||||||
|
backend => $batch->backend,
|
||||||
|
library_id => $batch->branchcode,
|
||||||
|
name => $batch->name,
|
||||||
|
statuscode => $batch->statuscode,
|
||||||
|
patron_id => $batch->borrowernumber,
|
||||||
patron => $batch->patron->unblessed,
|
patron => $batch->patron->unblessed,
|
||||||
branch => $batch->branch->unblessed,
|
branch => $batch->branch->unblessed,
|
||||||
status => $batch->status->unblessed,
|
status => $batch->status->unblessed,
|
||||||
|
@ -222,8 +238,7 @@ sub update {
|
||||||
status => 200,
|
status => 200,
|
||||||
openapi => $ret
|
openapi => $ret
|
||||||
);
|
);
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
$c->unhandled_exception($_);
|
$c->unhandled_exception($_);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -238,7 +253,7 @@ sub delete {
|
||||||
|
|
||||||
my $c = shift->openapi->valid_input or return;
|
my $c = shift->openapi->valid_input or return;
|
||||||
|
|
||||||
my $batch = Koha::Illbatches->find( $c->validation->param( 'illbatch_id' ) );
|
my $batch = Koha::Illbatches->find( $c->validation->param('illbatch_id') );
|
||||||
|
|
||||||
if ( not defined $batch ) {
|
if ( not defined $batch ) {
|
||||||
return $c->render( status => 404, openapi => { error => "ILL batch not found" } );
|
return $c->render( status => 404, openapi => { error => "ILL batch not found" } );
|
||||||
|
@ -246,9 +261,8 @@ sub delete {
|
||||||
|
|
||||||
return try {
|
return try {
|
||||||
$batch->delete_and_log;
|
$batch->delete_and_log;
|
||||||
return $c->render( status => 204, openapi => '');
|
return $c->render( status => 204, openapi => '' );
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
$c->unhandled_exception($_);
|
$c->unhandled_exception($_);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,14 +93,12 @@ sub add {
|
||||||
my $create_result = &{$create_api}($body, $request);
|
my $create_result = &{$create_api}($body, $request);
|
||||||
my $new_id = $create_result->illrequest_id;
|
my $new_id = $create_result->illrequest_id;
|
||||||
|
|
||||||
my @new_req = Koha::Illrequests->search({
|
my $new_req = Koha::Illrequests->find($new_id);
|
||||||
illrequest_id => $new_id
|
|
||||||
})->as_list;
|
|
||||||
|
|
||||||
$c->res->headers->location($c->req->url->to_string . '/' . $new_req[0]->illrequest_id);
|
$c->res->headers->location($c->req->url->to_string . '/' . $new_req->illrequest_id);
|
||||||
return $c->render(
|
return $c->render(
|
||||||
status => 201,
|
status => 201,
|
||||||
openapi => $new_req[0]->to_api
|
openapi => $new_req->to_api
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -197,4 +197,12 @@ __PACKAGE__->belongs_to(
|
||||||
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
|
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YKxQxJMKxdBP9X4+i0Rfzw
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:YKxQxJMKxdBP9X4+i0Rfzw
|
||||||
|
|
||||||
|
sub koha_object_class {
|
||||||
|
'Koha::Illbatch';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub koha_objects_class {
|
||||||
|
'Koha::Illbatches';
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -114,4 +114,16 @@ __PACKAGE__->has_many(
|
||||||
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
|
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2023-09-08 13:49:29
|
||||||
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yo60FJ+kyRj8QuEMac8CFA
|
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:yo60FJ+kyRj8QuEMac8CFA
|
||||||
|
|
||||||
|
__PACKAGE__->add_columns(
|
||||||
|
'+is_system' => { is_boolean => 1 },
|
||||||
|
);
|
||||||
|
|
||||||
|
sub koha_object_class {
|
||||||
|
'Koha::IllbatchStatus';
|
||||||
|
}
|
||||||
|
|
||||||
|
sub koha_objects_class {
|
||||||
|
'Koha::IllbatchStatuses';
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -837,6 +837,7 @@ modules:
|
||||||
columnname: ill_request_id
|
columnname: ill_request_id
|
||||||
-
|
-
|
||||||
columnname: batch
|
columnname: batch
|
||||||
|
is_hidden: 1
|
||||||
-
|
-
|
||||||
columnname: metadata_author
|
columnname: metadata_author
|
||||||
-
|
-
|
||||||
|
|
|
@ -18,11 +18,11 @@
|
||||||
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
||||||
|
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
use CGI qw ( -utf8 );
|
use CGI qw ( -utf8 );
|
||||||
use Try::Tiny qw( catch try );
|
use Try::Tiny qw( catch try );
|
||||||
|
|
||||||
use C4::Context;
|
use C4::Context;
|
||||||
use C4::Auth qw( get_template_and_user );
|
use C4::Auth qw( get_template_and_user );
|
||||||
use C4::Output qw( output_html_with_http_headers );
|
use C4::Output qw( output_html_with_http_headers );
|
||||||
|
|
||||||
use Koha::IllbatchStatus;
|
use Koha::IllbatchStatus;
|
||||||
|
@ -35,55 +35,51 @@ my @messages;
|
||||||
|
|
||||||
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
my ( $template, $loggedinuser, $cookie ) = get_template_and_user(
|
||||||
{
|
{
|
||||||
template_name => "admin/ill_batch_statuses.tt",
|
template_name => "admin/ill_batch_statuses.tt",
|
||||||
query => $input,
|
query => $input,
|
||||||
type => "intranet",
|
type => "intranet",
|
||||||
flagsrequired => { parameters => 'ill' },
|
flagsrequired => { parameters => 'ill' },
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
my $status;
|
my $status;
|
||||||
if ($code) {
|
if ($code) {
|
||||||
$status = Koha::IllbatchStatuses->find({ code => $code });
|
$status = Koha::IllbatchStatuses->find( { code => $code } );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $op eq 'add_form' ) {
|
if ( $op eq 'add_form' ) {
|
||||||
if ($status) {
|
if ($status) {
|
||||||
$template->param(
|
$template->param( status => $status );
|
||||||
status => $status
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
} elsif ( $op eq 'add_validate' ) {
|
||||||
elsif ( $op eq 'add_validate' ) {
|
|
||||||
my $name = $input->param('name');
|
my $name = $input->param('name');
|
||||||
my $code = $input->param('code');
|
my $code = $input->param('code');
|
||||||
|
|
||||||
if ( not defined $status ) {
|
if ( not defined $status ) {
|
||||||
$status = Koha::IllbatchStatus->new( {
|
$status = Koha::IllbatchStatus->new(
|
||||||
name => $name,
|
{
|
||||||
code => $code
|
name => $name,
|
||||||
} );
|
code => $code
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if ($status->id) {
|
if ( $status->id ) {
|
||||||
$status->update_and_log({ name => $name });
|
$status->update_and_log( { name => $name } );
|
||||||
} else {
|
} else {
|
||||||
$status->create_and_log;
|
$status->create_and_log;
|
||||||
}
|
}
|
||||||
push @messages, { type => 'message', code => 'success_on_saving' };
|
push @messages, { type => 'message', code => 'success_on_saving' };
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
push @messages, { type => 'error', code => 'error_on_saving' };
|
push @messages, { type => 'error', code => 'error_on_saving' };
|
||||||
};
|
};
|
||||||
$op = 'list';
|
$op = 'list';
|
||||||
}
|
} elsif ( $op eq 'delete' ) {
|
||||||
elsif ( $op eq 'delete' ) {
|
|
||||||
try {
|
try {
|
||||||
$status->delete_and_log;
|
$status->delete_and_log;
|
||||||
push @messages, { code => 'success_on_delete', type => 'message' };
|
push @messages, { code => 'success_on_delete', type => 'message' };
|
||||||
}
|
} catch {
|
||||||
catch {
|
|
||||||
push @messages, { code => 'error_on_delete', type => 'alert' };
|
push @messages, { code => 'error_on_delete', type => 'alert' };
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
---
|
---
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
batch_id:
|
||||||
type: string
|
type: string
|
||||||
description: Internal ILL batch identifier
|
description: Internal ILL batch identifier
|
||||||
name:
|
name:
|
||||||
|
@ -13,10 +13,10 @@ properties:
|
||||||
cardnumber:
|
cardnumber:
|
||||||
type: string
|
type: string
|
||||||
description: Card number of the patron of the ILL batch
|
description: Card number of the patron of the ILL batch
|
||||||
borrowernumber:
|
patron_id:
|
||||||
type: string
|
type: string
|
||||||
description: Borrower number of the patron of the ILL batch
|
description: Borrower number of the patron of the ILL batch
|
||||||
branchcode:
|
library_id:
|
||||||
type: string
|
type: string
|
||||||
description: Branch code of the branch of the ILL batch
|
description: Branch code of the branch of the ILL batch
|
||||||
patron:
|
patron:
|
||||||
|
@ -44,5 +44,5 @@ additionalProperties: false
|
||||||
required:
|
required:
|
||||||
- name
|
- name
|
||||||
- backend
|
- backend
|
||||||
- branchcode
|
- library_id
|
||||||
- statuscode
|
- statuscode
|
|
@ -11,7 +11,7 @@ properties:
|
||||||
type: string
|
type: string
|
||||||
description: Unique, immutable status code
|
description: Unique, immutable status code
|
||||||
is_system:
|
is_system:
|
||||||
type: string
|
type: boolean
|
||||||
description: Is this status required for system operation
|
description: Is this status required for system operation
|
||||||
additionalProperties: false
|
additionalProperties: false
|
||||||
required:
|
required:
|
||||||
|
|
|
@ -1,54 +1,157 @@
|
||||||
use Modern::Perl;
|
use Modern::Perl;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
bug_number => "30719",
|
bug_number => "30719",
|
||||||
description => "Add ILL batches",
|
description => "Add ILL batches",
|
||||||
up => sub {
|
up => sub {
|
||||||
my ($args) = @_;
|
my ($args) = @_;
|
||||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
my ( $dbh, $out ) = @$args{qw(dbh out)};
|
||||||
$dbh->do(q{
|
$dbh->do(
|
||||||
CREATE TABLE IF NOT EXISTS `illbatches` (
|
q{
|
||||||
`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` (
|
CREATE TABLE IF NOT EXISTS `illbatch_statuses` (
|
||||||
`id` int(11) NOT NULL auto_increment, -- Status ID
|
`id` int(11) NOT NULL auto_increment COMMENT "Status ID",
|
||||||
`name` varchar(100) NOT NULL, -- Name of status
|
`name` varchar(100) NOT NULL COMMENT "Name of status",
|
||||||
`code` varchar(20) NOT NULL, -- Unique, immutable code for status
|
`code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status",
|
||||||
`is_system` int(1), -- Is this status required for system operation
|
`is_system` tinyint(1) COMMENT "Is this status required for system operation",
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `u_illbatchstatuses__code` (`code`)
|
UNIQUE KEY `u_illbatchstatuses__code` (`code`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
|
||||||
});
|
}
|
||||||
$dbh->do(q{
|
);
|
||||||
ALTER TABLE `illrequests`
|
$dbh->do(
|
||||||
ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
|
q{
|
||||||
});
|
CREATE TABLE IF NOT EXISTS `illbatches` (
|
||||||
$dbh->do(q{
|
`id` int(11) NOT NULL auto_increment COMMENT "Batch ID",
|
||||||
ALTER TABLE `illrequests`
|
`name` varchar(100) NOT NULL COMMENT "Unique name of batch",
|
||||||
ADD CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
`backend` varchar(20) NOT NULL COMMENT "Name of batch backend",
|
||||||
});
|
`borrowernumber` int(11) COMMENT "Patron associated with batch",
|
||||||
$dbh->do(q{
|
`branchcode` varchar(50) COMMENT "Branch associated with batch",
|
||||||
ALTER TABLE `illbatches`
|
`statuscode` varchar(20) COMMENT "Status of batch",
|
||||||
ADD CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
|
PRIMARY KEY (`id`),
|
||||||
});
|
UNIQUE KEY `u_illbatches__name` (`name`),
|
||||||
$dbh->do(q{
|
CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
ALTER TABLE `illbatches`
|
CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
ADD 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
|
||||||
$dbh->do(q{
|
}
|
||||||
ALTER TABLE `illbatches`
|
);
|
||||||
ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
|
unless ( column_exists( 'illrequests', 'batch_id' ) ) {
|
||||||
});
|
$dbh->do(
|
||||||
|
q{
|
||||||
|
ALTER TABLE `illrequests`
|
||||||
|
ADD COLUMN `batch_id` int(11) AFTER backend -- Optional ID of batch that this request belongs to
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
say $out "Bug 30719: Add ILL batches completed"
|
unless ( foreign_key_exists( 'illrequests', 'illrequests_ibfk' ) ) {
|
||||||
|
$dbh->do(
|
||||||
|
q{
|
||||||
|
ALTER TABLE `illrequests`
|
||||||
|
ADD CONSTRAINT `illrequests_ibfk` FOREIGN KEY (`batch_id`) REFERENCES `illbatches` (`id`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unless ( foreign_key_exists( 'illbatches', 'illbatches_bnfk' ) ) {
|
||||||
|
$dbh->do(
|
||||||
|
q{
|
||||||
|
ALTER TABLE `illbatches`
|
||||||
|
ADD CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unless ( foreign_key_exists( 'illbatches', 'illbatches_bcfk' ) ) {
|
||||||
|
$dbh->do(
|
||||||
|
q{
|
||||||
|
ALTER TABLE `illbatches`
|
||||||
|
ADD CONSTRAINT `illbatches_bcfk` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
unless ( foreign_key_exists( 'illbatches', 'illbatches_sfk' ) ) {
|
||||||
|
$dbh->do(
|
||||||
|
q{
|
||||||
|
ALTER TABLE `illbatches`
|
||||||
|
ADD CONSTRAINT `illbatches_sfk` FOREIGN KEY (`statuscode`) REFERENCES `illbatch_statuses` (`code`) ON DELETE SET NULL ON UPDATE CASCADE
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get any existing NEW batch status
|
||||||
|
my ($new_status) = $dbh->selectrow_array(
|
||||||
|
q|
|
||||||
|
SELECT name FROM illbatch_statuses WHERE code='NEW';
|
||||||
|
|
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($new_status) {
|
||||||
|
say $out "Bug 30719: NEW ILL batch status found. Update has already been run.";
|
||||||
|
} else {
|
||||||
|
$dbh->do(
|
||||||
|
qq{
|
||||||
|
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES ('New', 'NEW', '1')
|
||||||
|
}
|
||||||
|
);
|
||||||
|
say $out "Bug 30719: Added NEW ILL batch status";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get any existing IN_PROGRESS batch status
|
||||||
|
my ($in_progress_status) = $dbh->selectrow_array(
|
||||||
|
q|
|
||||||
|
SELECT name FROM illbatch_statuses WHERE code='IN_PROGRESS';
|
||||||
|
|
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($in_progress_status) {
|
||||||
|
say $out "Bug 30719: IN_PROGRESS ILL batch status found. Update has already been run.";
|
||||||
|
} else {
|
||||||
|
$dbh->do(
|
||||||
|
qq{
|
||||||
|
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'In progress', 'IN_PROGRESS', '1' )
|
||||||
|
}
|
||||||
|
);
|
||||||
|
say $out "Bug 30719: Added IN_PROGRESS ILL batch status";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get any existing COMPLETED batch status
|
||||||
|
my ($completed_status) = $dbh->selectrow_array(
|
||||||
|
q|
|
||||||
|
SELECT name FROM illbatch_statuses WHERE code='COMPLETED';
|
||||||
|
|
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($completed_status) {
|
||||||
|
say $out "Bug 30719: COMPLETED ILL batch status found. Update has already been run.";
|
||||||
|
} else {
|
||||||
|
$dbh->do(
|
||||||
|
qq{
|
||||||
|
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Completed', 'COMPLETED', '1' )
|
||||||
|
}
|
||||||
|
);
|
||||||
|
say $out "Bug 30719: Added COMPLETED ILL batch status";
|
||||||
|
}
|
||||||
|
|
||||||
|
# Get any existing UNKNOWN batch status
|
||||||
|
my ($unknown_status) = $dbh->selectrow_array(
|
||||||
|
q|
|
||||||
|
SELECT name FROM illbatch_statuses WHERE code='UNKNOWN';
|
||||||
|
|
|
||||||
|
);
|
||||||
|
|
||||||
|
if ($unknown_status) {
|
||||||
|
say $out "Bug 30719: UNKNOWN ILL batch status found. Update has already been run.";
|
||||||
|
} else {
|
||||||
|
$dbh->do(
|
||||||
|
qq{
|
||||||
|
INSERT INTO illbatch_statuses( name, code, is_system ) VALUES( 'Unknown', 'UNKNOWN', '1' )
|
||||||
|
}
|
||||||
|
);
|
||||||
|
say $out "Bug 30719: Added UNKNOWN ILL batch status";
|
||||||
|
}
|
||||||
|
|
||||||
|
say $out "Bug 30719: Add ILL batches completed";
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
42
installer/data/mysql/en/mandatory/illbatch_statuses.yml
Normal file
42
installer/data/mysql/en/mandatory/illbatch_statuses.yml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
---
|
||||||
|
#
|
||||||
|
# Copyright 2023 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>.
|
||||||
|
|
||||||
|
description:
|
||||||
|
- "ILL batch statuses used in Koha"
|
||||||
|
|
||||||
|
tables:
|
||||||
|
- illbatch_statuses:
|
||||||
|
translatable: [ description ]
|
||||||
|
multiline: []
|
||||||
|
rows:
|
||||||
|
- code: "NEW"
|
||||||
|
name: "New"
|
||||||
|
is_system: "1"
|
||||||
|
|
||||||
|
- code: "IN_PROGRESS"
|
||||||
|
name: "In progress"
|
||||||
|
is_system: "1"
|
||||||
|
|
||||||
|
- code: "COMPLETED"
|
||||||
|
name: "Completed"
|
||||||
|
is_system: "1"
|
||||||
|
|
||||||
|
- code: "UNKNOWN"
|
||||||
|
name: "Unknown"
|
||||||
|
is_system: "1"
|
|
@ -3306,10 +3306,10 @@ CREATE TABLE `illrequestattributes` (
|
||||||
--
|
--
|
||||||
DROP TABLE IF EXISTS `illbatch_statuses`;
|
DROP TABLE IF EXISTS `illbatch_statuses`;
|
||||||
CREATE TABLE `illbatch_statuses` (
|
CREATE TABLE `illbatch_statuses` (
|
||||||
`id` int(11) NOT NULL auto_increment, -- Status ID
|
`id` int(11) NOT NULL auto_increment COMMENT "Status ID",
|
||||||
`name` varchar(100) NOT NULL, -- Name of status
|
`name` varchar(100) NOT NULL COMMENT "Name of status",
|
||||||
`code` varchar(20) NOT NULL, -- Unique, immutable code for status
|
`code` varchar(20) NOT NULL COMMENT "Unique, immutable code for status",
|
||||||
`is_system` int(1), -- Is this status required for system operation
|
`is_system` tinyint(1) COMMENT "Is this status required for system operation",
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `u_illbatchstatuses__code` (`code`)
|
UNIQUE KEY `u_illbatchstatuses__code` (`code`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||||
|
@ -3319,12 +3319,12 @@ CREATE TABLE `illbatch_statuses` (
|
||||||
--
|
--
|
||||||
DROP TABLE IF EXISTS `illbatches`;
|
DROP TABLE IF EXISTS `illbatches`;
|
||||||
CREATE TABLE `illbatches` (
|
CREATE TABLE `illbatches` (
|
||||||
`id` int(11) NOT NULL auto_increment, -- Batch ID
|
`id` int(11) NOT NULL auto_increment COMMENT "Batch ID",
|
||||||
`name` varchar(100) NOT NULL, -- Unique name of batch
|
`name` varchar(100) NOT NULL COMMENT "Unique name of batch",
|
||||||
`backend` varchar(20) NOT NULL, -- Name of batch backend
|
`backend` varchar(20) NOT NULL COMMENT "Name of batch backend",
|
||||||
`borrowernumber` int(11), -- Patron associated with batch
|
`borrowernumber` int(11) COMMENT "Patron associated with batch",
|
||||||
`branchcode` varchar(50), -- Branch associated with batch
|
`branchcode` varchar(50) COMMENT "Branch associated with batch",
|
||||||
`statuscode` varchar(20), -- Status of batch
|
`statuscode` varchar(20) COMMENT "Status of batch",
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
UNIQUE KEY `u_illbatches__name` (`name`),
|
UNIQUE KEY `u_illbatches__name` (`name`),
|
||||||
CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
|
CONSTRAINT `illbatches_bnfk` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
INSERT INTO illbatch_statuses ( name, code, is_system ) VALUES
|
|
||||||
('New', 'NEW', 1),
|
|
||||||
('In progress', 'IN_PROGRESS', 1),
|
|
||||||
('Completed', 'COMPLETED', 1),
|
|
||||||
('Unknown', 'UNKNOWN', 1);
|
|
|
@ -178,7 +178,7 @@
|
||||||
<li><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></li>
|
<li><a href="/cgi-bin/koha/admin/adveditorshortcuts.pl">Keyboard shortcuts</a></li>
|
||||||
[% END %]
|
[% END %]
|
||||||
[% IF Koha.Preference('ILLModule ') && CAN_user_ill %]
|
[% IF Koha.Preference('ILLModule ') && CAN_user_ill %]
|
||||||
<li><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></li>
|
<li><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary loan batch statuses</a></li>
|
||||||
[% END %]
|
[% END %]
|
||||||
</ul>
|
</ul>
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
var ill_button_remove = _("Remove");
|
var ill_button_remove = _("Remove");
|
||||||
var ill_batch_create_api_fail = _("Unable to create batch request");
|
var ill_batch_create_api_fail = _("Unable to create batch request");
|
||||||
var ill_batch_update_api_fail = _("Unable to updatecreate batch request");
|
var ill_batch_update_api_fail = _("Unable to updatecreate batch request");
|
||||||
var ill_batch_item_remove = _("Are you sure you want to remove this item from the batch");
|
var ill_batch_item_remove = _("Are you sure you want to remove this item from the batch?");
|
||||||
var ill_batch_create_cancel_button = _("Close");
|
var ill_batch_create_cancel_button = _("Close");
|
||||||
var ill_batch_metadata_more = _("More");
|
var ill_batch_metadata_more = _("More");
|
||||||
var ill_batch_metadata_less = _("Less");
|
var ill_batch_metadata_less = _("Less");
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
[% IF query_type == "batch_list" %]
|
[% IF query_type == "batch_list" %]
|
||||||
<div>
|
<h1>
|
||||||
|
<span>View ILL requests batches</span>
|
||||||
|
</h1>
|
||||||
|
<div class="page-section">
|
||||||
|
<h2>Details for all batches</h2>
|
||||||
<table id="ill-batch-requests">
|
<table id="ill-batch-requests">
|
||||||
<thead>
|
<thead>
|
||||||
<tr id="ill-batch-header">
|
<tr id="ill-batch-header">
|
||||||
|
@ -8,7 +12,7 @@
|
||||||
<th scope="col">Number of requests</th>
|
<th scope="col">Number of requests</th>
|
||||||
<th scope="col">Status</th>
|
<th scope="col">Status</th>
|
||||||
<th scope="col">Patron</th>
|
<th scope="col">Patron</th>
|
||||||
<th scope="col">Branch</th>
|
<th scope="col">Library</th>
|
||||||
<th scope="col"></th>
|
<th scope="col"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
|
|
@ -37,7 +37,7 @@
|
||||||
<div id="ill-batch">
|
<div id="ill-batch">
|
||||||
<div class="dropdown btn-group">
|
<div class="dropdown btn-group">
|
||||||
<button class="btn btn-default dropdown-toggle" type="button" id="ill-batch-backend-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
<button class="btn btn-default dropdown-toggle" type="button" id="ill-batch-backend-dropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
|
||||||
<i class="fa fa-plus"></i> New ILL batch request <span class="caret"></span>
|
<i class="fa fa-plus"></i> New ILL requests batch <span class="caret"></span>
|
||||||
</button>
|
</button>
|
||||||
<ul class="dropdown-menu" aria-labelledby="ill-batch-backend-dropdown">
|
<ul class="dropdown-menu" aria-labelledby="ill-batch-backend-dropdown">
|
||||||
[% FOREACH backend IN have_batch %]
|
[% FOREACH backend IN have_batch %]
|
||||||
|
|
|
@ -286,8 +286,8 @@
|
||||||
<dd>Define which keys trigger actions in the advanced cataloging editor</dd>
|
<dd>Define which keys trigger actions in the advanced cataloging editor</dd>
|
||||||
[% END %]
|
[% END %]
|
||||||
[% IF Koha.Preference('ILLModule') && CAN_user_ill %]
|
[% IF Koha.Preference('ILLModule') && CAN_user_ill %]
|
||||||
<dt><a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary Loan batch statuses</a></dt>
|
<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>
|
<dd>Manage the statuses that can be assigned to Interlibrary loan batches</dd>
|
||||||
[% END %]
|
[% END %]
|
||||||
</dl>
|
</dl>
|
||||||
[% END %]
|
[% END %]
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
[% ELSE %]
|
[% ELSE %]
|
||||||
New batch status
|
New batch status
|
||||||
[% END %] › [% END %]
|
[% END %] › [% END %]
|
||||||
Interlibrary Loan batch statuses › Administration › Koha
|
Interlibrary loan batch statuses › Administration › Koha
|
||||||
</title>
|
</title>
|
||||||
[% INCLUDE 'doc-head-close.inc' %]
|
[% INCLUDE 'doc-head-close.inc' %]
|
||||||
</head>
|
</head>
|
||||||
|
@ -20,38 +20,29 @@
|
||||||
[% INCLUDE 'header.inc' %]
|
[% INCLUDE 'header.inc' %]
|
||||||
[% INCLUDE 'prefs-admin-search.inc' %]
|
[% INCLUDE 'prefs-admin-search.inc' %]
|
||||||
|
|
||||||
<nav id="breadcrumbs" aria-label="Breadcrumb" class="breadcrumb">
|
[% WRAPPER 'sub-header.inc' %]
|
||||||
<ol>
|
[% WRAPPER breadcrumbs %]
|
||||||
<li>
|
[% WRAPPER breadcrumb_item %]
|
||||||
<a href="/cgi-bin/koha/mainpage.pl">Home</a>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
|
<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 %]
|
[% END %]
|
||||||
</ol>
|
[% IF op == 'add_form' %]
|
||||||
</nav>
|
[% WRAPPER breadcrumb_item %]
|
||||||
|
<a href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Interlibrary loan batch statuses</a>
|
||||||
|
[% END %]
|
||||||
|
[% WRAPPER breadcrumb_item bc_active= 1 %]
|
||||||
|
[% IF status.id %]
|
||||||
|
<span>Modify batch status</span>
|
||||||
|
[% ELSE %]
|
||||||
|
<span>New batch status</span>
|
||||||
|
[% END %]
|
||||||
|
[% END %]
|
||||||
|
[% ELSE %]
|
||||||
|
[% WRAPPER breadcrumb_item bc_active= 1 %]
|
||||||
|
Interlibrary loan batch statuses
|
||||||
|
[% END %]
|
||||||
|
[% END %]
|
||||||
|
[% END #/ WRAPPER breadcrumbs %]
|
||||||
|
[% END #/ WRAPPER sub-header.inc %]
|
||||||
|
|
||||||
<div class="main container-fluid">
|
<div class="main container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
@ -101,14 +92,18 @@
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="is_system">Is a system status: </label>
|
<label for="is_system">Is a system status: </label>
|
||||||
<strong>[% status.is_system ? "Yes" : "No" | html %]</strong>
|
[% IF status.is_system %]
|
||||||
|
<strong>Yes</strong>
|
||||||
|
[% ELSE %]
|
||||||
|
<strong>No</strong>
|
||||||
|
[% END %]
|
||||||
<input type="hidden" name="is_system" value="[% status.is_system | html %]" />
|
<input type="hidden" name="is_system" value="[% status.is_system | html %]" />
|
||||||
</li>
|
</li>
|
||||||
</ol>
|
</ol>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<fieldset class="action">
|
<fieldset class="action">
|
||||||
<button id="save_batch_status" class="btn btn-default">Save</button>
|
<button id="save_batch_status" class="btn btn-primary">Save</button>
|
||||||
<a class="cancel" href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Cancel</a>
|
<a class="cancel" href="/cgi-bin/koha/admin/ill_batch_statuses.pl">Cancel</a>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
@ -119,31 +114,33 @@
|
||||||
<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>
|
<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>
|
</div>
|
||||||
|
|
||||||
<h1>Interlibrary Loan batch statuses</h1>
|
<h1>Interlibrary loan batch statuses</h1>
|
||||||
[% IF statuses.count %]
|
[% IF statuses.count %]
|
||||||
<table id="table_batch_statuses">
|
<div class="page-section">
|
||||||
<thead>
|
<table id="table_batch_statuses">
|
||||||
<th>Name</th>
|
<thead>
|
||||||
<th>Code</th>
|
<th>Name</th>
|
||||||
<th>Is system</th>
|
<th>Code</th>
|
||||||
<th class="noExport">Actions</th>
|
<th>Is system</th>
|
||||||
</thead>
|
<th class="noExport">Actions</th>
|
||||||
<tbody>
|
</thead>
|
||||||
[% FOREACH status IN statuses %]
|
<tbody>
|
||||||
<tr>
|
[% FOREACH status IN statuses %]
|
||||||
<td>[% status.name | html %]</td>
|
<tr>
|
||||||
<td>[% status.code | html %]</td>
|
<td>[% status.name | html %]</td>
|
||||||
<td>[% status.is_system ? "Yes" : "No" | html %]</td>
|
<td>[% status.code | html %]</td>
|
||||||
<td class="actions">
|
<td>[% status.is_system ? "Yes" : "No" | html %]</td>
|
||||||
<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>
|
<td class="actions">
|
||||||
[% IF !status.is_system %]
|
<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>
|
||||||
<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>
|
[% IF !status.is_system %]
|
||||||
[% END %]
|
<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>
|
||||||
</td>
|
[% END %]
|
||||||
</tr>
|
</td>
|
||||||
[% END %]
|
</tr>
|
||||||
</tbody>
|
[% END %]
|
||||||
</table>
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</page-section>
|
||||||
[% ELSE %]
|
[% ELSE %]
|
||||||
<div class="dialog message">
|
<div class="dialog message">
|
||||||
There are no batch statuses defined. <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form">Create new batch status</a>
|
There are no batch statuses defined. <a href="/cgi-bin/koha/admin/ill_batch_statuses.pl?op=add_form">Create new batch status</a>
|
||||||
|
|
|
@ -669,7 +669,7 @@
|
||||||
[% IF request.batch > 0 %]
|
[% IF request.batch > 0 %]
|
||||||
<li class="batch">
|
<li class="batch">
|
||||||
<span class="label batch">Batch:</span>
|
<span class="label batch">Batch:</span>
|
||||||
<a href="/cgi-bin/koha/ill/ill-requests.pl?batch_id=[% request.batch.id | html %]">
|
<a href="/cgi-bin/koha/ill/ill-requests.pl?batch_id=[% request.batch.id | uri %]">
|
||||||
[% request.batch.name | html %]
|
[% request.batch.name | html %]
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -806,9 +806,10 @@
|
||||||
[% ELSIF query_type == 'illlist' %]
|
[% ELSIF query_type == 'illlist' %]
|
||||||
<!-- illlist -->
|
<!-- illlist -->
|
||||||
<h1>
|
<h1>
|
||||||
View ILL requests
|
[% IF !batch %]
|
||||||
[% IF batch %]
|
<span>View ILL requests</span>
|
||||||
for batch "[% batch.name | html %]"
|
[% ELSIF batch %]
|
||||||
|
<span>View ILL requests for batch "[% batch.name | html %]"</span>
|
||||||
[% END %]
|
[% END %]
|
||||||
</h1>
|
</h1>
|
||||||
<div id="results" class="page-section">
|
<div id="results" class="page-section">
|
||||||
|
|
|
@ -310,7 +310,7 @@
|
||||||
batch_id: batchId,
|
batch_id: batchId,
|
||||||
ill_backend_id: batch.data.backend,
|
ill_backend_id: batch.data.backend,
|
||||||
patron_id: batch.data.patron.borrowernumber,
|
patron_id: batch.data.patron.borrowernumber,
|
||||||
library_id: batch.data.branchcode,
|
library_id: batch.data.library_id,
|
||||||
extended_attributes: extended_attributes
|
extended_attributes: extended_attributes
|
||||||
};
|
};
|
||||||
window.doCreateSubmission(payload)
|
window.doCreateSubmission(payload)
|
||||||
|
@ -378,7 +378,7 @@
|
||||||
var option = document.createElement('option')
|
var option = document.createElement('option')
|
||||||
option.value = status.code;
|
option.value = status.code;
|
||||||
option.text = status.name;
|
option.text = status.name;
|
||||||
if (batch.data.id && batch.data.statuscode === status.code) {
|
if (batch.data.batch_id && batch.data.statuscode === status.code) {
|
||||||
option.selected = true;
|
option.selected = true;
|
||||||
}
|
}
|
||||||
statusesSelect.add(option);
|
statusesSelect.add(option);
|
||||||
|
@ -479,7 +479,7 @@
|
||||||
updateBatch()
|
updateBatch()
|
||||||
.then(function () {
|
.then(function () {
|
||||||
$('#ill-batch-modal').modal({ show: false });
|
$('#ill-batch-modal').modal({ show: false });
|
||||||
location.href = '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + batch.data.id;
|
location.href = '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + batch.data.batch_id;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -505,11 +505,11 @@
|
||||||
})
|
})
|
||||||
.then(function (jsoned) {
|
.then(function (jsoned) {
|
||||||
batch.data = {
|
batch.data = {
|
||||||
id: jsoned.id,
|
batch_id: jsoned.batch_id,
|
||||||
name: jsoned.name,
|
name: jsoned.name,
|
||||||
backend: jsoned.backend,
|
backend: jsoned.backend,
|
||||||
cardnumber: jsoned.cardnumber,
|
cardnumber: jsoned.cardnumber,
|
||||||
branchcode: jsoned.branchcode,
|
library_id: jsoned.library_id,
|
||||||
statuscode: jsoned.statuscode
|
statuscode: jsoned.statuscode
|
||||||
}
|
}
|
||||||
return jsoned;
|
return jsoned;
|
||||||
|
@ -534,7 +534,7 @@
|
||||||
name: nameInput.value,
|
name: nameInput.value,
|
||||||
backend: backend,
|
backend: backend,
|
||||||
cardnumber: cardnumberInput.value,
|
cardnumber: cardnumberInput.value,
|
||||||
branchcode: selectedBranchcode,
|
library_id: selectedBranchcode,
|
||||||
statuscode: selectedStatuscode
|
statuscode: selectedStatuscode
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -545,13 +545,13 @@
|
||||||
return Promise.reject(response);
|
return Promise.reject(response);
|
||||||
})
|
})
|
||||||
.then(function (body) {
|
.then(function (body) {
|
||||||
batchId = body.id;
|
batchId = body.batch_id;
|
||||||
batch.data = {
|
batch.data = {
|
||||||
id: body.id,
|
batch_id: body.batch_id,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
backend: body.backend,
|
backend: body.backend,
|
||||||
cardnumber: body.patron.cardnumber,
|
cardnumber: body.patron.cardnumber,
|
||||||
branchcode: body.branchcode,
|
library_id: body.library_id,
|
||||||
statuscode: body.statuscode,
|
statuscode: body.statuscode,
|
||||||
patron: body.patron,
|
patron: body.patron,
|
||||||
status: body.status
|
status: body.status
|
||||||
|
@ -572,7 +572,7 @@
|
||||||
function updateBatch() {
|
function updateBatch() {
|
||||||
var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
|
var selectedBranchcode = branchcodeSelect.selectedOptions[0].value;
|
||||||
var selectedStatuscode = statusesSelect.selectedOptions[0].value;
|
var selectedStatuscode = statusesSelect.selectedOptions[0].value;
|
||||||
return doBatchApiRequest('/' + batch.data.id, {
|
return doBatchApiRequest('/' + batch.data.batch_id, {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-type': 'application/json'
|
'Content-type': 'application/json'
|
||||||
|
@ -581,7 +581,7 @@
|
||||||
name: nameInput.value,
|
name: nameInput.value,
|
||||||
backend: batch.data.backend,
|
backend: batch.data.backend,
|
||||||
cardnumber: batch.data.patron.cardnumber,
|
cardnumber: batch.data.patron.cardnumber,
|
||||||
branchcode: selectedBranchcode,
|
library_id: selectedBranchcode,
|
||||||
statuscode: selectedStatuscode
|
statuscode: selectedStatuscode
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -966,7 +966,7 @@
|
||||||
{
|
{
|
||||||
width: '18%',
|
width: '18%',
|
||||||
render: createActions,
|
render: createActions,
|
||||||
className: 'action-column'
|
className: 'action-column noExport'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
createdRow: function (row, data) {
|
createdRow: function (row, data) {
|
||||||
|
@ -1039,13 +1039,13 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function manageBatchItemsDisplay() {
|
function manageBatchItemsDisplay() {
|
||||||
batchItemsDisplay.style.display = batch.data.id ? 'block' : 'none'
|
batchItemsDisplay.style.display = batch.data.batch_id ? 'block' : 'none'
|
||||||
};
|
};
|
||||||
|
|
||||||
function updateBatchInputs() {
|
function updateBatchInputs() {
|
||||||
nameInput.value = batch.data.name || '';
|
nameInput.value = batch.data.name || '';
|
||||||
cardnumberInput.value = batch.data.cardnumber || '';
|
cardnumberInput.value = batch.data.cardnumber || '';
|
||||||
branchcodeSelect.value = batch.data.branchcode || '';
|
branchcodeSelect.value = batch.data.library_id || '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function debounce(func) {
|
function debounce(func) {
|
||||||
|
|
|
@ -46,7 +46,7 @@
|
||||||
data: batchesProxy.data,
|
data: batchesProxy.data,
|
||||||
columns: [
|
columns: [
|
||||||
{
|
{
|
||||||
data: 'id',
|
data: 'batch_id',
|
||||||
width: '10%'
|
width: '10%'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -76,7 +76,8 @@
|
||||||
{
|
{
|
||||||
render: createActions,
|
render: createActions,
|
||||||
width: '10%',
|
width: '10%',
|
||||||
orderable: false
|
orderable: false,
|
||||||
|
className: 'noExport'
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
processing: true,
|
processing: true,
|
||||||
|
@ -93,7 +94,7 @@
|
||||||
// A render function for batch name
|
// A render function for batch name
|
||||||
var createName = function (x, y, data) {
|
var createName = function (x, y, data) {
|
||||||
var a = document.createElement('a');
|
var a = document.createElement('a');
|
||||||
a.setAttribute('href', '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + data.id);
|
a.setAttribute('href', '/cgi-bin/koha/ill/ill-requests.pl?batch_id=' + data.batch_id);
|
||||||
a.setAttribute('title', data.name);
|
a.setAttribute('title', data.name);
|
||||||
a.textContent = data.name;
|
a.textContent = data.name;
|
||||||
return a.outerHTML;
|
return a.outerHTML;
|
||||||
|
@ -106,13 +107,7 @@
|
||||||
|
|
||||||
// A render function for our patron link
|
// A render function for our patron link
|
||||||
var createPatronLink = function (data) {
|
var createPatronLink = function (data) {
|
||||||
var link = document.createElement('a');
|
return data ? $patron_to_html(data, { display_cardnumber: true, url: true }) : '';
|
||||||
link.setAttribute('title', ill_batch_borrower_details);
|
|
||||||
link.setAttribute('href', '/cgi-bin/koha/members/moremember.pl?borrowernumber=' + data.borrowernumber);
|
|
||||||
var displayText = [data.firstname, data.surname].join(' ') + ' ( ' + data.cardnumber + ' )';
|
|
||||||
link.appendChild(document.createTextNode(displayText));
|
|
||||||
|
|
||||||
return link.outerHTML;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// A render function for our row action buttons
|
// A render function for our row action buttons
|
||||||
|
@ -123,13 +118,13 @@
|
||||||
var editButton = document.createElement('button');
|
var editButton = document.createElement('button');
|
||||||
editButton.setAttribute('type', 'button');
|
editButton.setAttribute('type', 'button');
|
||||||
editButton.setAttribute('class', 'editButton btn btn-xs btn-default');
|
editButton.setAttribute('class', 'editButton btn btn-xs btn-default');
|
||||||
editButton.setAttribute('data-batch-id', row.id);
|
editButton.setAttribute('data-batch-id', row.batch_id);
|
||||||
editButton.appendChild(document.createTextNode(ill_batch_edit));
|
editButton.appendChild(document.createTextNode(ill_batch_edit));
|
||||||
|
|
||||||
var deleteButton = document.createElement('button');
|
var deleteButton = document.createElement('button');
|
||||||
deleteButton.setAttribute('type', 'button');
|
deleteButton.setAttribute('type', 'button');
|
||||||
deleteButton.setAttribute('class', 'deleteButton btn btn-xs btn-danger');
|
deleteButton.setAttribute('class', 'deleteButton btn btn-xs btn-danger');
|
||||||
deleteButton.setAttribute('data-batch-id', row.id);
|
deleteButton.setAttribute('data-batch-id', row.batch_id);
|
||||||
deleteButton.appendChild(document.createTextNode(ill_batch_delete));
|
deleteButton.appendChild(document.createTextNode(ill_batch_delete));
|
||||||
|
|
||||||
div.appendChild(editButton);
|
div.appendChild(editButton);
|
||||||
|
@ -201,7 +196,7 @@
|
||||||
// Remove a batch from our proxy data
|
// Remove a batch from our proxy data
|
||||||
var removeBatch = function(id) {
|
var removeBatch = function(id) {
|
||||||
batchesProxy.data = batchesProxy.data.filter(function (batch) {
|
batchesProxy.data = batchesProxy.data.filter(function (batch) {
|
||||||
return batch.id != id;
|
return batch.batch_id != id;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ use Test::MockModule;
|
||||||
|
|
||||||
use Test::More tests => 13;
|
use Test::More tests => 13;
|
||||||
|
|
||||||
my $schema = Koha::Database->new->schema;
|
my $schema = Koha::Database->new->schema;
|
||||||
my $builder = t::lib::TestBuilder->new;
|
my $builder = t::lib::TestBuilder->new;
|
||||||
use_ok('Koha::IllbatchStatus');
|
use_ok('Koha::IllbatchStatus');
|
||||||
use_ok('Koha::IllbatchStatuses');
|
use_ok('Koha::IllbatchStatuses');
|
||||||
|
@ -48,37 +48,44 @@ my $effects = {
|
||||||
|
|
||||||
# Mock a logger so we can check it is called
|
# Mock a logger so we can check it is called
|
||||||
my $logger = Test::MockModule->new('Koha::Illrequest::Logger');
|
my $logger = Test::MockModule->new('Koha::Illrequest::Logger');
|
||||||
$logger->mock('log_something', sub {
|
$logger->mock(
|
||||||
my ($self, $to_log ) = @_;
|
'log_something',
|
||||||
$effects->{$to_log->{actionname}} ++;
|
sub {
|
||||||
});
|
my ( $self, $to_log ) = @_;
|
||||||
|
$effects->{ $to_log->{actionname} }++;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
# Create a batch status
|
# Create a batch status
|
||||||
my $status = $builder->build({
|
my $status = $builder->build(
|
||||||
source => 'IllbatchStatus',
|
{
|
||||||
value => {
|
source => 'IllbatchStatus',
|
||||||
name => "Feeling the call to the Dark Side",
|
value => {
|
||||||
code => "OH_NO",
|
name => "Feeling the call to the Dark Side",
|
||||||
is_system => 1
|
code => "OH_NO",
|
||||||
|
is_system => 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
my $status_obj = Koha::IllbatchStatuses->find({ code => $status->{code} });
|
my $status_obj = Koha::IllbatchStatuses->find( { code => $status->{code} } );
|
||||||
isa_ok( $status_obj, 'Koha::IllbatchStatus' );
|
isa_ok( $status_obj, 'Koha::IllbatchStatus' );
|
||||||
|
|
||||||
# Try to delete the status, it's a system status, so this should fail
|
# Try to delete the status, it's a system status, so this should fail
|
||||||
$status_obj->delete_and_log;
|
$status_obj->delete_and_log;
|
||||||
my $status_obj_del = Koha::IllbatchStatuses->find({ code => $status->{code} });
|
my $status_obj_del = Koha::IllbatchStatuses->find( { code => $status->{code} } );
|
||||||
isa_ok( $status_obj_del, 'Koha::IllbatchStatus' );
|
isa_ok( $status_obj_del, 'Koha::IllbatchStatus' );
|
||||||
|
|
||||||
## Status create
|
## Status create
|
||||||
|
|
||||||
# Try creating a duplicate status
|
# Try creating a duplicate status
|
||||||
my $status2 = Koha::IllbatchStatus->new({
|
my $status2 = Koha::IllbatchStatus->new(
|
||||||
name => "Obi-wan",
|
{
|
||||||
code => $status->{code},
|
name => "Obi-wan",
|
||||||
is_system => 0
|
code => $status->{code},
|
||||||
});
|
is_system => 0
|
||||||
|
}
|
||||||
|
);
|
||||||
is_deeply(
|
is_deeply(
|
||||||
$status2->create_and_log,
|
$status2->create_and_log,
|
||||||
{ error => "Duplicate status found" },
|
{ error => "Duplicate status found" },
|
||||||
|
@ -86,11 +93,13 @@ is_deeply(
|
||||||
);
|
);
|
||||||
|
|
||||||
# Create a non-duplicate status and ensure that the logger is called
|
# Create a non-duplicate status and ensure that the logger is called
|
||||||
my $status3 = Koha::IllbatchStatus->new({
|
my $status3 = Koha::IllbatchStatus->new(
|
||||||
name => "Kylo",
|
{
|
||||||
code => "DARK_SIDE",
|
name => "Kylo",
|
||||||
is_system => 0
|
code => "DARK_SIDE",
|
||||||
});
|
is_system => 0
|
||||||
|
}
|
||||||
|
);
|
||||||
$status3->create_and_log;
|
$status3->create_and_log;
|
||||||
is(
|
is(
|
||||||
$effects->{'batch_status_create'},
|
$effects->{'batch_status_create'},
|
||||||
|
@ -99,27 +108,33 @@ is(
|
||||||
);
|
);
|
||||||
|
|
||||||
# Try creating a system status and ensure it's not created
|
# Try creating a system status and ensure it's not created
|
||||||
my $cannot_create_system = Koha::IllbatchStatus->new({
|
my $cannot_create_system = Koha::IllbatchStatus->new(
|
||||||
name => "Jar Jar Binks",
|
{
|
||||||
code => "GUNGAN",
|
name => "Jar Jar Binks",
|
||||||
is_system => 1
|
code => "GUNGAN",
|
||||||
});
|
is_system => 1
|
||||||
|
}
|
||||||
|
);
|
||||||
$cannot_create_system->create_and_log;
|
$cannot_create_system->create_and_log;
|
||||||
my $created_but_not_system = Koha::IllbatchStatuses->find({ code => "GUNGAN" });
|
my $created_but_not_system = Koha::IllbatchStatuses->find( { code => "GUNGAN" } );
|
||||||
is($created_but_not_system->{is_system}, undef, "is_system statuses cannot be created");
|
is( $created_but_not_system->{is_system}, undef, "is_system statuses cannot be created" );
|
||||||
|
|
||||||
## Status update
|
## Status update
|
||||||
|
|
||||||
# Ensure only name can be updated
|
# Ensure only name can be updated
|
||||||
$status3->update_and_log({
|
$status3->update_and_log(
|
||||||
name => "Rey",
|
{
|
||||||
code => "LIGHT_SIDE",
|
name => "Rey",
|
||||||
is_system => 1
|
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
|
# 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;
|
my $not_updated = Koha::IllbatchStatuses->find( { code => "DARK_SIDE" } )->unblessed;
|
||||||
is($not_updated->{is_system}, 0, "is_system cannot be changed");
|
is( $not_updated->{is_system}, 0, "is_system cannot be changed" );
|
||||||
is($not_updated->{name}, "Rey", "name can be changed");
|
is( $not_updated->{name}, "Rey", "name can be changed" );
|
||||||
|
|
||||||
# Ensure the logger is called
|
# Ensure the logger is called
|
||||||
is(
|
is(
|
||||||
$effects->{'batch_status_update'},
|
$effects->{'batch_status_update'},
|
||||||
|
@ -128,21 +143,26 @@ is(
|
||||||
);
|
);
|
||||||
|
|
||||||
## Status delete
|
## Status delete
|
||||||
my $cannot_delete = Koha::IllbatchStatus->new({
|
my $cannot_delete = Koha::IllbatchStatus->new(
|
||||||
name => "Palapatine",
|
{
|
||||||
code => "SITH",
|
name => "Palapatine",
|
||||||
is_system => 1
|
code => "SITH",
|
||||||
})->store;
|
is_system => 1
|
||||||
my $can_delete = Koha::IllbatchStatus->new({
|
}
|
||||||
name => "Windu",
|
)->store;
|
||||||
code => "JEDI",
|
my $can_delete = Koha::IllbatchStatus->new(
|
||||||
is_system => 0
|
{
|
||||||
});
|
name => "Windu",
|
||||||
|
code => "JEDI",
|
||||||
|
is_system => 0
|
||||||
|
}
|
||||||
|
);
|
||||||
$cannot_delete->delete_and_log;
|
$cannot_delete->delete_and_log;
|
||||||
my $not_deleted = Koha::IllbatchStatuses->find({ code => "SITH" });
|
my $not_deleted = Koha::IllbatchStatuses->find( { code => "SITH" } );
|
||||||
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
|
isa_ok( $not_deleted, 'Koha::IllbatchStatus', "is_system statuses cannot be deleted" );
|
||||||
$can_delete->create_and_log;
|
$can_delete->create_and_log;
|
||||||
$can_delete->delete_and_log;
|
$can_delete->delete_and_log;
|
||||||
|
|
||||||
# Ensure the logger is called following a successful delete
|
# Ensure the logger is called following a successful delete
|
||||||
is(
|
is(
|
||||||
$effects->{'batch_status_delete'},
|
$effects->{'batch_status_delete'},
|
||||||
|
@ -151,33 +171,41 @@ is(
|
||||||
);
|
);
|
||||||
|
|
||||||
# Create a system "UNKNOWN" status
|
# Create a system "UNKNOWN" status
|
||||||
my $status_unknown = Koha::IllbatchStatus->new({
|
my $status_unknown = Koha::IllbatchStatus->new(
|
||||||
name => "Unknown",
|
{
|
||||||
code => "UNKNOWN",
|
name => "Unknown",
|
||||||
is_system => 1
|
code => "UNKNOWN",
|
||||||
});
|
is_system => 1
|
||||||
|
}
|
||||||
|
);
|
||||||
$status_unknown->create_and_log;
|
$status_unknown->create_and_log;
|
||||||
|
|
||||||
# Create a batch and assign it a status
|
# Create a batch and assign it a status
|
||||||
my $patron = $builder->build_object({ class => 'Koha::Patrons' });
|
my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
||||||
my $library = $builder->build_object({ class => 'Koha::Libraries' });
|
my $library = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||||
my $status5 = Koha::IllbatchStatus->new({
|
my $status5 = Koha::IllbatchStatus->new(
|
||||||
name => "Plagueis",
|
{
|
||||||
code => "DEAD_SITH",
|
name => "Plagueis",
|
||||||
is_system => 0
|
code => "DEAD_SITH",
|
||||||
});
|
is_system => 0
|
||||||
|
}
|
||||||
|
);
|
||||||
$status5->create_and_log;
|
$status5->create_and_log;
|
||||||
my $batch = Koha::Illbatch->new({
|
my $batch = Koha::Illbatch->new(
|
||||||
name => "My test batch",
|
{
|
||||||
borrowernumber => $patron->borrowernumber,
|
name => "My test batch",
|
||||||
branchcode => $library->branchcode,
|
borrowernumber => $patron->borrowernumber,
|
||||||
backend => "TEST",
|
branchcode => $library->branchcode,
|
||||||
statuscode => $status5->code
|
backend => "TEST",
|
||||||
});
|
statuscode => $status5->code
|
||||||
|
}
|
||||||
|
);
|
||||||
$batch->create_and_log;
|
$batch->create_and_log;
|
||||||
|
|
||||||
# Delete the batch status and ensure the batch's status has been changed
|
# Delete the batch status and ensure the batch's status has been changed
|
||||||
# to UNKNOWN
|
# to UNKNOWN
|
||||||
$status5->delete_and_log;
|
$status5->delete_and_log;
|
||||||
my $updated_code = Koha::Illbatches->find({ statuscode => "UNKNOWN" });
|
my $updated_code = Koha::Illbatches->find( { statuscode => "UNKNOWN" } );
|
||||||
is($updated_code->statuscode, "UNKNOWN", "batches attached to deleted status have status changed to UNKNOWN");
|
is( $updated_code->statuscode, "UNKNOWN", "batches attached to deleted status have status changed to UNKNOWN" );
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
|
|
|
@ -30,7 +30,7 @@ use Test::MockModule;
|
||||||
|
|
||||||
use Test::More tests => 8;
|
use Test::More tests => 8;
|
||||||
|
|
||||||
my $schema = Koha::Database->new->schema;
|
my $schema = Koha::Database->new->schema;
|
||||||
my $builder = t::lib::TestBuilder->new;
|
my $builder = t::lib::TestBuilder->new;
|
||||||
use_ok('Koha::Illbatch');
|
use_ok('Koha::Illbatch');
|
||||||
use_ok('Koha::Illbatches');
|
use_ok('Koha::Illbatches');
|
||||||
|
@ -40,43 +40,45 @@ $schema->storage->txn_begin;
|
||||||
Koha::Illrequests->search->delete;
|
Koha::Illrequests->search->delete;
|
||||||
|
|
||||||
# Create a patron
|
# Create a patron
|
||||||
my $patron = $builder->build({ source => 'Borrower' });
|
my $patron = $builder->build( { source => 'Borrower' } );
|
||||||
|
|
||||||
# Create a librarian
|
# Create a librarian
|
||||||
my $librarian = $builder->build({
|
my $librarian = $builder->build(
|
||||||
source => 'Borrower',
|
{
|
||||||
value => {
|
source => 'Borrower',
|
||||||
firstname => "Grogu"
|
value => { firstname => "Grogu" }
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
# Create a branch
|
# Create a branch
|
||||||
my $branch = $builder->build({
|
my $branch = $builder->build( { source => 'Branch' } );
|
||||||
source => 'Branch'
|
|
||||||
});
|
|
||||||
|
|
||||||
# Create a batch
|
# Create a batch
|
||||||
my $illbatch = $builder->build({
|
my $illbatch = $builder->build(
|
||||||
source => 'Illbatch',
|
{
|
||||||
value => {
|
source => 'Illbatch',
|
||||||
name => "My test batch",
|
value => {
|
||||||
backend => "Mock",
|
name => "My test batch",
|
||||||
borrowernumber => $librarian->{borrowernumber},
|
backend => "Mock",
|
||||||
branchcode => $branch->{branchcode}
|
borrowernumber => $librarian->{borrowernumber},
|
||||||
|
branchcode => $branch->{branchcode}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
my $batch_obj = Koha::Illbatches->find($illbatch->{id});
|
my $batch_obj = Koha::Illbatches->find( $illbatch->{id} );
|
||||||
isa_ok( $batch_obj, 'Koha::Illbatch' );
|
isa_ok( $batch_obj, 'Koha::Illbatch' );
|
||||||
|
|
||||||
# Create an ILL request in the batch
|
# Create an ILL request in the batch
|
||||||
my $illrq = $builder->build({
|
my $illrq = $builder->build(
|
||||||
source => 'Illrequest',
|
{
|
||||||
value => {
|
source => 'Illrequest',
|
||||||
borrowernumber => $patron->{borrowernumber},
|
value => {
|
||||||
batch_id => $illbatch->{id}
|
borrowernumber => $patron->{borrowernumber},
|
||||||
|
batch_id => $illbatch->{id}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
my $illrq_obj = Koha::Illrequests->find($illrq->{illrequest_id});
|
my $illrq_obj = Koha::Illrequests->find( $illrq->{illrequest_id} );
|
||||||
|
|
||||||
# Check requests_count
|
# Check requests_count
|
||||||
my $requests_count = $batch_obj->requests_count;
|
my $requests_count = $batch_obj->requests_count;
|
||||||
|
|
|
@ -144,6 +144,7 @@ subtest 'list() tests' => sub {
|
||||||
class => 'Koha::Illrequests',
|
class => 'Koha::Illrequests',
|
||||||
value => {
|
value => {
|
||||||
borrowernumber => $patron->borrowernumber,
|
borrowernumber => $patron->borrowernumber,
|
||||||
|
batch_id => undef,
|
||||||
status => $request_status->{code},
|
status => $request_status->{code},
|
||||||
backend => $backend->name,
|
backend => $backend->name,
|
||||||
notesstaff => '1'
|
notesstaff => '1'
|
||||||
|
@ -154,6 +155,7 @@ subtest 'list() tests' => sub {
|
||||||
{
|
{
|
||||||
class => 'Koha::Illrequests',
|
class => 'Koha::Illrequests',
|
||||||
value => {
|
value => {
|
||||||
|
batch_id => undef,
|
||||||
status => $request_status->{code},
|
status => $request_status->{code},
|
||||||
backend => $backend->name,
|
backend => $backend->name,
|
||||||
status_alias => $av->authorised_value,
|
status_alias => $av->authorised_value,
|
||||||
|
@ -291,9 +293,7 @@ subtest 'add() tests' => sub {
|
||||||
my $backend = Test::MockObject->new;
|
my $backend = Test::MockObject->new;
|
||||||
$backend->set_isa('Koha::Illbackends::Mock');
|
$backend->set_isa('Koha::Illbackends::Mock');
|
||||||
$backend->set_always('name', 'Mock');
|
$backend->set_always('name', 'Mock');
|
||||||
$backend->set_always('capabilities', sub {
|
|
||||||
return $illrequest;
|
|
||||||
} );
|
|
||||||
$backend->mock(
|
$backend->mock(
|
||||||
'metadata',
|
'metadata',
|
||||||
sub {
|
sub {
|
||||||
|
@ -310,32 +310,63 @@ subtest 'add() tests' => sub {
|
||||||
|
|
||||||
# Mock Koha::Illrequest::load_backend (to load Mocked Backend)
|
# Mock Koha::Illrequest::load_backend (to load Mocked Backend)
|
||||||
my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
|
my $illreqmodule = Test::MockModule->new('Koha::Illrequest');
|
||||||
$illreqmodule->mock( 'load_backend',
|
$illreqmodule->mock(
|
||||||
|
'load_backend',
|
||||||
sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
|
sub { my $self = shift; $self->{_my_backend} = $backend; return $self }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$illreqmodule->mock(
|
||||||
|
'_backend',
|
||||||
|
sub {
|
||||||
|
my $self = shift;
|
||||||
|
$self->{_my_backend} = $backend if ($backend);
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
$illreqmodule->mock(
|
||||||
|
'capabilities',
|
||||||
|
sub {
|
||||||
|
my ( $self, $name ) = @_;
|
||||||
|
|
||||||
|
my $capabilities = {
|
||||||
|
|
||||||
|
create_api => sub {
|
||||||
|
my ($body, $request ) = @_;
|
||||||
|
|
||||||
|
my $api_req = $builder->build_object(
|
||||||
|
{
|
||||||
|
class => 'Koha::Illrequests',
|
||||||
|
value => {
|
||||||
|
borrowernumber => $patron->borrowernumber,
|
||||||
|
batch_id => undef,
|
||||||
|
status => 'NEW',
|
||||||
|
backend => $backend->name,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
return $api_req;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return $capabilities->{$name};
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
Koha::Illrequests->search->delete;
|
Koha::Illrequests->search->delete;
|
||||||
|
|
||||||
my $body = {
|
my $body = {
|
||||||
backend => 'Mock',
|
ill_backend_id => 'Mock',
|
||||||
borrowernumber => $patron->borrowernumber,
|
patron_id => $patron->borrowernumber,
|
||||||
branchcode => $library->branchcode,
|
library_id => $library->branchcode
|
||||||
metadata => {
|
|
||||||
article_author => "Jessop, E. G.",
|
|
||||||
article_title => "Sleep",
|
|
||||||
issn => "0957-4832",
|
|
||||||
issue => "2",
|
|
||||||
pages => "89-90",
|
|
||||||
publisher => "OXFORD UNIVERSITY PRESS",
|
|
||||||
title => "Journal of public health medicine.",
|
|
||||||
year => "2001"
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
## Authorized user test
|
## Authorized user test
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illrequests" => json => $body)
|
$t->post_ok( "//$userid:$password@/api/v1/ill/requests" => json => $body)
|
||||||
->status_is(201);
|
->status_is(201);
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
|
|
|
@ -47,16 +47,12 @@ subtest 'list() tests' => sub {
|
||||||
{
|
{
|
||||||
class => 'Koha::Patrons',
|
class => 'Koha::Patrons',
|
||||||
value => {
|
value => {
|
||||||
flags => 2 ** 22 # 22 => ill
|
flags => 2**22 # 22 => ill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
my $branch = $builder->build_object(
|
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||||
{
|
|
||||||
class => 'Koha::Libraries'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
my $password = 'sheev_is_da_boss!';
|
my $password = 'sheev_is_da_boss!';
|
||||||
$librarian->set_password( { password => $password, skip_validation => 1 } );
|
$librarian->set_password( { password => $password, skip_validation => 1 } );
|
||||||
|
@ -64,59 +60,53 @@ subtest 'list() tests' => sub {
|
||||||
|
|
||||||
## Authorized user tests
|
## Authorized user tests
|
||||||
# No batches, so empty array should be returned
|
# No batches, so empty array should be returned
|
||||||
$t->get_ok("//$userid:$password@/api/v1/illbatches")
|
$t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_is( [] );
|
||||||
->status_is(200)
|
|
||||||
->json_is( [] );
|
|
||||||
|
|
||||||
my $batch = $builder->build_object({
|
my $batch = $builder->build_object(
|
||||||
class => 'Koha::Illbatches',
|
{
|
||||||
value => {
|
class => 'Koha::Illbatches',
|
||||||
name => "PapaPalpatine",
|
value => {
|
||||||
backend => "Mock",
|
name => "PapaPalpatine",
|
||||||
borrowernumber => $librarian->borrowernumber,
|
backend => "Mock",
|
||||||
branchcode => $branch->branchcode
|
borrowernumber => $librarian->borrowernumber,
|
||||||
|
branchcode => $branch->branchcode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
my $illrq = $builder->build({
|
my $illrq = $builder->build(
|
||||||
source => 'Illrequest',
|
{
|
||||||
value => {
|
source => 'Illrequest',
|
||||||
borrowernumber => $librarian->borrowernumber,
|
value => {
|
||||||
batch_id => $batch->id
|
borrowernumber => $librarian->borrowernumber,
|
||||||
|
batch_id => $batch->id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
# One batch created, should get returned
|
# One batch created, should get returned
|
||||||
$t->get_ok("//$userid:$password@/api/v1/illbatches")
|
$t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0/batch_id', 'Batch ID' )
|
||||||
->status_is(200)
|
->json_has( '/0/name', 'Batch name' )->json_has( '/0/backend', 'Backend name' )
|
||||||
->json_has( '/0/id', 'Batch ID' )
|
->json_has( '/0/patron_id', 'Borrowernumber' )->json_has( '/0/library_id', 'Branchcode' )
|
||||||
->json_has( '/0/name', 'Batch name' )
|
->json_has( '/0/patron', 'patron embedded' )->json_has( '/0/branch', 'branch embedded' )
|
||||||
->json_has( '/0/backend', 'Backend name' )
|
->json_has( '/0/requests_count', 'request count' );
|
||||||
->json_has( '/0/borrowernumber', 'Borrowernumber' )
|
|
||||||
->json_has( '/0/branchcode', 'Branchcode' )
|
|
||||||
->json_has( '/0/patron', 'patron embedded' )
|
|
||||||
->json_has( '/0/branch', 'branch embedded' )
|
|
||||||
->json_has( '/0/requests_count', 'request count' );
|
|
||||||
|
|
||||||
# Try to create a second batch with the same name, this should fail
|
# Try to create a second batch with the same name, this should fail
|
||||||
my $another_batch = $builder->build_object({ class => 'Koha::Illbatches', value => {
|
my $another_batch = $builder->build_object( { class => 'Koha::Illbatches', value => { name => $batch->name } } );
|
||||||
name => $batch->name
|
|
||||||
} });
|
|
||||||
# Create a second batch with a different name
|
# Create a second batch with a different name
|
||||||
my $batch_with_another_name = $builder->build_object({ class => 'Koha::Illbatches' });
|
my $batch_with_another_name = $builder->build_object( { class => 'Koha::Illbatches' } );
|
||||||
|
|
||||||
# Two batches created, they should both be returned
|
# Two batches created, they should both be returned
|
||||||
$t->get_ok("//$userid:$password@/api/v1/illbatches")
|
$t->get_ok("//$userid:$password@/api/v1/illbatches")->status_is(200)->json_has( '/0', 'has first batch' )
|
||||||
->status_is(200)
|
->json_has( '/1', 'has second batch' );
|
||||||
->json_has('/0', 'has first batch')
|
|
||||||
->json_has('/1', 'has second batch');
|
|
||||||
|
|
||||||
my $patron = $builder->build_object(
|
my $patron = $builder->build_object(
|
||||||
{
|
{
|
||||||
class => 'Koha::Patrons',
|
class => 'Koha::Patrons',
|
||||||
value => {
|
value => {
|
||||||
cardnumber => 999,
|
cardnumber => 999,
|
||||||
flags => 0
|
flags => 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -125,8 +115,7 @@ subtest 'list() tests' => sub {
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
# Unauthorized access
|
# Unauthorized access
|
||||||
$t->get_ok("//$unauth_userid:$password@/api/v1/illbatches")
|
$t->get_ok("//$unauth_userid:$password@/api/v1/illbatches")->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
@ -154,54 +143,44 @@ subtest 'get() tests' => sub {
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
my $branch = $builder->build_object(
|
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||||
|
|
||||||
|
my $batch = $builder->build_object(
|
||||||
{
|
{
|
||||||
class => 'Koha::Libraries'
|
class => 'Koha::Illbatches',
|
||||||
|
value => {
|
||||||
|
name => "LeiaOrgana",
|
||||||
|
backend => "Mock",
|
||||||
|
borrowernumber => $librarian->borrowernumber,
|
||||||
|
branchcode => $branch->branchcode
|
||||||
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
my $batch = $builder->build_object({
|
|
||||||
class => 'Koha::Illbatches',
|
|
||||||
value => {
|
|
||||||
name => "LeiaOrgana",
|
|
||||||
backend => "Mock",
|
|
||||||
borrowernumber => $librarian->borrowernumber,
|
|
||||||
branchcode => $branch->branchcode
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
$t->get_ok( "//$userid:$password@/api/v1/illbatches/" . $batch->id )
|
$t->get_ok( "//$userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(200)
|
||||||
->status_is(200)
|
->json_has( '/batch_id', 'Batch ID' )->json_has( '/name', 'Batch name' )
|
||||||
->json_has( '/id', 'Batch ID' )
|
->json_has( '/backend', 'Backend name' )->json_has( '/patron_id', 'Borrowernumber' )
|
||||||
->json_has( '/name', 'Batch name' )
|
->json_has( '/library_id', 'Branchcode' )->json_has( '/patron', 'patron embedded' )
|
||||||
->json_has( '/backend', 'Backend name' )
|
->json_has( '/branch', 'branch embedded' )->json_has( '/requests_count', 'request count' );
|
||||||
->json_has( '/borrowernumber', 'Borrowernumber' )
|
|
||||||
->json_has( '/branchcode', 'Branchcode' )
|
|
||||||
->json_has( '/patron', 'patron embedded' )
|
|
||||||
->json_has( '/branch', 'branch embedded' )
|
|
||||||
->json_has( '/requests_count', 'request count' );
|
|
||||||
|
|
||||||
$t->get_ok( "//$unauth_userid:$password@/api/v1/illbatches/" . $batch->id )
|
$t->get_ok( "//$unauth_userid:$password@/api/v1/illbatches/" . $batch->id )->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
my $batch_to_delete = $builder->build_object({ class => 'Koha::Illbatches' });
|
my $batch_to_delete = $builder->build_object( { class => 'Koha::Illbatches' } );
|
||||||
my $non_existent_id = $batch_to_delete->id;
|
my $non_existent_id = $batch_to_delete->id;
|
||||||
$batch_to_delete->delete;
|
$batch_to_delete->delete;
|
||||||
|
|
||||||
$t->get_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" )
|
$t->get_ok("//$userid:$password@/api/v1/illbatches/$non_existent_id")->status_is(404)
|
||||||
->status_is(404)
|
->json_is( '/error' => 'ILL batch not found' );
|
||||||
->json_is( '/error' => 'ILL batch not found' );
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'add() tests' => sub {
|
subtest 'add() tests' => sub {
|
||||||
|
|
||||||
plan tests =>19;
|
plan tests => 19;
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
|
@ -225,29 +204,20 @@ subtest 'add() tests' => sub {
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
my $branch = $builder->build_object(
|
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||||
{
|
|
||||||
class => 'Koha::Libraries'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
my $batch_status = $builder->build_object(
|
my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
|
||||||
{
|
|
||||||
class => 'Koha::IllbatchStatuses'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
my $batch_metadata = {
|
my $batch_metadata = {
|
||||||
name => "Anakin's requests",
|
name => "Anakin's requests",
|
||||||
backend => "Mock",
|
backend => "Mock",
|
||||||
cardnumber => $librarian->cardnumber,
|
cardnumber => $librarian->cardnumber,
|
||||||
branchcode => $branch->branchcode,
|
library_id => $branch->branchcode,
|
||||||
statuscode => $batch_status->code
|
statuscode => $batch_status->code
|
||||||
};
|
};
|
||||||
|
|
||||||
# Unauthorized attempt to write
|
# Unauthorized attempt to write
|
||||||
$t->post_ok("//$unauth_userid:$password@/api/v1/illbatches" => json => $batch_metadata)
|
$t->post_ok( "//$unauth_userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
# Authorized attempt to write invalid data
|
# Authorized attempt to write invalid data
|
||||||
my $batch_with_invalid_field = {
|
my $batch_with_invalid_field = {
|
||||||
|
@ -255,36 +225,28 @@ subtest 'add() tests' => sub {
|
||||||
doh => 1
|
doh => 1
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_with_invalid_field )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_with_invalid_field )->status_is(400)
|
||||||
->status_is(400)
|
->json_is(
|
||||||
->json_is(
|
|
||||||
"/errors" => [
|
"/errors" => [
|
||||||
{
|
{
|
||||||
message => "Properties not allowed: doh.",
|
message => "Properties not allowed: doh.",
|
||||||
path => "/body"
|
path => "/body"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
# Authorized attempt to write
|
# Authorized attempt to write
|
||||||
my $batch_id =
|
my $batch_id =
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(201)
|
||||||
->status_is( 201 )
|
->json_is( '/name' => $batch_metadata->{name} )->json_is( '/backend' => $batch_metadata->{backend} )
|
||||||
->json_is( '/name' => $batch_metadata->{name} )
|
->json_is( '/patron_id' => $librarian->borrowernumber )
|
||||||
->json_is( '/backend' => $batch_metadata->{backend} )
|
->json_is( '/library_id' => $batch_metadata->{library_id} )->json_is( '/statuscode' => $batch_status->code )
|
||||||
->json_is( '/borrowernumber' => $librarian->borrowernumber )
|
->json_has('/patron')->json_has('/status')->json_has('/requests_count')->json_has('/branch');
|
||||||
->json_is( '/branchcode' => $batch_metadata->{branchcode} )
|
|
||||||
->json_is( '/statuscode' => $batch_status->code )
|
|
||||||
->json_has( '/patron' )
|
|
||||||
->json_has( '/status' )
|
|
||||||
->json_has( '/requests_count' )
|
|
||||||
->json_has( '/branch' );
|
|
||||||
|
|
||||||
# Authorized attempt to create with null id
|
# Authorized attempt to create with null id
|
||||||
$batch_metadata->{id} = undef;
|
$batch_metadata->{id} = undef;
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatches" => json => $batch_metadata )->status_is(400)
|
||||||
->status_is(400)
|
->json_has('/errors');
|
||||||
->json_has('/errors');
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
@ -315,81 +277,68 @@ subtest 'update() tests' => sub {
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
my $branch = $builder->build_object(
|
my $branch = $builder->build_object( { class => 'Koha::Libraries' } );
|
||||||
{
|
|
||||||
class => 'Koha::Libraries'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
my $batch_id = $builder->build_object({ class => 'Koha::Illbatches' } )->id;
|
my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id;
|
||||||
|
|
||||||
# Unauthorized attempt to update
|
# Unauthorized attempt to update
|
||||||
$t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json => { name => 'These are not the droids you are looking for' } )
|
$t->put_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" => json =>
|
||||||
->status_is(403);
|
{ name => 'These are not the droids you are looking for' } )->status_is(403);
|
||||||
|
|
||||||
my $batch_status = $builder->build_object(
|
my $batch_status = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
|
||||||
{
|
|
||||||
class => 'Koha::IllbatchStatuses'
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
# Attempt partial update on a PUT
|
# Attempt partial update on a PUT
|
||||||
my $batch_with_missing_field = {
|
my $batch_with_missing_field = {
|
||||||
backend => "Mock",
|
backend => "Mock",
|
||||||
borrowernumber => $librarian->borrowernumber,
|
patron_id => $librarian->borrowernumber,
|
||||||
branchcode => $branch->branchcode,
|
library_id => $branch->branchcode,
|
||||||
statuscode => $batch_status->code
|
statuscode => $batch_status->code
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_missing_field )
|
||||||
->status_is(400)
|
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||||
->json_is( "/errors" =>
|
|
||||||
[ { message => "Missing property.", path => "/body/name" } ]
|
|
||||||
);
|
|
||||||
|
|
||||||
# Full object update on PUT
|
# Full object update on PUT
|
||||||
my $batch_with_updated_field = {
|
my $batch_with_updated_field = {
|
||||||
name => "Master Ploo Koon",
|
name => "Master Ploo Koon",
|
||||||
backend => "Mock",
|
backend => "Mock",
|
||||||
borrowernumber => $librarian->borrowernumber,
|
patron_id => $librarian->borrowernumber,
|
||||||
branchcode => $branch->branchcode,
|
library_id => $branch->branchcode,
|
||||||
statuscode => $batch_status->code
|
statuscode => $batch_status->code
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
|
||||||
->status_is(200)
|
->status_is(200)->json_is( '/name' => 'Master Ploo Koon' );
|
||||||
->json_is( '/name' => 'Master Ploo Koon' );
|
|
||||||
|
|
||||||
# Authorized attempt to write invalid data
|
# Authorized attempt to write invalid data
|
||||||
my $batch_with_invalid_field = {
|
my $batch_with_invalid_field = {
|
||||||
doh => 1,
|
doh => 1,
|
||||||
name => "Master Mace Windu",
|
name => "Master Mace Windu",
|
||||||
backend => "Mock"
|
backend => "Mock"
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_invalid_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_invalid_field )
|
||||||
->status_is(400)
|
->status_is(400)->json_is(
|
||||||
->json_is(
|
|
||||||
"/errors" => [
|
"/errors" => [
|
||||||
{
|
{
|
||||||
message => "Properties not allowed: doh.",
|
message => "Properties not allowed: doh.",
|
||||||
path => "/body"
|
path => "/body"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
my $batch_to_delete = $builder->build_object({ class => 'Koha::Cities' });
|
my $batch_to_delete = $builder->build_object( { class => 'Koha::Cities' } );
|
||||||
my $non_existent_id = $batch_to_delete->id;
|
my $non_existent_id = $batch_to_delete->id;
|
||||||
$batch_to_delete->delete;
|
$batch_to_delete->delete;
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" => json => $batch_with_updated_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatches/$non_existent_id" => json => $batch_with_updated_field )
|
||||||
->status_is(404);
|
->status_is(404);
|
||||||
|
|
||||||
# Wrong method (POST)
|
# Wrong method (POST)
|
||||||
$batch_with_updated_field->{id} = 2;
|
$batch_with_updated_field->{id} = 2;
|
||||||
|
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatches/$batch_id" => json => $batch_with_updated_field )
|
||||||
->status_is(404);
|
->status_is(404);
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
@ -420,17 +369,14 @@ subtest 'delete() tests' => sub {
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
my $batch_id = $builder->build_object({ class => 'Koha::Illbatches' })->id;
|
my $batch_id = $builder->build_object( { class => 'Koha::Illbatches' } )->id;
|
||||||
|
|
||||||
# Unauthorized attempt to delete
|
# Unauthorized attempt to delete
|
||||||
$t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatches/$batch_id" )
|
$t->delete_ok("//$unauth_userid:$password@/api/v1/illbatches/$batch_id")->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
$t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")
|
$t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(204);
|
||||||
->status_is(204);
|
|
||||||
|
|
||||||
$t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")
|
$t->delete_ok("//$userid:$password@/api/v1/illbatches/$batch_id")->status_is(404);
|
||||||
->status_is(404);
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,7 +46,7 @@ subtest 'list() tests' => sub {
|
||||||
{
|
{
|
||||||
class => 'Koha::Patrons',
|
class => 'Koha::Patrons',
|
||||||
value => {
|
value => {
|
||||||
flags => 2 ** 22 # 22 => ill
|
flags => 2**22 # 22 => ill
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -56,26 +56,22 @@ subtest 'list() tests' => sub {
|
||||||
|
|
||||||
## Authorized user tests
|
## Authorized user tests
|
||||||
# No statuses, so empty array should be returned
|
# No statuses, so empty array should be returned
|
||||||
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")
|
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")->status_is(200)->json_is( [] );
|
||||||
->status_is(200)
|
|
||||||
->json_is( [] );
|
|
||||||
|
|
||||||
my $status = $builder->build_object({
|
my $status = $builder->build_object(
|
||||||
class => 'Koha::IllbatchStatuses',
|
{
|
||||||
value => {
|
class => 'Koha::IllbatchStatuses',
|
||||||
name => "Han Solo",
|
value => {
|
||||||
code => "SOLO",
|
name => "Han Solo",
|
||||||
is_system => 0
|
code => "SOLO",
|
||||||
|
is_system => 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
# One batch created, should get returned
|
# One batch created, should get returned
|
||||||
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")
|
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses")->status_is(200)->json_has( '/0/id', 'ID' )
|
||||||
->status_is(200)
|
->json_has( '/0/name', 'Name' )->json_has( '/0/code', 'Code' )->json_has( '/0/is_system', 'is_system' );
|
||||||
->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;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
@ -96,14 +92,16 @@ subtest 'get() tests' => sub {
|
||||||
$librarian->set_password( { password => $password, skip_validation => 1 } );
|
$librarian->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $userid = $librarian->userid;
|
my $userid = $librarian->userid;
|
||||||
|
|
||||||
my $status = $builder->build_object({
|
my $status = $builder->build_object(
|
||||||
class => 'Koha::IllbatchStatuses',
|
{
|
||||||
value => {
|
class => 'Koha::IllbatchStatuses',
|
||||||
name => "Han Solo",
|
value => {
|
||||||
code => "SOLO",
|
name => "Han Solo",
|
||||||
is_system => 0
|
code => "SOLO",
|
||||||
|
is_system => 0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
# Unauthorised user
|
# Unauthorised user
|
||||||
my $patron = $builder->build_object(
|
my $patron = $builder->build_object(
|
||||||
|
@ -115,30 +113,25 @@ subtest 'get() tests' => sub {
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
$t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code )
|
$t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $status->code )->status_is(200)
|
||||||
->status_is(200)
|
->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' )
|
||||||
->json_has( '/id', 'ID' )
|
->json_has( '/is_system', 'is_system' );
|
||||||
->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 )
|
$t->get_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $status->id )->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' });
|
my $status_to_delete = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
|
||||||
my $non_existent_code = $status_to_delete->code;
|
my $non_existent_code = $status_to_delete->code;
|
||||||
$status_to_delete->delete;
|
$status_to_delete->delete;
|
||||||
|
|
||||||
$t->get_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" )
|
$t->get_ok("//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code")->status_is(404)
|
||||||
->status_is(404)
|
->json_is( '/error' => 'ILL batch status not found' );
|
||||||
->json_is( '/error' => 'ILL batch status not found' );
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
||||||
subtest 'add() tests' => sub {
|
subtest 'add() tests' => sub {
|
||||||
|
|
||||||
plan tests =>14;
|
plan tests => 14;
|
||||||
|
|
||||||
$schema->storage->txn_begin;
|
$schema->storage->txn_begin;
|
||||||
|
|
||||||
|
@ -162,14 +155,13 @@ subtest 'add() tests' => sub {
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
my $status_metadata = {
|
my $status_metadata = {
|
||||||
name => "In a bacta tank",
|
name => "In a bacta tank",
|
||||||
code => "BACTA",
|
code => "BACTA",
|
||||||
is_system => 0
|
is_system => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
# Unauthorized attempt to write
|
# Unauthorized attempt to write
|
||||||
$t->post_ok("//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata)
|
$t->post_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
# Authorized attempt to write invalid data
|
# Authorized attempt to write invalid data
|
||||||
my $status_with_invalid_field = {
|
my $status_with_invalid_field = {
|
||||||
|
@ -177,31 +169,26 @@ subtest 'add() tests' => sub {
|
||||||
doh => 1
|
doh => 1
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_with_invalid_field )->status_is(400)
|
||||||
->status_is(400)
|
->json_is(
|
||||||
->json_is(
|
|
||||||
"/errors" => [
|
"/errors" => [
|
||||||
{
|
{
|
||||||
message => "Properties not allowed: doh.",
|
message => "Properties not allowed: doh.",
|
||||||
path => "/body"
|
path => "/body"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
# Authorized attempt to write
|
# Authorized attempt to write
|
||||||
my $status_id =
|
my $status_id =
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(201)
|
||||||
->status_is( 201 )
|
->json_has( '/id', 'ID' )->json_has( '/name', 'Name' )->json_has( '/code', 'Code' )
|
||||||
->json_has( '/id', 'ID' )
|
|
||||||
->json_has( '/name', 'Name' )
|
|
||||||
->json_has( '/code', 'Code' )
|
|
||||||
->json_has( '/is_system', 'is_system' );
|
->json_has( '/is_system', 'is_system' );
|
||||||
|
|
||||||
# Authorized attempt to create with null id
|
# Authorized attempt to create with null id
|
||||||
$status_metadata->{id} = undef;
|
$status_metadata->{id} = undef;
|
||||||
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )
|
$t->post_ok( "//$userid:$password@/api/v1/illbatchstatuses" => json => $status_metadata )->status_is(400)
|
||||||
->status_is(400)
|
->json_has('/errors');
|
||||||
->json_has('/errors');
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
@ -231,11 +218,11 @@ subtest 'update() tests' => sub {
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
my $status_code = $builder->build_object({ class => 'Koha::IllbatchStatuses' } )->code;
|
my $status_code = $builder->build_object( { class => 'Koha::IllbatchStatuses' } )->code;
|
||||||
|
|
||||||
# Unauthorized attempt to update
|
# 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' } )
|
$t->put_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/$status_code" => json =>
|
||||||
->status_is(403);
|
{ name => 'These are not the droids you are looking for' } )->status_is(403);
|
||||||
|
|
||||||
# Attempt partial update on a PUT
|
# Attempt partial update on a PUT
|
||||||
my $status_with_missing_field = {
|
my $status_with_missing_field = {
|
||||||
|
@ -244,21 +231,17 @@ subtest 'update() tests' => sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_missing_field )
|
||||||
->status_is(400)
|
->status_is(400)->json_is( "/errors" => [ { message => "Missing property.", path => "/body/name" } ] );
|
||||||
->json_is( "/errors" =>
|
|
||||||
[ { message => "Missing property.", path => "/body/name" } ]
|
|
||||||
);
|
|
||||||
|
|
||||||
# Full object update on PUT
|
# Full object update on PUT
|
||||||
my $status_with_updated_field = {
|
my $status_with_updated_field = {
|
||||||
name => "Master Ploo Koon",
|
name => "Master Ploo Koon",
|
||||||
code => $status_code,
|
code => $status_code,
|
||||||
is_system => 0
|
is_system => 0
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_updated_field )
|
||||||
->status_is(200)
|
->status_is(200)->json_is( '/name' => 'Master Ploo Koon' );
|
||||||
->json_is( '/name' => 'Master Ploo Koon' );
|
|
||||||
|
|
||||||
# Authorized attempt to write invalid data
|
# Authorized attempt to write invalid data
|
||||||
my $status_with_invalid_field = {
|
my $status_with_invalid_field = {
|
||||||
|
@ -268,22 +251,22 @@ subtest 'update() tests' => sub {
|
||||||
};
|
};
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field )
|
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$status_code" => json => $status_with_invalid_field )
|
||||||
->status_is(400)
|
->status_is(400)->json_is(
|
||||||
->json_is(
|
|
||||||
"/errors" => [
|
"/errors" => [
|
||||||
{
|
{
|
||||||
message => "Properties not allowed: doh.",
|
message => "Properties not allowed: doh.",
|
||||||
path => "/body"
|
path => "/body"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
my $status_to_delete = $builder->build_object({ class => 'Koha::IllbatchStatuses' });
|
my $status_to_delete = $builder->build_object( { class => 'Koha::IllbatchStatuses' } );
|
||||||
my $non_existent_code = $status_to_delete->code;
|
my $non_existent_code = $status_to_delete->code;
|
||||||
$status_to_delete->delete;
|
$status_to_delete->delete;
|
||||||
|
|
||||||
$t->put_ok( "//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field )
|
$t->put_ok(
|
||||||
->status_is(404);
|
"//$userid:$password@/api/v1/illbatchstatuses/$non_existent_code" => json => $status_with_updated_field )
|
||||||
|
->status_is(404);
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
@ -314,39 +297,29 @@ subtest 'delete() tests' => sub {
|
||||||
$patron->set_password( { password => $password, skip_validation => 1 } );
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
||||||
my $unauth_userid = $patron->userid;
|
my $unauth_userid = $patron->userid;
|
||||||
|
|
||||||
my $non_system_status = $builder->build_object({
|
my $non_system_status = $builder->build_object(
|
||||||
class => 'Koha::IllbatchStatuses',
|
{
|
||||||
value => {
|
class => 'Koha::IllbatchStatuses',
|
||||||
is_system => 0
|
value => { is_system => 0 }
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
my $system_status = $builder->build_object({
|
my $system_status = $builder->build_object(
|
||||||
class => 'Koha::IllbatchStatuses',
|
{
|
||||||
value => {
|
class => 'Koha::IllbatchStatuses',
|
||||||
is_system => 1
|
value => { is_system => 1 }
|
||||||
}
|
}
|
||||||
});
|
);
|
||||||
|
|
||||||
# Unauthorized attempt to delete
|
# Unauthorized attempt to delete
|
||||||
$t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
|
$t->delete_ok( "//$unauth_userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(403);
|
||||||
->status_is(403);
|
|
||||||
|
|
||||||
$t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
|
$t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(204);
|
||||||
->status_is(204);
|
|
||||||
|
|
||||||
$t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )
|
$t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $non_system_status->code )->status_is(404);
|
||||||
->status_is(404);
|
|
||||||
|
|
||||||
$t->delete_ok("//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code )
|
$t->delete_ok( "//$userid:$password@/api/v1/illbatchstatuses/" . $system_status->code )->status_is(400)
|
||||||
->status_is(400)
|
->json_is( "/errors" => [ { message => "ILL batch status cannot be deleted" } ] );
|
||||||
->json_is(
|
|
||||||
"/errors" => [
|
|
||||||
{
|
|
||||||
message => "ILL batch status cannot be deleted"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
);
|
|
||||||
|
|
||||||
$schema->storage->txn_rollback;
|
$schema->storage->txn_rollback;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue