View | Details | Raw Unified | Return to bug 29886
Collapse All | Expand All

(-)a/Koha/Suggestions.pm (-16 / +11 lines)
Lines 44-65 Returns all the suggestions the logged in user is allowed to see. Link Here
44
sub search_limited {
44
sub search_limited {
45
    my ( $self, $params, $attributes ) = @_;
45
    my ( $self, $params, $attributes ) = @_;
46
46
47
    my $resultset = $self;
47
    my $rs = $self;
48
48
49
    # filter on user branch
49
    my $userenv = C4::Context->userenv;
50
    if (   C4::Context->preference('IndependentBranches')
50
    my @restricted_branchcodes;
51
        && !C4::Context->IsSuperLibrarian() )
51
    if ( $userenv and $userenv->{number} ) {
52
    {
52
        my $logged_in_user = Koha::Patrons->find( $userenv->{number} );
53
        # If IndependentBranches is set and the logged in user is not superlibrarian
53
        @restricted_branchcodes =
54
        # Then we want to filter by the user's library (i.e. cannot see suggestions
54
          $logged_in_user->libraries_where_can_see_patrons;
55
        # from other libraries)
55
        $rs = $self->search( { 'me.branchcode' => { -in => \@restricted_branchcodes } } )
56
        my $userenv = C4::Context->userenv;
56
          if @restricted_branchcodes;
57
58
        $resultset = $self->search({ branchcode => $userenv->{branch} })
59
            if $userenv && $userenv->{branch};
60
    }
57
    }
61
58
    return $rs->search( $params, $attributes );
62
    return $resultset->search( $params, $attributes);
63
}
59
}
64
60
65
=head2 Internal methods
61
=head2 Internal methods
66
- 

Return to bug 29886