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 <phil@chetcolibrary.org>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
David Cook 2026-07-08 05:35:04 +00:00 committed by Pedro Amorim
parent a45638d8fc
commit e50267072f
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
1 changed files with 2 additions and 2 deletions

View File

@ -36,7 +36,7 @@ my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
my $page_id = $query->param('page_id'); my $page_id = $query->param('page_id');
my $homebranch = $ENV{OPAC_BRANCH_DEFAULT}; my $homebranch = $ENV{OPAC_BRANCH_DEFAULT} //= "";
if ( C4::Context->userenv ) { if ( C4::Context->userenv ) {
$homebranch = C4::Context->userenv->{'branch'}; $homebranch = C4::Context->userenv->{'branch'};
} }
@ -45,7 +45,7 @@ my $page = Koha::AdditionalContents->find($page_id);
if ( !$page if ( !$page
|| $page->category ne 'pages' || $page->category ne 'pages'
|| $page->branchcode && $page->branchcode != $homebranch || $page->branchcode && $page->branchcode ne $homebranch
|| $page->location ne 'opac_only' && $page->location ne 'staff_and_opac' ) || $page->location ne 'opac_only' && $page->location ne 'staff_and_opac' )
{ {
print $query->redirect('/cgi-bin/koha/errors/404.pl'); print $query->redirect('/cgi-bin/koha/errors/404.pl');