From 26e78d4945fcf1c2dee6aab529296194dad02596 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 3 Feb 2022 16:38:43 +0000 Subject: [PATCH] Bug 29886: (QA follow-up) --- Koha/Suggestions.pm | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Koha/Suggestions.pm b/Koha/Suggestions.pm index 5fadfd163b..6a41aabd15 100644 --- a/Koha/Suggestions.pm +++ b/Koha/Suggestions.pm @@ -44,22 +44,18 @@ Returns all the suggestions the logged in user is allowed to see. sub search_limited { my ( $self, $params, $attributes ) = @_; - my $resultset = $self; - - # filter on user branch - if ( C4::Context->preference('IndependentBranches') - && !C4::Context->IsSuperLibrarian() ) - { - # If IndependentBranches is set and the logged in user is not superlibrarian - # Then we want to filter by the user's library (i.e. cannot see suggestions - # from other libraries) - my $userenv = C4::Context->userenv; - - $resultset = $self->search({ branchcode => $userenv->{branch} }) - if $userenv && $userenv->{branch}; + my $rs = $self; + + my $userenv = C4::Context->userenv; + my @restricted_branchcodes; + if ( $userenv and $userenv->{number} ) { + my $logged_in_user = Koha::Patrons->find( $userenv->{number} ); + @restricted_branchcodes = + $logged_in_user->libraries_where_can_see_patrons; + $rs = $self->search( { 'me.branchcode' => { -in => \@restricted_branchcodes } } ) + if @restricted_branchcodes; } - - return $resultset->search( $params, $attributes); + return $rs->search( $params, $attributes ); } =head2 Internal methods -- 2.20.1