x-koha-authorization:
permissions:
reserveforothers: place_holds
+"/public/items":
+ get:
+ x-mojo-to: Items#list_public
+ operationId: listItemsPublic
+ tags:
+ - items
+ summary: List items publically visible
+ parameters:
+ - name: external_id
+ in: query
+ description: Search on the item's barcode
+ required: false
+ type: string
+ - $ref: "../swagger.yaml#/parameters/match"
+ - $ref: "../swagger.yaml#/parameters/order_by"
+ - $ref: "../swagger.yaml#/parameters/page"
+ - $ref: "../swagger.yaml#/parameters/per_page"
+ - $ref: "../swagger.yaml#/parameters/q_param"
+ - $ref: "../swagger.yaml#/parameters/q_body"
+ - $ref: "../swagger.yaml#/parameters/q_header"
+ - $ref: "../swagger.yaml#/parameters/request_id_header"
+ - name: x-koha-embed
+ in: header
+ required: false
+ description: Embed list sent as a request header
+ type: array
+ items:
+ type: string
+ enum:
+ - +strings
+ collectionFormat: csv
+ consumes:
+ - application/json
+ produces:
+ - application/json
+ responses:
+ "200":
+ description: A list of item
+ schema:
+ type: array
+ items:
+ $ref: "../swagger.yaml#/definitions/item"
+ "401":
+ description: Authentication required
+ schema:
+ $ref: "../swagger.yaml#/definitions/error"
+ "403":
+ description: Access forbidden
+ schema:
+ $ref: "../swagger.yaml#/definitions/error"
+ "500":
+ description: |
+ Internal server error. Possible `error_code` attribute values:
+
+ * `internal_server_error`
+ schema:
+ $ref: "../swagger.yaml#/definitions/error"
+ "503":
+ description: Under maintenance
+ schema:
+ $ref: "../swagger.yaml#/definitions/error"
use t::lib::TestBuilder;
use t::lib::Mocks;
+use Mojo::JSON qw(encode_json);
+
use C4::Auth;
use Koha::Items;
use Koha::Database;
$schema->storage->txn_begin;
- # Clean out all demo items
- Koha::Items->delete();
+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } );
- my $patron = $builder->build_object({ class => 'Koha::Patrons' });
- my $mocked_category = Test::MockModule->new('Koha::Patron::Category');
my $exception = 1;
- $mocked_category->mock( 'override_hidden_items', sub {
- return $exception;
- });
+
+ my $mocked_category = Test::MockModule->new('Koha::Patron::Category');
+ $mocked_category->mock(
+ 'override_hidden_items',
+ sub {
+ return $exception;
+ }
+ );
my $password = 'thePassword123';
$patron->set_password( { password => $password, skip_validation => 1 } );
return $rules;
});
+ my $query = encode_json({ item_id => [ $item_1->id, $item_2->id, $item_3->id, $item_4->id, $item_5->id, $item_6->id ] });
+
+ t::lib::Mocks::mock_preference( 'RESTPublicAPI', 1 );
subtest 'anonymous access' => sub {
plan tests => 21;
+ t::lib::Mocks::mock_preference( 'RESTPublicAnonymousRequests', 1 );
+
t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
- my $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json;
+ my $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json;
is( scalar @{ $res }, 6, 'No rules set, hidelostitems unset, all items returned');
t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
- $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json;
+ $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json;
is( scalar @{ $res }, 3, 'No rules set, hidelostitems set, 3 items hidden');
t::lib::Mocks::mock_preference( 'hidelostitems', 0 );
$rules = { biblionumber => [ $biblio->biblionumber ] };
- $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json;
+ $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json;
is( scalar @{ $res }, 0, 'Biblionumber rule set, hidelostitems unset, all items hidden');
$rules = { withdrawn => [ 1, 2 ] };
- $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json;
+ $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json;
is( scalar @{ $res }, 4, 'Withdrawn rule set, hidelostitems unset, 2 items hidden');
$rules = { itype => [ $itype_1->itemtype ] };
- $res = $t->get_ok( "/api/v1/public/items" )->status_is(200)->tx->res->json;
+ $res = $t->get_ok( "/api/v1/public/items?q=" . $query )->status_is(200)->tx->res->json;
is( scalar @{ $res }, 2, 'Itype rule set, hidelostitems unset, 4 items hidden');
$rules = { withdrawn => [ 1 ] };
t::lib::Mocks::mock_preference( 'hidelostitems', 1 );
$rules = { withdrawn => [ 1, 2 ] };
- my $res = $t->get_ok("//$userid:$password@/api/v1/public/items")
+ my $res = $t->get_ok("//$userid:$password@/api/v1/public/items?q=" . $query)
->status_is(200)->tx->res->json;
is(
scalar @{$res},