Bug 18403: Add new method Koha::Patron->can_see_patron_info
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 6 Apr 2017 19:10:18 +0000 (16:10 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Mon, 12 Feb 2018 18:41:37 +0000 (15:41 -0300)
Technical note:
This is the method that will be called on the logged_in_user variable sent to
the template. Moreover we will check that the logged in user can access patron'
information when access to members/* and some circulation scripts will be done.

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 e83eed6..782e5ee 100644 (file)
@@ -709,6 +709,39 @@ sub account_locked {
           and $self->login_attempts >= $FailedLoginAttempts )? 1 : 0;
 }
 
+=head3 can_see_patron_infos
+
+my $can_see = $patron->can_see_patron_infos( $patron );
+
+Return true if the patron (usually the logged in user) can see the patron's infos for a given patron
+
+=cut
+
+sub can_see_patron_infos {
+    my ( $self, $patron ) = @_;
+    my $can = 0;
+    if ( $self->branchcode eq $patron->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 ) ) {
+                $can = 1;
+                last;
+            }
+        }
+    }
+    return $can;
+}
+
+sub can {
+    my ( $self, $flagsrequired ) = @_;
+    return unless $self->userid;
+    # TODO code from haspermission needs to be moved here!
+    return C4::Auth::haspermission( $self->userid, $flagsrequired );
+}
+
 =head3 type
 
 =cut