@@ -, +, @@ staff --- Koha/Schema/Result/Letter.pm | 6 +-- Koha/Schema/Result/Virtualshelve.pm | 12 +++++- Koha/Virtualshelf.pm | 12 ++++-- Koha/Virtualshelves.pm | 38 ++++++++++++++----- installer/data/mysql/atomicupdate/bug_26346.perl | 7 ++++ .../prog/en/modules/virtualshelves/shelves.tt | 2 + opac/opac-addbybiblionumber.pl | 43 ++++++++++++++++------ virtualshelves/shelves.pl | 3 ++ 8 files changed, 92 insertions(+), 31 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_26346.perl --- a/Koha/Schema/Result/Letter.pm +++ a/Koha/Schema/Result/Letter.pm @@ -29,8 +29,6 @@ __PACKAGE__->table("letter"); is_auto_increment: 1 is_nullable: 0 -primary key identifier - =head2 module data_type: 'varchar' @@ -217,8 +215,8 @@ __PACKAGE__->belongs_to( ); -# Created by DBIx::Class::Schema::Loader v0.07046 @ 2021-02-11 12:33:50 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qqdTVEicMu5rHppY5qsEuA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2021-04-09 22:58:34 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:2QkUwMWgZ9WfOk9Ngf7yFA sub koha_object_class { 'Koha::Notice::Template'; --- a/Koha/Schema/Result/Virtualshelve.pm +++ a/Koha/Schema/Result/Virtualshelve.pm @@ -97,6 +97,12 @@ can owner change contents? can others change contents? +=head2 allow_change_from_staff + + data_type: 'tinyint' + default_value: 0 + is_nullable: 1 + =cut __PACKAGE__->add_columns( @@ -132,6 +138,8 @@ __PACKAGE__->add_columns( { data_type => "tinyint", default_value => 1, is_nullable => 1 }, "allow_change_from_others", { data_type => "tinyint", default_value => 0, is_nullable => 1 }, + "allow_change_from_staff", + { data_type => "tinyint", default_value => 0, is_nullable => 1 }, ); =head1 PRIMARY KEY @@ -199,8 +207,8 @@ __PACKAGE__->has_many( ); -# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29 -# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:6ZQ6kL/0DzyOMymz+4+LhA +# Created by DBIx::Class::Schema::Loader v0.07046 @ 2021-04-09 23:02:21 +# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:4FyGa/O1QtVe1t5ih9PK5A sub koha_object_class { 'Koha::Virtualshelf'; --- a/Koha/Virtualshelf.pm +++ a/Koha/Virtualshelf.pm @@ -184,8 +184,11 @@ 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_others; + return unless ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) || ( $self->allow_change_from_staff && $staffuser ) || $self->allow_change_from_others; my $content = Koha::Virtualshelfcontent->new( { @@ -251,9 +254,12 @@ 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_others ); + and ( ( $self->owner == $borrowernumber && $self->allow_change_from_owner ) or ( $self->allow_change_from_staff && $staffuser ) or $self->allow_change_from_others ); return 0; } @@ -267,4 +273,4 @@ sub _type { return 'Virtualshelve'; } -1; + --- a/Koha/Virtualshelves.pm +++ a/Koha/Virtualshelves.pm @@ -23,6 +23,8 @@ use Koha::Database; use Koha::Virtualshelf; +use C4::Auth; + use base qw(Koha::Objects); =head1 NAME @@ -88,16 +90,32 @@ sub get_some_shelves { my @conditions; if ( $add_allowed ) { - push @conditions, { - -or => - [ - { - "me.owner" => $borrowernumber, - "me.allow_change_from_owner" => 1, - }, - "me.allow_change_from_others" => 1, - ] - }; + my $patron = Koha::Patrons->find( $borrowernumber ); + my $staffuser = haspermission( $patron->userid, {'catalogue' => 1}); + if ( $staffuser ) { + push @conditions, { + -or => + [ + { + "me.owner" => $borrowernumber, + "me.allow_change_from_owner" => 1, + }, + "me.allow_change_from_others" => 1, + "me.allow_change_from_staff" => 1 + ] + }; + } else { + push @conditions, { + -or => + [ + { + "me.owner" => $borrowernumber, + "me.allow_change_from_owner" => 1, + }, + "me.allow_change_from_others" => 1, + ] + }; + } } if ( $category == 1 ) { push @conditions, { --- a/installer/data/mysql/atomicupdate/bug_26346.perl +++ a/installer/data/mysql/atomicupdate/bug_26346.perl @@ -0,0 +1,7 @@ +$DBversion = 'XXX'; +if ( CheckVersion($DBversion) ) { + if ( !column_exists( 'virtualshelves', 'allow_change_from_staff' ) ) { + $dbh->do(q{ALTER TABLE virtualshelves ADD COLUMN `allow_change_from_staff` tinyint(1) DEFAULT '0'}); + } + NewVersion( $DBversion, 26346, "Add allow_change_from_staff to virtualshelves table" ); +} --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -25,6 +25,8 @@ [% IF shelf.allow_change_from_others %][% ELSE %][% END %] + [% IF shelf.allow_change_from_staff %][% ELSE %][% END %] +   --- a/opac/opac-addbybiblionumber.pl +++ a/opac/opac-addbybiblionumber.pl @@ -118,18 +118,37 @@ if ($newvirtualshelf) { }, { join => 'virtualshelfshares', } ); - my $public_shelves = Koha::Virtualshelves->search( - { category => 2, - -or => [ - -and => { - allow_change_from_owner => 1, - owner => $loggedinuser, - }, - allow_change_from_others => 1, - ], - }, - { order_by => 'shelfname' } - ); + my $public_shelves; + my $logged_in_patron = Koha::Patrons->find( $loggedinuser ); + if ( haspermission( $logged_in_patron->userid, {'catalogue' => 1})) { + $public_shelves = Koha::Virtualshelves->search( + { category => 2, + -or => [ + -and => { + allow_change_from_owner => 1, + owner => $loggedinuser, + }, + allow_change_from_others => 1, + allow_change_from_staff => 1 + ], + }, + { order_by => 'shelfname' } + ); + } else { + $public_shelves = Koha::Virtualshelves->search( + { category => 2, + -or => [ + -and => { + allow_change_from_owner => 1, + owner => $loggedinuser, + }, + allow_change_from_others => 1, + ], + }, + {order_by => 'shelfname' } + ); + } + $template->param( private_shelves => $private_shelves, private_shelves_shared_with_me => $shelves_shared_with_me, --- a/virtualshelves/shelves.pl +++ a/virtualshelves/shelves.pl @@ -36,6 +36,7 @@ use Koha::Patrons; use Koha::Virtualshelves; use constant ANYONE => 2; +use constant STAFF => 3; my $query = CGI->new; @@ -79,6 +80,7 @@ if ( $op eq 'add_form' ) { category => scalar $query->param('category'), allow_change_from_owner => $allow_changes_from > 0, allow_change_from_others => $allow_changes_from == ANYONE, + allow_change_from_staff => $allow_changes_from == STAFF, owner => scalar $query->param('owner'), } ); @@ -108,6 +110,7 @@ if ( $op eq 'add_form' ) { my $allow_changes_from = $query->param('allow_changes_from'); $shelf->allow_change_from_owner( $allow_changes_from > 0 ); $shelf->allow_change_from_others( $allow_changes_from == ANYONE ); + $shelf->allow_change_from_staff( $allow_changes_from == STAFF ); $shelf->category( scalar $query->param('category') ); eval { $shelf->store }; --