@@ -, +, @@ Koha/Patron.pm --- Koha/Patron.pm | 15 +++++++++++++++ Koha/Virtualshelf.pm | 16 ++++------------ Koha/Virtualshelves.pm | 4 +--- opac/opac-addbybiblionumber.pl | 3 +-- 4 files changed, 21 insertions(+), 17 deletions(-) --- a/Koha/Patron.pm +++ a/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 --- a/Koha/Virtualshelf.pm +++ a/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; } --- a/Koha/Virtualshelves.pm +++ a/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 => [ --- a/opac/opac-addbybiblionumber.pl +++ a/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 => [ --