From 578f708cb557eb78bc45371bed58728fae4616f8 Mon Sep 17 00:00:00 2001 From: Olli-Antti Kivilahti Date: Thu, 5 Nov 2015 14:05:08 +0200 Subject: [PATCH] Bug 14540 - Move member-flags.pl to PermissionsManager. Recover from changed userid mid-session. --- C4/Auth.pm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index 179fea5..22df21a 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -1715,13 +1715,25 @@ sub get_user_subpermissions { my $userid = shift; return {} unless $userid; - use Koha::Auth::PermissionManager; - my $permissionManager = Koha::Auth::PermissionManager->new(); - my $borrowerPermissions = $permissionManager->getBorrowerPermissions($userid); #Prefetch all related tables. my $user_perms = {}; - foreach my $perm ( @$borrowerPermissions ) { - $user_perms->{ $perm->getPermissionModule->module }->{ $perm->getPermission->code } = 1; - } + try { + use Koha::Auth::PermissionManager; + my $permissionManager = Koha::Auth::PermissionManager->new(); + my $borrowerPermissions = $permissionManager->getBorrowerPermissions($userid); #Prefetch all related tables. + foreach my $perm ( @$borrowerPermissions ) { + $user_perms->{ $perm->getPermissionModule->module }->{ $perm->getPermission->code } = 1; + } + } catch { + if (blessed($_) && $_->isa('Koha::Exception::UnknownObject')) { + return $user_perms; + } + elsif (blessed($_)) { + $_->rethrow(); + } + else { + die $_; + } + }; return $user_perms; } -- 1.9.1