Bug 28907: REST - Remove allow-owner from public article requests cancel route

To test:
1. prove t/db_dependent/api/v1/article_requests.t
2. Apply patch
3. prove t/db_dependent/api/v1/article_requests.t

Observe success in both cases.

Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Signed-off-by: Alex Buckley <alexbuckley@catalyst.net.nz>
(cherry picked from commit 0470a59c03)
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Lari Taskula 2024-09-18 11:21:30 +00:00 committed by Fridolin Somers
parent 639140c6f4
commit 824e7991c1
3 changed files with 30 additions and 27 deletions

View File

@ -80,30 +80,31 @@ Controller function that handles cancelling a patron's Koha::ArticleRequest obje
sub patron_cancel {
my $c = shift->openapi->valid_input or return;
my $patron = Koha::Patrons->find( $c->param('patron_id') );
unless ( $patron ) {
return $c->render(
status => 404,
openapi => { error => "Patron not found" }
);
}
# patron_id has been validated by the allow-owner check, so the following call to related
# article requests covers the case of article requests not belonging to the patron
my $article_request = $patron->article_requests->find( $c->param('article_request_id') );
unless ( $article_request ) {
return $c->render(
status => 404,
openapi => { error => "Article request not found" }
);
}
my $reason = $c->param('cancellation_reason');
my $notes = $c->param('notes');
my $patron_id = $c->param('patron_id');
return try {
$c->auth->public($patron_id);
my $patron = Koha::Patrons->find($patron_id);
unless ( $patron ) {
return $c->render(
status => 404,
openapi => { error => "Patron not found" }
);
}
# patron_id has been validated by the $c->auth->public check, so the following call to related
# article requests covers the case of article requests not belonging to the patron
my $article_request = $patron->article_requests->find( $c->param('article_request_id') );
unless ( $article_request ) {
return $c->render(
status => 404,
openapi => { error => "Article request not found" }
);
}
my $reason = $c->param('cancellation_reason');
my $notes = $c->param('notes');
$article_request->cancel(
{

View File

@ -113,5 +113,3 @@
description: Under maintenance
schema:
$ref: "../swagger.yaml#/definitions/error"
x-koha-authorization:
allow-owner: true

View File

@ -84,7 +84,7 @@ subtest 'cancel() tests' => sub {
subtest 'patron_cancel() tests' => sub {
plan tests => 14;
plan tests => 17;
t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 );
t::lib::Mocks::mock_preference( 'RESTBasicAuth', 1 );
@ -116,10 +116,14 @@ subtest 'patron_cancel() tests' => sub {
my $article_request_2 = $builder->build_object({ class => 'Koha::ArticleRequests', value => { borrowernumber => $another_patron_id } });
# delete another patron's request when unauthorized
$t->delete_ok( "/api/v1/public/patrons/$another_patron_id/article_requests/" . $article_request_2->id )
->status_is(401)->json_is( '/error' => "Authentication failure." );
# delete another patron's request
$t->delete_ok("//$userid:$password@/api/v1/public/patrons/$another_patron_id/article_requests/" . $article_request_2->id)
->status_is(403)
->json_is( '/error' => 'Authorization failure. Missing required permission(s).' );
->json_is( '/error' => "Unprivileged user cannot access another user's resources" );
my $another_article_request = $builder->build_object(
{