From 0bd6443bb255e863ffa5c4ae40f42212193aed0f Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Fri, 10 Jun 2022 08:26:16 +0000 Subject: [PATCH] Bug 25498: Add a transfer form for public lists Content-Type: text/plain; charset=utf-8 Test plan: [1] Valid transfer: Log in with staff patron C having edit_public_lists. Pick a public list. Choose Transfer. Select a patron. Submit and check if transfer was successful. [2] Permission problem: Pick a staff user D. Temporary enable edit_public_lists. Add another private tab. Login with D. Pick a public list. Transfer. Choose another patron. Wait. Switch tab: remove added permission from D. Switch tab again: Submit transfer form. Error? Close tab. [3] Bonus test - Shelf disappeared: Pick a public list. Transfer. Choose another patron. Wait. Open another tab. Delete the selected public list. Close tab. Submit the transfer. Not exist error? [4] Bonus test - Patron not found: Pick a public list. Transfer. Choose another patron. Wait. Open another tab. Delete selected patron. Close tab. Submit transfer. Patron not found error? Signed-off-by: Marcel de Rooy --- .../prog/en/modules/virtualshelves/shelves.tt | 72 ++++++++++++++++++- virtualshelves/shelves.pl | 19 +++++ 2 files changed, 90 insertions(+), 1 deletion(-) 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 e0e8754c03..0c21b70122 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/virtualshelves/shelves.tt @@ -114,6 +114,10 @@ [% END %] + + [% IF op == 'transfer' %] +
  • Transfer list [% shelf.shelfname | html %]
  • + [% END %] @@ -122,7 +126,7 @@
    - [% INCLUDE 'virtualshelves-toolbar.inc' %] + [% IF op != 'transfer' %][% INCLUDE 'virtualshelves-toolbar.inc' %][% END %] [% FOR m IN messages %]
    @@ -169,20 +173,57 @@ 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 'new_owner_not_found' %] + The new owner could not be found anymore. [% CASE 'no_biblio_removed' %] No record was removed. + [% CASE 'Koha::Exceptions::Virtualshelf::DuplicateObject' %] An error occurred when creating this list. The name [% shelfname | html %] already exists. [% CASE 'Koha::Exceptions::Virtualshelf::UseDbAdminAccount' %] List could not be created. (Do not use the database administrator account.) [% CASE 'DBIx::Class::Exception' %] [% m.msg | html %] + [% CASE %] [% m.code | html %] [% m.msg | html %] [% END %]
    [% END %] +[% IF op == 'transfer' %] +

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

    + +
    +
    + + + + +
    + + +
    + +
    +
    + + + +
    + +
    +
    + + Cancel +
    + +
    +
    +[% END %] + [% IF op == 'view' %]

    Contents of [% shelf.shelfname | html %]

    [% IF itemsloop %] @@ -848,6 +889,35 @@ }); [% END %] + + [% IF op == 'transfer' %] + $(document).ready(function() { + $('#find_patron').autocomplete({ + source: "/cgi-bin/koha/circ/ysearch.pl", + minLength: 3, + select: function( event, ui ) { + $('#new_owner_name').html( ui.item.firstname + " " + ui.item.surname ); + $('#new_owner').val( ui.item.borrowernumber ); + $('#find_patron').val('').focus(); + return false; + }, + }).data('ui-autocomplete')._renderItem = function( ul, item ) { + return $('
  • ') + .data( 'ui-autocomplete-item', item ) + .append( '' + item.surname + ', ' + item.firstname + '' ) + .appendTo(ul); + }; + + $('#transferform').submit(function() { + if( $('#new_owner').val() == '' ) { + alert( _("Please select a new owner first") ); + return false; + } + return true; + }); + }); + [% END %] + [% END %] diff --git a/virtualshelves/shelves.pl b/virtualshelves/shelves.pl index 44706800c7..0386268cb6 100755 --- a/virtualshelves/shelves.pl +++ b/virtualshelves/shelves.pl @@ -234,6 +234,25 @@ if ( $op eq 'add_form' ) { push @messages, { type => 'alert', code => 'does_not_exist' }; } $op = $referer; +} elsif ( $op eq 'transfer' ) { + $shelfnumber = $query->param('shelfnumber'); + $shelf = Koha::Virtualshelves->find($shelfnumber) if $shelfnumber; + my $new_owner = $query->param('new_owner'); # is a borrowernumber + + if( $new_owner ) { + $op = 'list'; + # First check: shelf found, permission, patron found? + if( !$shelf ) { + push @messages, { type => 'alert', code => 'does_not_exist' }; + } elsif( !haspermission(C4::Context->userenv->{id}, { lists => 'edit_public_lists' }) ) { + push @messages, { type => 'alert', code => 'unauthorized_transfer' }; + } elsif( !Koha::Patrons->find($new_owner) ) { + push @messages, { type => 'alert', code => 'new_owner_not_found' }; + $op = 'transfer'; # find again.. + } else { # success + $shelf->owner($new_owner)->store; + } + } } if ( $op eq 'view' ) { -- 2.20.1