@@ -, +, @@ --- C4/Auth.pm | 4 ++++ Koha/REST/V1/Auth.pm | 2 +- svc/members/search | 2 +- t/db_dependent/Auth/haspermission.t | 14 +++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) --- a/C4/Auth.pm +++ a/C4/Auth.pm @@ -2072,6 +2072,10 @@ sub _dispatch { sub haspermission { my ( $userid, $flagsrequired ) = @_; + + Koha::Exceptions::WrongParameter->throw('$flagsrequired should not be undef') + unless defined($flagsrequired); + my $sth = C4::Context->dbh->prepare("SELECT flags FROM borrowers WHERE userid=?"); $sth->execute($userid); my $row = $sth->fetchrow(); --- a/Koha/REST/V1/Auth.pm +++ a/Koha/REST/V1/Auth.pm @@ -189,7 +189,7 @@ sub authenticate_api_request { # Manually pass the remote_address to check_auth_cookie my $remote_addr = $c->tx->remote_address; my ($status, $sessionID) = check_cookie_auth( - $cookie, undef, + $cookie, '*', { remote_addr => $remote_addr }); if ($status eq "ok") { my $session = get_session($sessionID); --- a/svc/members/search +++ a/svc/members/search @@ -91,7 +91,7 @@ if ($has_permission) { my ( $permission, $subpermission ) = split /\./, $has_permission; my @patrons_with_permission; for my $patron ( @{ $results->{patrons} } ) { - my $perms = haspermission( $patron->{userid} ); + my $perms = haspermission( $patron->{userid}, '*' ); if ( $perms->{superlibrarian} == 1 or $perms->{$permission} == 1 ) { --- a/t/db_dependent/Auth/haspermission.t +++ a/t/db_dependent/Auth/haspermission.t @@ -20,7 +20,8 @@ # along with Koha; if not, see . use Modern::Perl; -use Test::More tests => 3; +use Test::More tests => 4; +use Test::Exception; use Koha::Database; use t::lib::TestBuilder; @@ -70,6 +71,17 @@ $builder->build( } ); +subtest 'undef top level tests' => sub { + + plan tests => 2; + + throws_ok { my $r = haspermission( $borr1->{userid} ); } + 'Koha::Exceptions::WrongParameter', + 'Exception thrown when missing $requiredflags'; + throws_ok { my $r = haspermission( $borr1->{userid}, undef ); } + 'Koha::Exceptions::WrongParameter', 'Exception thrown when explicit undef'; +}; + subtest 'scalar top level tests' => sub { plan tests => 3; --