From 32fe4c63b6e385ab5effc961c21e8e266b4fef82 Mon Sep 17 00:00:00 2001 From: Alex Buckley Date: Wed, 14 Apr 2021 14:06:48 +1200 Subject: [PATCH] Bug 26346: Add option to make public lists editable by all staff If a staff member has access to the staff client (either because 'catalogue' permission is enabled or they're a superlibrarian then that user can add items (from OPAC or staff client) to a list marked 'Staff only' Test plan: 1. In the staff client go to: Lists > 'New list'. Notice under 'Allow changes to contents from' there are three options: Nobody, Owner only, Anyone seeing this list 2. Apply patch and run updatedatabase.pl cd installer/data/mysql sudo koha-shell ./updatedatabase.pl 3. Restart memcached and plack 4. Create a public list and select the new 'Staff only' option under 'Allow changes to contents from' 5. Log out of the staff client and log back in as a different user with the 'Staff access, allows viewing of catalogue in staff interface (catalogue)' permission enabled. 6. Navigate to the Lists module, and click on the name of the list you created in #5 7. Select 'Add items' and enter an item barcode and submit 8. Notice the item has been added to the list 9. Search the catalogue in the staff client. Confirm you can add to the list you created in #5 from both the search result page and biblio record detail page 10. Login to the OPAC as the same user as #5 11. Perform an OPAC search, Select 'Save to lists' under a biblio record, choose the list from #4 in 'Select a list' and save 12. Confirm in the staff client that the record from #11 has been added to the list 13. Logout of OPAC and login again as a user which does not have 'Staff access, allows viewing of catalogue in staff interface (catalogue)' or superlibrarian enabled 14. Do a OPAC search, hit 'Save to lists' and notice you cannot add the record to the list from #4 Sponsored-by: Horowhenua Library Trust, New Zealand --- 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 diff --git a/Koha/Schema/Result/Letter.pm b/Koha/Schema/Result/Letter.pm index 613c4d9b274..b5627b96744 100644 --- a/Koha/Schema/Result/Letter.pm +++ b/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'; diff --git a/Koha/Schema/Result/Virtualshelve.pm b/Koha/Schema/Result/Virtualshelve.pm index 4fa1265959f..709b3f9f1e0 100644 --- a/Koha/Schema/Result/Virtualshelve.pm +++ b/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'; diff --git a/Koha/Virtualshelf.pm b/Koha/Virtualshelf.pm index c27c695ada6..4360b60cf95 100644 --- a/Koha/Virtualshelf.pm +++ b/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; + diff --git a/Koha/Virtualshelves.pm b/Koha/Virtualshelves.pm index 3dde3c35da4..2cd1f6f7b0e 100644 --- a/Koha/Virtualshelves.pm +++ b/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, { diff --git a/installer/data/mysql/atomicupdate/bug_26346.perl b/installer/data/mysql/atomicupdate/bug_26346.perl new file mode 100644 index 00000000000..a3470125ad2 --- /dev/null +++ b/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" ); +} diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt index db6f2da101f..ea6690c6106 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/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 %] +   diff --git a/opac/opac-addbybiblionumber.pl b/opac/opac-addbybiblionumber.pl index 3563dfc300d..c6a76b47159 100755 --- a/opac/opac-addbybiblionumber.pl +++ b/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, diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index d233eb1355b..8b8e1bc4e02 100755 --- a/virtualshelves/shelves.pl +++ b/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 }; -- 2.11.0