https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43606 Bug ID: 43606 Summary: Add x-koha-embed: items support to GET /biblios (list), respecting OPAC/public item visibility Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: tomascohen@gmail.com CC: tomascohen@gmail.com Target Milestone: --- The REST API endpoint GET /biblios (operationId listBiblio) can return records as MARCXML, MARC-in-JSON, USMARC and plain text via content negotiation. However, the serialized records never include item data (952 fields), even when the caller would like them embedded. Currently: * The swagger definition for GET /biblios (api/v1/swagger/paths/biblios.yaml) does not declare an x-koha-embed header parameter. Because OpenAPI input validation is strict, sending "x-koha-embed: items" against this endpoint results in an HTTP 400 response. * The controller Koha::REST::V1::Biblios::list serializes with $biblios->print_collection('marcxml'), passing no embed option. * Koha::Objects::Record::Collections::print_collection has a positional signature ( $self, $format ) and serializes each element using $element->record, i.e. the raw stored MARC with no items. As a result, clients that need biblios with items must fall back to fetching items one biblio at a time (GET /biblios/{biblio_id}/items), which is an N+1 access pattern and is significantly slower for bulk/list use cases. Proposed enhancement: Add the ability to embed items into the records returned by the list endpoints, driven by the existing x-koha-embed request header, e.g.: x-koha-embed: items Item visibility MUST be respected according to the interface the request is served on: * Staff/intranet route (GET /biblios): embed all items (subject to the existing catalogue permission already required by the endpoint). * Public route (GET /public/biblios and related public list endpoints): embed only items visible in the OPAC, honouring OpacHiddenItems and patron category override_hidden_items, consistent with how get_public, get_items_public and Items::list_public already scope items via filter_by_visible_in_opac. The building block already exists: Koha::Biblio::metadata_record already supports: $biblio->metadata_record({ embed_items => 1, interface => 'opac' | 'intranet', patron => $patron, }); which applies the EmbedItems record processor and, for the opac interface, scopes items through filter_by_visible_in_opac (plus the ViewPolicy filter). Suggested implementation outline: 1. Give print_collection a hashref-based signature that accepts embed_items (and interface/patron), choosing per element between $element->record and $element->metadata_record({ embed_items => 1, interface => ..., patron => ... }). 2. In the list controllers, read the embed list from the request (the koha.embed stash populated when x-koha-embed is sent) and pass embed_items through to print_collection. The public list controller must pass interface => 'opac' and the current patron so OPAC visibility rules apply; the staff controller passes interface => 'intranet'. 3. Declare the x-koha-embed header parameter with an "items" enum value on the listBiblio operation (and the equivalent public list operation) in the swagger spec, so the header is accepted instead of rejected with HTTP 400. This keeps serialization logic in the collection class, reuses the existing item-visibility scoping, and makes it possible to retrieve a page of biblios with their items in a single request rather than one request per record. Backwards compatibility: default behaviour (no x-koha-embed header) is unchanged and continues to return records without items. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.