From cca177876637832cb4f374be8b0d055bad05e171 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 7 Apr 2017 14:00:34 -0300 Subject: [PATCH] Bug 18403: Add new method Koha::Patron->can_see_patrons_from Technical note: Sometimes we do not have the patron object, for instance for the patron modifications we will need to know if the logged in user can modify patron's from a given library. This new subroutine 'can_see_patrons_from' will then be useful Signed-off-by: Jon McGowan --- Koha/Patron.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index af62ecb..83cabd9 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -595,14 +595,27 @@ Return true if the patron (usually the logged in user) can see the patron's info sub can_see_patron_infos { my ( $self, $patron ) = @_; + return $self->can_see_patrons_from( $patron->library->branchcode ); +} + +=head3 can_see_patrons_from + +my $can_see = $patron->can_see_patrons_from( $branchcode ); + +Return true if the patron (usually the logged in user) can see the patron's infos from a given library + +=cut + +sub can_see_patrons_from { + my ( $self, $branchcode ) = @_; my $can = 0; - if ( $self->branchcode eq $patron->branchcode ) { + if ( $self->branchcode eq $branchcode ) { $can = 1; } elsif ( $self->can( { borrowers => 'view_borrower_infos_from_any_libraries' } ) ) { $can = 1; } elsif ( my $library_groups = $self->library->library_groups ) { while ( my $library_group = $library_groups->next ) { - if ( $library_group->parent->has_child( $patron->library->branchcode ) ) { + if ( $library_group->parent->has_child( $branchcode ) ) { $can = 1; last; } @@ -652,6 +665,7 @@ sub libraries_where_can_see_patrons { } } } + return sort(uniq(@restricted_branchcodes)); } -- 2.1.4