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>
(cherry picked from commit 16df1a33b2)
Signed-off-by: Baptiste Wojtkowski <baptiste.wojtkowski@biblibre.com>
This commit is contained in:
David Cook 2026-07-08 05:35:04 +00:00 committed by Baptiste Wojtkowski
parent a042773a78
commit 16299d41ab
No known key found for this signature in database
GPG Key ID: 47A8A13E10BC0D40
1 changed files with 6 additions and 2 deletions

View File

@ -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;
}