From b7661a8d8f4fe01761fadd499919575444da5fe9 Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Thu, 13 Mar 2025 23:34:23 +0000 Subject: [PATCH] Bug 38184: [24.05] Show due date on OpacTrustedCheckout modal This fixes checkout fields being made available to the public API. Note: This depends on the fix at Bug 39313, so make sure you apply that first. To test: 1. Enabled OpacTrustedCheckout system preference 2. Search for an item and get the barcode 3. Go to the OPAC 4. Click the Self-checkout button at the top 5. Enter the barcode and submit 6. Notice that the due date does not show in the modal, even though the due date was correctly set 7. Apply the patch and restart services 8. Go to the staff interface and check in your barcode 9. Repeat steps 3-5 10. Confirm the due date does show correctly in the modal 11. Confirm tests pass t/db_dependent/Koha/Checkout.t Sponsored-by: Reserve Bank of New Zealand Signed-off-by: Owen Leonard Signed-off-by: David Nind --- Koha/Checkout.pm | 15 ++++++++++ t/db_dependent/Koha/Checkout.t | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index a63ec71ab88..5656c32bf44 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -222,6 +222,21 @@ sub to_api_mapping { }; } +=head3 public_read_list + +This method returns the list of publicly readable database fields for both API and UI output purposes + +=cut + +sub public_read_list { + return [ + 'checkin_library', 'issue_id', 'borrowernumber', + 'itemnumber', 'date_due', 'branchcode', + 'returndate', 'lastreneweddate', 'issuedate', + 'notedate', 'noteseen' + ]; +} + =head3 claim_returned my $return_claim = $checkout->claim_returned(); diff --git a/t/db_dependent/Koha/Checkout.t b/t/db_dependent/Koha/Checkout.t index 7459cbcbf8a..9dc83397440 100755 --- a/t/db_dependent/Koha/Checkout.t +++ b/t/db_dependent/Koha/Checkout.t @@ -77,3 +77,53 @@ subtest 'renewals() tests' => sub { $schema->storage->txn_rollback; }; + +subtest 'public_read_list() tests' => sub { + + $schema->storage->txn_begin; + + my @all_attrs = Koha::Checkouts->columns(); + my $public_attrs = + { map { $_ => 1 } @{ Koha::Checkout->public_read_list() } }; + my $mapping = Koha::Checkout->to_api_mapping; + + plan tests => scalar @all_attrs * 2; + + # Create a sample checkout + my $checkout = $builder->build_object( { class => 'Koha::Checkouts' } ); + + my $unprivileged_representation = $checkout->to_api( { public => 1 } ); + my $privileged_representation = $checkout->to_api; + + foreach my $attr (@all_attrs) { + my $mapped = exists $mapping->{$attr} ? $mapping->{$attr} : $attr; + if ( defined($mapped) ) { + ok( + exists $privileged_representation->{$mapped}, + "Attribute '$attr' is present when privileged" + ); + if ( exists $public_attrs->{$attr} ) { + ok( + exists $unprivileged_representation->{$mapped}, + "Attribute '$attr' is present when public" + ); + } else { + ok( + !exists $unprivileged_representation->{$mapped}, + "Attribute '$attr' is not present when public" + ); + } + } else { + ok( + !exists $privileged_representation->{$attr}, + "Unmapped attribute '$attr' is not present when privileged" + ); + ok( + !exists $unprivileged_representation->{$attr}, + "Unmapped attribute '$attr' is not present when public" + ); + } + } + + $schema->storage->txn_rollback; +}; -- 2.39.5