From 48cac33fb8a2574b40314e20f5a09e0f7089c137 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Wed, 3 Dec 2025 09:05:42 +0200 Subject: [PATCH] Bug 41269: Use borrowernumber to fetch patrons subpermissions Koha currently fetches patrons subpermissions with userid in method get_user_subpermissions. If for some reason patron doesn't have userid their subpermissions aren't displayed on Koha UI. Althougt this shouldn't really happen (unless there are some local use cases where userid can be empty), this method is only used to either display patrons subpermissions on page Set permissions or to check if SCO user only has SCO permissions. In both of these cases we can use patrons borrowernumber instead of userid since they check existing patrons permissions, not the ones for patron who is about to log into Koha. To test: 1. Apply this patch. 2. Enable sysprefs WebBasedSelfCheck and AutoSelfCheckAllowed and add some patrons userid to AutoSelfCheckID. 3. Make sure patron whose userid you used doesn't have permissions to use SCO and has other subpermissions instead. 4. Navigate to page About Koha>System infromation. => Confirm that warnings starting with "The patron used for the self-checkout..." are displayed. 5. Check patrons permissions. => Confirm that patrons subpermissions are displayed normally. Sponsored-by: Koha-Suomi Oy Signed-off-by: David Nind --- C4/Auth.pm | 6 +++--- about.pl | 4 +++- members/member-flags.pl | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 3252f6c448..7a50975a8e 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -2235,7 +2235,7 @@ necessary to check borrowers.flags. =cut sub get_user_subpermissions { - my $userid = shift; + my $borrowernumber = shift; my $dbh = C4::Context->dbh; my $sth = $dbh->prepare( @@ -2244,9 +2244,9 @@ sub get_user_subpermissions { JOIN permissions USING (module_bit, code) JOIN userflags ON (module_bit = bit) JOIN borrowers USING (borrowernumber) - WHERE userid = ?" + WHERE borrowernumber = ?" ); - $sth->execute($userid); + $sth->execute($borrowernumber); my $user_perms = {}; while ( my $perm = $sth->fetchrow_hashref ) { diff --git a/about.pl b/about.pl index 45a435894f..9fff71e993 100755 --- a/about.pl +++ b/about.pl @@ -395,7 +395,9 @@ if ( $tab eq 'sysinfo' ) { and C4::Context->preference('AutoSelfCheckAllowed') ) { my $userid = C4::Context->preference('AutoSelfCheckID'); - my $all_permissions = C4::Auth::get_user_subpermissions($userid); + my $borrowernumber = Koha::Patrons->find( { userid => $userid } )->borrowernumber; + my $all_permissions = C4::Auth::get_user_subpermissions($borrowernumber); + my ( $has_self_checkout_perm, $has_other_permissions ); while ( my ( $module, $permissions ) = each %$all_permissions ) { if ( $module eq 'self_check' ) { diff --git a/members/member-flags.pl b/members/member-flags.pl index ccc6092e6b..73903129eb 100755 --- a/members/member-flags.pl +++ b/members/member-flags.pl @@ -121,7 +121,7 @@ if ( $op eq 'cud-newflags' ) { } my $all_perms = get_all_subpermissions(); - my $user_perms = get_user_subpermissions( $bor->{'userid'} ); + my $user_perms = get_user_subpermissions( $bor->{'borrowernumber'} ); $sth = $dbh->prepare("SELECT bit, flag FROM userflags ORDER BY bit"); $sth->execute; my @loop; -- 2.39.5