Bug 40841: Add Z39.50 library limits

This patch adds the library limits mixin to the Z39.50 classes following
a well established pattern in Koha.

Signed-off-by: Tomás Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Andrew Fuerste Henry <andrew@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk>
This commit is contained in:
Tomás Cohen Arazi 2025-10-29 09:36:13 -03:00 committed by Martin Renvoize
parent 3169620db5
commit 1abd451c5d
No known key found for this signature in database
GPG Key ID: 2D86E0EAEC83711B
3 changed files with 79 additions and 4 deletions

View File

@ -19,7 +19,7 @@ use Modern::Perl;
use Koha::Database;
use base qw(Koha::Object);
use base qw(Koha::Object Koha::Object::Limit::Library);
=head1 NAME
@ -27,10 +27,22 @@ Koha::Z3950Server - Koha Z3950Server Object class
=head1 API
=head2 Class Methods
=head2 Internal methods
=head3 _library_limits
Configure library limits for Z39.50 servers
=cut
sub _library_limits {
return {
class => "Z3950serversBranch",
id => "server_id",
library => "branchcode",
};
}
=head3 _type
Return type of Object relating to Schema ResultSet

View File

@ -21,7 +21,7 @@ use Koha::Database;
use Koha::Z3950Server;
use base qw(Koha::Objects);
use base qw(Koha::Objects Koha::Objects::Limit::Library);
=head1 NAME

View File

@ -19,7 +19,7 @@
use Modern::Perl;
use Test::NoWarnings;
use Test::More tests => 3;
use Test::More tests => 4;
use Test::Exception;
use t::lib::TestBuilder;
@ -105,3 +105,66 @@ subtest 'Host, syntax and encoding are NOT NULL now (BZ 30571)' => sub {
$schema->storage->txn_rollback;
};
subtest 'library_limits' => sub {
plan tests => 8;
$schema->storage->txn_begin;
my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
my $server = $builder->build_object(
{
class => 'Koha::Z3950Servers',
value => {
host => 'test.example.com',
port => 210,
db => 'testdb'
}
}
);
# Test adding library limit
$server->add_library_limit( $library1->branchcode );
my $limits = $server->library_limits();
is( $limits->count, 1, 'One library limit added' );
is( $limits->next->branchcode, $library1->branchcode, 'Correct library limit' );
# Test search with library limits
my $servers = Koha::Z3950Servers->search_with_library_limits(
{ id => $server->id },
{},
$library1->branchcode
);
is( $servers->count, 1, 'Server found for authorized library' );
$servers = Koha::Z3950Servers->search_with_library_limits(
{ id => $server->id },
{},
$library2->branchcode
);
is( $servers->count, 0, 'Server not found for unauthorized library' );
# Test replacing library limits
$server->library_limits( [ $library1->branchcode, $library2->branchcode ] );
$limits = $server->library_limits();
is( $limits->count, 2, 'Two library limits set' );
# Test removing library limit
$server->del_library_limit( $library1->branchcode );
$limits = $server->library_limits();
is( $limits->count, 1, 'One library limit remains' );
is( $limits->next->branchcode, $library2->branchcode, 'Correct remaining limit' );
# Test server with no limits (available to all)
my $unrestricted_server = $builder->build_object( { class => 'Koha::Z3950Servers' } );
$servers = Koha::Z3950Servers->search_with_library_limits(
{ id => $unrestricted_server->id },
{},
$library1->branchcode
);
is( $servers->count, 1, 'Unrestricted server available to all libraries' );
$schema->storage->txn_rollback;
};