From 721fbc1140238bff1b29befd18485c6c85a9166f Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 13 Jun 2022 09:40:07 +0000 Subject: [PATCH] Bug 25498: Transfer ownership shared list on OPAC Content-Type: text/plain; charset=utf-8 Test plan: Pick or create a shared list. Login as owner. Transfer to one of the other members. Verify that you do no longer have Transfer, but see Remove share. Login as the other member. Transfer it back. Bonus: Working with two tabs, you can open the Transfer form and in the meantime delete the list, the patron or remove the share. Or change permissions. Submit after that and check the error message. Signed-off-by: Marcel de Rooy --- Koha/Virtualshelfshare.pm | 22 ++++++++++++- .../bootstrap/en/modules/opac-shelves.tt | 31 ++++++++++++++++++ opac/opac-shelves.pl | 32 ++++++++++++++++++- 3 files changed, 83 insertions(+), 2 deletions(-) diff --git a/Koha/Virtualshelfshare.pm b/Koha/Virtualshelfshare.pm index 64e13bd542..16bd017351 100644 --- a/Koha/Virtualshelfshare.pm +++ b/Koha/Virtualshelfshare.pm @@ -23,6 +23,7 @@ use DateTime::Duration; use Koha::Database; use Koha::DateUtils qw( dt_from_string ); use Koha::Exceptions; +use Koha::Patron; use base qw(Koha::Object); @@ -38,7 +39,7 @@ Koha::Virtualshelfshare - Koha Virtualshelfshare Object class =cut -=head3 type +=head3 accept =cut @@ -66,6 +67,10 @@ sub accept { } } +=head3 has_expired + +=cut + sub has_expired { my ($self) = @_; my $dt_sharedate = dt_from_string( $self->sharedate, 'sql' ); @@ -76,6 +81,21 @@ sub has_expired { return $has_expired == 1 ? 1 : 0 } +=head3 patron + + Returns related Koha::Patron object for this share. + +=cut + +sub patron { + my $self = shift; + return Koha::Patron->_new_from_dbic( $self->{_result}->borrowernumber ); +} + +=head3 _type + +=cut + sub _type { return 'Virtualshelfshare'; } diff --git a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt index 0fd48bca39..0096019579 100644 --- a/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt +++ b/koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-shelves.tt @@ -182,8 +182,15 @@ You do not have permission to delete this list. [% CASE 'unauthorized_on_add_biblio' %] You do not have permission to add a record to this list. + [% CASE 'unauthorized_transfer' %] + You do not have permission to transfer ownership of this list. [% CASE 'no_biblio_removed' %] No record was removed. + [% CASE 'new_owner_not_found' %] + The new owner could not be found anymore. + [% CASE 'new_owner_has_no_share' %] + The new owner has no share for this list. + [% CASE 'Koha::Exceptions::Virtualshelf::DuplicateObject' %] An error occurred when creating the list. The name [% shelfname | html %] already exists. [% CASE 'DBIx::Class::Exception' %] @@ -635,6 +642,30 @@ + [% ELSIF op == 'transfer' %] +

Transfer ownership of shared list '[% shelf.shelfname | html %]'

+
+
+
+ + + +
+ + +
+
+
+ + Cancel +
+
+
+ [% ELSIF op == 'list' %]

Lists

diff --git a/opac/opac-shelves.pl b/opac/opac-shelves.pl index 5bd342f514..cce27b9f05 100755 --- a/opac/opac-shelves.pl +++ b/opac/opac-shelves.pl @@ -38,9 +38,11 @@ use Koha::Biblios; use Koha::Biblioitems; use Koha::CirculationRules; use Koha::CsvProfiles; +use Koha::DateUtils qw/dt_from_string/; use Koha::Items; use Koha::ItemTypes; use Koha::Patrons; +use Koha::Virtualshelfshares; use Koha::Virtualshelves; use Koha::RecordProcessor; @@ -257,7 +259,35 @@ if ( $op eq 'add_form' ) { } $op = 'view'; } elsif( $op eq 'transfer' ) { - $op = 'list'; # TODO + $shelfnumber = $query->param('shelfnumber'); + $shelf = Koha::Virtualshelves->find($shelfnumber) if $shelfnumber; + my $new_owner = $query->param('new_owner'); # borrowernumber or undef + + $op = 'list'; + if( !$shelf ) { + push @messages, { type => 'error', code => 'does_not_exist' }; + } elsif( $shelf->public or !$shelf->is_shared or !$shelf->can_be_managed($loggedinuser) ) { + push @messages, { type => 'error', code => 'unauthorized_transfer' }; + } elsif( !$new_owner ) { + my $patrons = []; + my $shares = $shelf->get_shares->search({ borrowernumber => { '!=' => undef } }); + while( my $share = $shares->next ) { + push @$patrons, { email => $share->patron->notice_email_address, borrowernumber => $share->get_column('borrowernumber') }; + } + $template->param( shared_users => $patrons ); + $op = 'transfer'; + } elsif( !Koha::Patrons->find($new_owner) ) { + push @messages, { type => 'error', code => 'new_owner_not_found' }; + } elsif( !$shelf->get_shares->search({ borrowernumber => $new_owner })->count ) { + push @messages, { type => 'error', code => 'new_owner_has_no_share' }; + } else { + # Remove from virtualshelfshares new_owner, add loggedinuser + $shelf->_result->result_source->schema->txn_do( sub { + $shelf->get_shares->search({ borrowernumber => $new_owner })->delete; + Koha::Virtualshelfshare->new({ shelfnumber => $shelfnumber, borrowernumber => $loggedinuser, sharedate => dt_from_string })->store; + $shelf->owner($new_owner)->store; + }); + } } # PART 2: After a possible action, view one list or show a number of lists -- 2.20.1