diff --git a/Koha/REST/V1/Checkouts.pm b/Koha/REST/V1/Checkouts.pm index 88c73f026e..b2e86603b9 100644 --- a/Koha/REST/V1/Checkouts.pm +++ b/Koha/REST/V1/Checkouts.pm @@ -27,7 +27,8 @@ use Koha::Checkouts; use Koha::Old::Checkouts; use Koha::Token; -use Try::Tiny qw( catch try ); +use Scalar::Util qw( blessed ); +use Try::Tiny qw( catch try ); =head1 NAME @@ -190,18 +191,6 @@ sub add { my $onsite = $body->{onsite_checkout}; my $barcode = $body->{external_id}; - if ( $c->stash('is_public') - && !C4::Context->preference('OpacTrustedCheckout') ) - { - return $c->render( - status => 405, - openapi => { - error => 'Feature disabled', - error_code => 'FEATURE_DISABLED' - } - ); - } - return try { unless ( $item_id or $barcode ) { @@ -214,6 +203,18 @@ sub add { ); } + if ( $c->stash('is_public') ) { + $c->auth->public($patron_id); + + return $c->render( + status => 405, + openapi => { + error => 'Feature disabled', + error_code => 'FEATURE_DISABLED' + } + ) if !C4::Context->preference('OpacTrustedCheckout'); + } + my $item; if ($item_id) { $item = Koha::Items->find($item_id); diff --git a/api/v1/swagger/paths/public_patrons.yaml b/api/v1/swagger/paths/public_patrons.yaml index df10daa2e3..203549198e 100644 --- a/api/v1/swagger/paths/public_patrons.yaml +++ b/api/v1/swagger/paths/public_patrons.yaml @@ -130,8 +130,6 @@ description: Under maintenance schema: $ref: "../swagger.yaml#/definitions/error" - x-koha-authorization: - allow-owner: true "/public/patrons/{patron_id}/guarantors/can_see_charges": put: x-mojo-to: Patrons#guarantors_can_see_charges diff --git a/t/db_dependent/api/v1/checkouts.t b/t/db_dependent/api/v1/checkouts.t index 9e20839c8f..4a5668e7eb 100755 --- a/t/db_dependent/api/v1/checkouts.t +++ b/t/db_dependent/api/v1/checkouts.t @@ -517,12 +517,8 @@ subtest 'add checkout' => sub { ->status_is(401)->json_is( { error => "Authentication failure." } ); $t->post_ok( "//$userid:$password@/api/v1/public/patrons/$patron_id/checkouts" => json => - { item_id => $item1_id, patron_id => $patron_id } )->status_is(403)->json_is( - { - error => "Authorization failure. Missing required permission(s).", - required_permissions => undef - } - ); + { item_id => $item1_id, patron_id => $patron_id } )->status_is(403) + ->json_is( { error => "Unprivileged user cannot access another user's resources" } ); $t->post_ok( "//$useridp:$password@/api/v1/public/patrons/$patron_id/checkouts" => json => { item_id => $item1_id, patron_id => $patron_id } )->status_is(201);