9d8254efd3
This enhancement adds a REST API endpoint to list a patron's recalls: /api/v1/patrons/{patron_id}/recalls This depends on the logged in patron having the manage_recalls subpermission. To test: 1. Log in to the staff interface as your superlibrarian self (Patron A) 2. Go to Koha Administration -> Global system preferences. Enable the UseRecalls system preference 3. Set the relevant recalls circulation and fines rules 4. Search for an item (Item A) 5. Check out Item A to yourself (Patron A) 6. Log in to the OPAC as Patron B, a patron who does not have the manage_recalls permission 7. Search for Item A and request a recall 8. While still logged in to the OPAC as Patron B, hit this URL: https://your-opac-url/api/v1/patrons/patron-b-borrowernumber/recalls (swap out your URL and Patron B's borrowernumber) 9. Confirm you are given an error: "Authorization failure. Missing required permission(s)." 10. Log out of the OPAC and log back in, this time as Patron A 11. Hit the URL again https://your-opac-url/api/v1/patrons/patron-b-borrowernumber/recalls 12. Confirm you are able to view a list of Patron B's recalls 13. Confirm tests pass: t/db_dependent/api/v1/patrons_recalls.t Sponsored-by: Auckland University of Technology PA amended: QA follow-up: tidy Signed-off-by: Pedro Amorim <pedro.amorim@ptfs-europe.com> Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
71 lines
2.4 KiB
Perl
Executable file
71 lines
2.4 KiB
Perl
Executable file
#!/usr/bin/env perl
|
|
|
|
# This file is part of Koha.
|
|
#
|
|
# Koha is free software; you can redistribute it and/or modify it
|
|
# under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# Koha is distributed in the hope that it will be useful, but
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with Koha; if not, see <http://www.gnu.org/licenses>.
|
|
|
|
use Modern::Perl;
|
|
|
|
use Test::More tests => 1;
|
|
use Test::Mojo;
|
|
|
|
use t::lib::TestBuilder;
|
|
use t::lib::Mocks;
|
|
|
|
use Koha::Database;
|
|
|
|
my $schema = Koha::Database->new->schema;
|
|
my $builder = t::lib::TestBuilder->new();
|
|
|
|
my $t = Test::Mojo->new('Koha::REST::V1');
|
|
|
|
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
|
|
|
|
subtest 'list() tests' => sub {
|
|
|
|
plan tests => 9;
|
|
|
|
$schema->storage->txn_begin;
|
|
|
|
my $patron = $builder->build_object(
|
|
{
|
|
class => 'Koha::Patrons',
|
|
value => { flags => 2**27 } # recalls flag == 27
|
|
}
|
|
);
|
|
my $password = 'thePassword123';
|
|
$patron->set_password( { password => $password, skip_validation => 1 } );
|
|
my $userid = $patron->userid;
|
|
|
|
$t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/recalls' )->status_is( 200, 'SWAGGER3.2.2' )
|
|
->json_is( [] );
|
|
|
|
my $recall_1 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } );
|
|
my $recall_2 = $builder->build_object( { class => 'Koha::Recalls', value => { patron_id => $patron->id } } );
|
|
|
|
$t->get_ok( "//$userid:$password@/api/v1/patrons/" . $patron->id . '/recalls?_order_by=+me.recall_id' )
|
|
->status_is( 200, 'SWAGGER3.2.2' )
|
|
->json_is( '' => [ $recall_1->to_api, $recall_2->to_api ], 'Recalls retrieved' );
|
|
|
|
my $non_existent_patron = $builder->build_object( { class => 'Koha::Patrons' } );
|
|
my $non_existent_patron_id = $non_existent_patron->id;
|
|
|
|
# get rid of the patron
|
|
$non_existent_patron->delete;
|
|
|
|
$t->get_ok( "//$userid:$password@/api/v1/patrons/" . $non_existent_patron_id . '/recalls' )->status_is(404)
|
|
->json_is( '/error' => 'Patron not found' );
|
|
|
|
$schema->storage->txn_rollback;
|
|
};
|