From 38ae35332a60da74a69afb8765f8f2f3e870c11d 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: Signed-off-by: Jon McGowan Signed-off-by: Jonathan Druart --- Koha/Patron.pm | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index 24bb8e5bdc..0d7cca43c2 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -720,14 +720,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; } @@ -777,6 +790,7 @@ sub libraries_where_can_see_patrons { } } } + return sort(uniq(@restricted_branchcodes)); } -- 2.39.5