From 7365aa2b131a236aade6b3149343e82f2c38ebf7 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 20 Dec 2018 13:42:08 +0000 Subject: [PATCH] Bug 22031: Adjust haspermission to take an array To test: 1 - Apply this patch on top of unit tests 2 - Unit tests now pass 3 - Ensure you can use Koha as before with no regressions --- C4/Auth.pm | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/C4/Auth.pm b/C4/Auth.pm index b19197b35b..6dbe7eed1d 100644 --- a/C4/Auth.pm +++ b/C4/Auth.pm @@ -2039,20 +2039,27 @@ sub haspermission { my $flags = getuserflags( $row, $userid ); return $flags if $flags->{superlibrarian}; - foreach my $module ( keys %$flagsrequired ) { - my $subperm = $flagsrequired->{$module}; - if ( $subperm eq '*' ) { - return 0 unless ( $flags->{$module} == 1 or ref( $flags->{$module} ) ); + my $subperms = $flagsrequired->{$module}; + my @sub_loop; + if ( ref($subperms) eq 'ARRAY' ) { + @sub_loop = @$subperms; } else { - return 0 unless ( - ( defined $flags->{$module} and - $flags->{$module} == 1 ) - or - ( ref( $flags->{$module} ) and - exists $flags->{$module}->{$subperm} and - $flags->{$module}->{$subperm} == 1 ) - ); + push @sub_loop, $subperms; + } + foreach my $subperm (@sub_loop){ + if ( $subperm eq '*' ) { + return 0 unless ( $flags->{$module} == 1 or ref( $flags->{$module} ) ); + } else { + return 0 unless ( + ( defined $flags->{$module} and + $flags->{$module} == 1 ) + or + ( ref( $flags->{$module} ) and + exists $flags->{$module}->{$subperm} and + $flags->{$module}->{$subperm} == 1 ) + ); + } } } return $flags; -- 2.11.0