From 5daaeb933cafe21714cb9c551f5a2d3634300376 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Fri, 30 Apr 2021 08:13:21 +0000 Subject: [PATCH] Bug 26346: Move checking if patron can change staff list to Koha/Patron.pm Sponsored-by: Horowhenua Library Trust, New Zealand --- Koha/Patron.pm | 15 +++++++++++++++ Koha/Virtualshelf.pm | 16 ++++------------ Koha/Virtualshelves.pm | 4 +--- opac/opac-addbybiblionumber.pl | 3 +-- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/Koha/Patron.pm b/Koha/Patron.pm index d47b3f77d2..bd0e201f41 100644 --- a/Koha/Patron.pm +++ b/Koha/Patron.pm @@ -1909,6 +1909,21 @@ sub queue_notice { return \%return; } +=head3 can_patron_change_staff_only_lists + +$patron->can_patron_change_staff_only_lists; + +Return 1 if a patron has 'Superlibrarian' or 'Catalogue' permission. +Otherwise, return 0. + +=cut + +sub can_patron_change_staff_only_lists { + my ( $self, $params ) = @_; + return 1 if C4::Auth->haspermission( $self->userid, { 'catalogue' => 1 }); + return 0; +} + =head2 Internal methods =head3 _type diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index 56ffe42d74..3a937bc9d3 100644 --- a/Koha/Virtualshelf.pm +++ b/Koha/Virtualshelf.pm @@ -184,11 +184,8 @@ sub add_biblio { )->count; return if $already_exists; - my $patron = Koha::Patrons->find( $borrowernumber ); - my $staffuser = 1 if ( C4::Auth::haspermission( $patron->userid, {'catalogue' => 1 }) ); - # Check permissions - return unless ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) || ( $self->allow_change_from_staff && $staffuser ) || $self->allow_change_from_others; + return unless ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) || ( $self->allow_change_from_staff && Koha::Patrons->find( $borrowernumber )->can_patron_change_staff_only_lists ) || $self->allow_change_from_others; my $content = Koha::Virtualshelfcontent->new( { @@ -209,11 +206,9 @@ sub remove_biblios { my $borrowernumber = $params->{borrowernumber}; return unless @$biblionumbers; - my $patron = Koha::Patrons->find( $borrowernumber ); - my $staffuser = 1 if ( haspermission( $patron->userid, {'catalogue' => 1 })); my $number_removed = 0; if( ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) - || ( $staffuser && $self->allow_change_from_staff ) + || ( $self->allow_change_from_staff && Koha::Patrons->find( $borrowernumber )->can_patron_change_staff_only_lists ) || $self->allow_change_from_others ) { $number_removed += $self->get_contents->search({ biblionumber => $biblionumbers, @@ -242,7 +237,7 @@ sub can_be_deleted { my $patron = Koha::Patrons->find( $borrowernumber ); - return 1 if $self->is_public and C4::Auth::haspermission( $patron->userid, { lists => 'delete_public_lists' } ); + return 1 if $self->is_public and haspermission( $patron->userid, { lists => 'delete_public_lists' } ); return 0; } @@ -257,12 +252,9 @@ sub can_be_managed { sub can_biblios_be_added { my ( $self, $borrowernumber ) = @_; - my $patron = Koha::Patrons->find( $borrowernumber ); - my $staffuser = 1 if ( C4::Auth::haspermission( $patron->userid, {'catalogue' => 1 } )); - return 1 if $borrowernumber - and ( ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) or ( $self->allow_change_from_staff && $staffuser ) or $self->allow_change_from_others ); + and ( ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) or ( $self->allow_change_from_staff && Koha::Patrons->find( $borrowernumber )->can_patron_change_staff_only_lists ) or $self->allow_change_from_others ); return 0; } diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 2cd1f6f7b0..8162dfd815 100644 --- a/Koha/Virtualshelves.pm +++ b/Koha/Virtualshelves.pm @@ -90,9 +90,7 @@ sub get_some_shelves { my @conditions; if ( $add_allowed ) { - my $patron = Koha::Patrons->find( $borrowernumber ); - my $staffuser = haspermission( $patron->userid, {'catalogue' => 1}); - if ( $staffuser ) { + if ( Koha::Patrons->find( $borrowernumber )->can_patron_change_staff_only_lists ) { push @conditions, { -or => [ diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl index c6a76b4715..fd654f34fa 100755 --- a/opac/opac-addbybiblionumber.pl +++ b/opac/opac-addbybiblionumber.pl @@ -119,8 +119,7 @@ if ($newvirtualshelf) { { join => 'virtualshelfshares', } ); my $public_shelves; - my $logged_in_patron = Koha::Patrons->find( $loggedinuser ); - if ( haspermission( $logged_in_patron->userid, {'catalogue' => 1})) { + if ( Koha::Patrons->find( $borrowernumber )->can_patron_change_staff_only_lists ) { $public_shelves = Koha::Virtualshelves->search( { category => 2, -or => [ -- 2.11.0