https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711

--- Comment #2 from Tomás Cohen Arazi (tcohen) <[email protected]> ---
Created attachment 211059
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211059&action=edit
Bug 33711: Use Koha::Item::Availability::Checkout in the checkout endpoints

This patch makes the staff checkout routes in Koha::REST::V1::Checkouts
use Koha::Item->checkout_availability instead of calling CanBookBeIssued
and filtering its results in _check_availability. The flow mirrors the
POST /checkins one from bug 42383.

Staff routes (GET /checkouts/availability, POST /checkouts):

- the availability is checked with interface 'intranet', the logged in
  user, and the library passed explicitly: the new library_id query
  parameter (GET) or the library_id body attribute (POST), defaulting to
  the logged in library. AddIssue runs at that same library. An invalid
  library_id returns 400 (invalid_parameter_value), and a library the
  user cannot act at returns 403 (library_not_allowed). This uses
  Koha::Patron->can_log_into, the check the x-koha-library header goes
  through: with IndependentBranches only superlibrarians can use a
  library other than their own.
- blockers can be overridden with the x-koha-override header (a blocker
  key, or 'any'), if the user has circulate.force_checkout. Overridden
  blockers are reported as warnings, listed in 'forced' and passed to
  AddIssue as forced.
- keys are snake_case and payloads carry ids (see the class POD), the
  response includes 'forced', and confirmation_token is null when no
  confirmation is needed.
- missing item or patron returns 404 (render_resource_not_found).
- blockers return 403 with error_code 'checkout_blocked' and the
  blockers. Confirmations without a valid token return 412 with
  error_code 'confirmation_required', the availability and a
  confirmation_token, bound to the item, the patron and the user. The
  token is still passed as the 'confirmation' query parameter.
- AddIssue runs in a transaction, with the confirmations and forced keys
  from legacy_override_params.
- the Location header points to /api/v1/checkouts/{checkout_id}, without
  the query string (which carries the token).

The public routes (GET /public/checkouts/availability,
POST /public/patrons/{patron_id}/checkouts, OpacTrustedCheckout) shared
the controller methods with the staff ones. They are moved, unchanged, to
public_get_availability and public_add, which keep using
_check_availability. Moving the OPAC to the class is left for a separate
bug. No functional changes for them.

Contract changes for the staff routes:
- availability keys are snake_case, data keys (issued_*, res*, ...) are
  folded into the payloads, and 'forced' is added
- confirmation_token is null when no confirmation is needed
- missing item/patron: 404 instead of 409 ITEM_NOT_FOUND /
  PATRON_NOT_FOUND (POST) or 500 (GET); patron_id and item_id are
  required on GET /checkouts/availability
- blocked checkout: error_code 'checkout_blocked' and 'blockers' added
- 412 now carries the availability and a fresh confirmation_token
- library_id (body) is honoured instead of ignored
- due_date and onsite_checkout in the body are still ignored, as before
  (bug 33709 will handle them)

The cypress insertSampleCheckout helper no longer sends the random
library_id of the generated checkout, so it is still checked out at the
logged in library.

Test plan:
1. Apply this patch
2. Run:
   $ ktd --shell
  k$ yarn api:bundle
  k$ restart_all
  k$ prove t/db_dependent/api/v1/checkouts.t \
           t/db_dependent/Koha/Item/Availability/Checkout.t \
           xt/api.t
=> SUCCESS: Tests pass!
3. Enable OpacTrustedCheckout, log into the OPAC and use the self checkout
   modal to check out an item
=> SUCCESS: The item is checked out, blocked or confirmed as before
4. Sign off :-D

Assisted-by: Opus 5.5 (Anthropic)

-- 
You are receiving this mail because:
You are on the CC list for the bug.
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to