From 138d2b64ed18fafc25829981dd06611fb2fd8797 Mon Sep 17 00:00:00 2001 From: Paul Derscheid Date: Fri, 27 Mar 2026 09:42:52 +0100 Subject: [PATCH] Bug 42207: Allow library embed on GET /patrons/{patron_id} MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add 'library' to the allowed x-koha-embed values for the GET /patrons/{patron_id} endpoint - Add unit test verifying the library embed returns library_id and name Test plan: 1. Apply patch 2. yarn api:bundle 3. prove t/db_dependent/api/v1/patrons.t 4. Verify all tests pass, including the new 'library embed' subtest under get() which verifies that requesting x-koha-embed: library returns the patron's library object Sponsored-by: Büchereizentrale Schleswig-Holstein Signed-off-by: David Nind Signed-off-by: Martin Renvoize Signed-off-by: Pedro Amorim --- api/v1/swagger/paths/patrons.yaml | 1 + t/db_dependent/api/v1/patrons.t | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/api/v1/swagger/paths/patrons.yaml b/api/v1/swagger/paths/patrons.yaml index 138e9e8e7e..3621453c70 100644 --- a/api/v1/swagger/paths/patrons.yaml +++ b/api/v1/swagger/paths/patrons.yaml @@ -507,6 +507,7 @@ enum: - +strings - extended_attributes + - library collectionFormat: csv produces: - application/json diff --git a/t/db_dependent/api/v1/patrons.t b/t/db_dependent/api/v1/patrons.t index 5042f564a4..ec59b41b52 100755 --- a/t/db_dependent/api/v1/patrons.t +++ b/t/db_dependent/api/v1/patrons.t @@ -286,7 +286,7 @@ subtest 'list() tests' => sub { subtest 'get() tests' => sub { - plan tests => 4; + plan tests => 5; $schema->storage->txn_begin; unauthorized_access_tests( 'GET', -1, undef ); @@ -431,6 +431,32 @@ subtest 'get() tests' => sub { $schema->storage->txn_rollback; }; + + subtest 'library embed' => sub { + + plan tests => 4; + + $schema->storage->txn_begin; + + my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); + + my $librarian = $builder->build_object( + { + class => 'Koha::Patrons', + value => { flags => 2**4 } # borrowers flag = 4 + } + ); + my $password = 'thePassword123'; + $librarian->set_password( { password => $password, skip_validation => 1 } ); + my $userid = $librarian->userid; + + $t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id => { "x-koha-embed" => "library" } ) + ->status_is(200) + ->json_is( '/library/library_id' => $patron->branchcode ) + ->json_is( '/library/name' => $patron->library->branchname ); + + $schema->storage->txn_rollback; + }; }; subtest 'add() tests' => sub {