Bug 18403: Add new method Koha::Patron->can_see_patrons_from
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 7 Apr 2017 17:00:34 +0000 (14:00 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Feb 2018 18:41:40 +0000 (15:41 -0300)
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 <jon.mcgowan@ptfs-europe.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Patron.pm

index 24bb8e5..0d7cca4 100644 (file)
@@ -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));
 }