From 16299d41abc9a17edd505658d3553ce423e2b511 Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 8 Jul 2026 05:35:04 +0000 Subject: [PATCH] Bug 43019: Fix branch comparison This change fixes the branch comparison between the Page and the user. Previously, it was doing a numeric "!=" and now it does the string comparison "ne". Also, if no environmental variable is set for the default branch, it defaults to an empty string for anonymous (ie non-authenticated) users. Test plan: 0. Apply the patch 1. restart_all 2. Log into the staff interface 3. Go to Tools 4. Click on "Pages" 5. Create a Page for All Libraries for the OPAC 6. Copy the "OPAC" link in the "Page URL" table cell and open it in a private window or a separate browser 7. Note that the page appears 8. Now change the "Page" to a specific library 9. Revisit the URL in the private window 10. Note that it now gives a 404 error 11. Log into the OPAC with a user whose library matches the libary of the Page 12. Note that now you can view the URL again 13. Change the library of the user or the Page 14. Note that you cannot see the Page now Signed-off-by: Phil Ringnalda Signed-off-by: Jonathan Druart (cherry picked from commit 16df1a33b2c6980741bac7e2058f4f0397d05146) Signed-off-by: Baptiste Wojtkowski --- opac/opac-page.pl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/opac/opac-page.pl b/opac/opac-page.pl index 0a35c21433..49d51c4ca8 100755 --- a/opac/opac-page.pl +++ b/opac/opac-page.pl @@ -36,14 +36,18 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user( my $page_id = $query->param('page_id'); -my $homebranch = $ENV{OPAC_BRANCH_DEFAULT}; +my $homebranch = $ENV{OPAC_BRANCH_DEFAULT} //= ""; if (C4::Context->userenv) { $homebranch = C4::Context->userenv->{'branch'}; } my $page = Koha::AdditionalContents->find($page_id); -if ( !$page || $page->category ne 'pages' || $page->branchcode && $page->branchcode != $homebranch || $page->location ne 'opac_only' && $page->location ne 'staff_and_opac' ) { +if ( !$page + || $page->category ne 'pages' + || $page->branchcode && $page->branchcode ne $homebranch + || $page->location ne 'opac_only' && $page->location ne 'staff_and_opac' ) +{ print $query->redirect('/cgi-bin/koha/errors/404.pl'); exit; }