[Bug 33711] New: Refine the token passing mechanisms introduced in bug 23336
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Bug ID: 33711 Summary: Refine the token passing mechanisms introduced in bug 23336 Change sponsored?: --- Product: Koha Version: master Hardware: All OS: All Status: NEW Severity: enhancement Priority: P5 - low Component: REST API Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@ptfs-europe.com CC: koha-bugs@lists.koha-community.org, tomascohen@gmail.com Depends on: 23336 Bug 23336 introduces an API workflow for checkouts by adding two endpoints.. one for availability that creates a token for confirmations that can then be used by the checkouts endpoint to verify that availability has been checked. Whilst I think the availability endpoint is worthwhile in it's own right, I think we could also send back the token in the 409 pre-condition failed response of the checkouts endpoint so one could use that single endpoint for double duty in the right circumstances. I also think we could work on how the confirmation token is sent to the endpoint.. it's currently a simple query param but may lend itself to being part of the x-koha-overrides header or another header? Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23336 [Bug 23336] Add an API endpoint for issuing an item to a patron -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@ptfs-europe |ity.org |.com -- You are receiving this mail because: You are the assignee for the bug. You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Martin Renvoize <martin.renvoize@ptfs-europe.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |33712 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33712 [Bug 33712] Use new checkout api's for staff client checkouts -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Bug 33711 depends on bug 23336, which changed state. Bug 23336 Summary: Add an API endpoint for checking an item out to a patron https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23336 What |Removed |Added ---------------------------------------------------------------------------- Status|Needs documenting |RESOLVED Resolution|--- |FIXED -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |36540 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=36540 [Bug 36540] Migrate checkout page to Vue -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Lisette Scheer <lisette@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact| |testopia@bugs.koha-communit | |y.org -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 211058 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211058&action=edit Bug 33711: Add Koha::Item::Availability::Checkout This patch adds a checkout availability class, mirroring Koha::Item::Availability::Checkin from bug 42383, and the Koha::Item->checkout_availability convenience method. The class wraps CanBookBeIssued (it doesn't reimplement it) and returns a Koha::Item::Availability::Checkout::Result where: - every UPPERCASE key is renamed to a snake_case key, using a documented one to one mapping (KEY_MAP and WARNING_KEY_MAP). key_from_legacy and legacy_from_key translate both ways, and legacy_override_params returns the legacy keys for AddIssue's confirmations/forced params. - the data CanBookBeIssued stores in sibling keys (issued_*, res*, current_loan_count, circulation_rule_TOO_MANY, item_notforloan, branch_to_return, ...) becomes the payload of the key it relates to. Payloads carry ids instead of objects (recall_id, booking_id, patron_id, hold_id) so callers can fetch or embed them, and dates (the due date, the high holds return date) as RFC3339 strings. - the business rules callers applied on top of CanBookBeIssued are applied in the class: AllowHoldCheckoutOverride hold promotion and OnSiteCheckoutsForce relaxation (from circ/circulation.pl), the circulate.force_checkout requirement for every confirmation but high_holds and additional_materials (from circulation.tt), and the public route promotions and stripping (from Koha::REST::V1::Checkouts::_check_availability), selected with the 'interface' param. - the 'overrides' param replaces circ/circulation.pl's 'forceallow', following the 'overrides' param of the hold availability classes (bug 42386): a hashref of blocker keys, or { any => 1 }. When the user has circulate.force_checkout, the overridden blockers (but unknown_barcode, no_open_days and statistical_patron, and the holds when AllowHoldCheckoutOverride is disabled) are relaxed like OnSiteCheckoutsForce does: reported as warnings and recorded as forced, so AddIssue logs them. to_api lists them under 'forced'. Confirmations are not affected, they still need the token. - the 'library' param sets the library the check is done for. It defaults to the user environment's library, which CanBookBeIssued reads, and is restored afterwards. Checking availability doesn't write anything. CanBookBeIssued records a 'localuse' statistic and updates datelastseen for statistical patrons, so they are detected up front and a statistical_patron blocker is returned without calling CanBookBeIssued. This leaves CanBookBeIssued and its callers (SIP, ILS-DI, curbside pickup, ILL, SCO) untouched. The result's token is bound to the item, the patron and the user, so a confirmation obtained for one patron cannot be used for another one. Callers are not changed yet, that will be done in a follow-up. Test plan: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Item/Availability/Checkout.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Depends on|23336 |42383 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23336 [Bug 23336] Add an API endpoint for checking an item out to a patron https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42383 [Bug 42383] Migrate check-in page to Vue -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |23336 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=23336 [Bug 23336] Add an API endpoint for checking an item out to a patron -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |david@davidnind.com --- Comment #3 from David Nind <david@davidnind.com> --- Note: Dependent bug Bug 42425 - Add checkin_id FK to accountlines to link fee adjustments to checkin events does not apply (and is failed QA). -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211058|0 |1 is obsolete| | Attachment #211059|0 |1 is obsolete| | -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #4 from David Nind <david@davidnind.com> --- Created attachment 211926 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211926&action=edit Bug 33711: Add Koha::Item::Availability::Checkout This patch adds a checkout availability class, mirroring Koha::Item::Availability::Checkin from bug 42383, and the Koha::Item->checkout_availability convenience method. The class wraps CanBookBeIssued (it doesn't reimplement it) and returns a Koha::Item::Availability::Checkout::Result where: - every UPPERCASE key is renamed to a snake_case key, using a documented one to one mapping (KEY_MAP and WARNING_KEY_MAP). key_from_legacy and legacy_from_key translate both ways, and legacy_override_params returns the legacy keys for AddIssue's confirmations/forced params. - the data CanBookBeIssued stores in sibling keys (issued_*, res*, current_loan_count, circulation_rule_TOO_MANY, item_notforloan, branch_to_return, ...) becomes the payload of the key it relates to. Payloads carry ids instead of objects (recall_id, booking_id, patron_id, hold_id) so callers can fetch or embed them, and dates (the due date, the high holds return date) as RFC3339 strings. - the business rules callers applied on top of CanBookBeIssued are applied in the class: AllowHoldCheckoutOverride hold promotion and OnSiteCheckoutsForce relaxation (from circ/circulation.pl), the circulate.force_checkout requirement for every confirmation but high_holds and additional_materials (from circulation.tt), and the public route promotions and stripping (from Koha::REST::V1::Checkouts::_check_availability), selected with the 'interface' param. - the 'overrides' param replaces circ/circulation.pl's 'forceallow', following the 'overrides' param of the hold availability classes (bug 42386): a hashref of blocker keys, or { any => 1 }. When the user has circulate.force_checkout, the overridden blockers (but unknown_barcode, no_open_days and statistical_patron, and the holds when AllowHoldCheckoutOverride is disabled) are relaxed like OnSiteCheckoutsForce does: reported as warnings and recorded as forced, so AddIssue logs them. to_api lists them under 'forced'. Confirmations are not affected, they still need the token. - the 'library' param sets the library the check is done for. It defaults to the user environment's library, which CanBookBeIssued reads, and is restored afterwards. Checking availability doesn't write anything. CanBookBeIssued records a 'localuse' statistic and updates datelastseen for statistical patrons, so they are detected up front and a statistical_patron blocker is returned without calling CanBookBeIssued. This leaves CanBookBeIssued and its callers (SIP, ILS-DI, curbside pickup, ILL, SCO) untouched. The result's token is bound to the item, the patron and the user, so a confirmation obtained for one patron cannot be used for another one. Callers are not changed yet, that will be done in a follow-up. Test plan: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Item/Availability/Checkout.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #5 from David Nind <david@davidnind.com> --- Created attachment 211927 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=211927&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) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #6 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212399 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212399&action=edit Bug 33711: (follow-up) Refer to other patrons by id only CanBookBeIssued returns the name and cardnumber of the patron the item is checked out to (issued_*) or on hold for (res*). The availability payloads passed them on, next to the patron_id, without checking if the user is allowed to see that patron (library groups 'Hide patron info', IndependentBranches). The staff routes exposed them through the API. This patch makes the issued_to_another and hold payloads carry the patron_id only, as the API definition already described: callers fetch or embed the patrons, so the information the user is not allowed to see is redacted. Test plan: 1. Apply this patch 2. Run: $ ktd --shell k$ restart_all k$ prove t/db_dependent/Koha/Item/Availability/Checkout.t \ t/db_dependent/api/v1/checkouts.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #7 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212400 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212400&action=edit Bug 33711: (follow-up) Do not find patrons the user cannot see GET /checkouts/availability and POST /checkouts looked the patron up with Koha::Patrons->find, so a staff user could check the availability for, and check out to, a patron they are not allowed to see (library groups 'Hide patron info', IndependentBranches). circ/circulation.pl refuses that. This patch makes the patron the pivot: it is looked up through Koha::Patrons->search_limited, like GET /patrons/{patron_id} does, and patrons the user cannot see return 404. The existing get_availability() and add() tests are about circulation, not patron visibility: their staff users are given the view_borrower_infos_from_any_libraries permission, and the IndependentBranches tests use a patron from the librarian's library. A new subtest covers the visibility rules. 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 \ xt/api.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #8 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212401 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212401&action=edit Bug 33711: (follow-up) Use snake_case error codes on POST /checkouts The staff POST /checkouts route contract changes on this bug, and it still returned the uppercase error codes from bug 23336, and no error_code when AddIssue fails. This patch renames them, as the API coding guidelines require: - MISSING_OR_WRONG_PARAMETERS => item_id_or_external_id_required - ITEM_ID_NOT_MATCHING_EXTERNAL_ID => item_id_not_matching_external_id - the 500 returned when AddIssue fails carries internal_server_error The public route (POST /public/patrons/{patron_id}/checkouts) keeps its codes, as it is left unchanged on this bug. 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 \ xt/api.t => SUCCESS: Tests pass! 3. 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.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Needs Signoff -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|martin.renvoize@openfifth.c |tomascohen@gmail.com |o.uk | -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #211926|0 |1 is obsolete| | Attachment #211927|0 |1 is obsolete| | Attachment #212399|0 |1 is obsolete| | Attachment #212400|0 |1 is obsolete| | Attachment #212401|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #9 from David Nind <david@davidnind.com> --- Created attachment 212433 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212433&action=edit Bug 33711: Add Koha::Item::Availability::Checkout This patch adds a checkout availability class, mirroring Koha::Item::Availability::Checkin from bug 42383, and the Koha::Item->checkout_availability convenience method. The class wraps CanBookBeIssued (it doesn't reimplement it) and returns a Koha::Item::Availability::Checkout::Result where: - every UPPERCASE key is renamed to a snake_case key, using a documented one to one mapping (KEY_MAP and WARNING_KEY_MAP). key_from_legacy and legacy_from_key translate both ways, and legacy_override_params returns the legacy keys for AddIssue's confirmations/forced params. - the data CanBookBeIssued stores in sibling keys (issued_*, res*, current_loan_count, circulation_rule_TOO_MANY, item_notforloan, branch_to_return, ...) becomes the payload of the key it relates to. Payloads carry ids instead of objects (recall_id, booking_id, patron_id, hold_id) so callers can fetch or embed them, and dates (the due date, the high holds return date) as RFC3339 strings. - the business rules callers applied on top of CanBookBeIssued are applied in the class: AllowHoldCheckoutOverride hold promotion and OnSiteCheckoutsForce relaxation (from circ/circulation.pl), the circulate.force_checkout requirement for every confirmation but high_holds and additional_materials (from circulation.tt), and the public route promotions and stripping (from Koha::REST::V1::Checkouts::_check_availability), selected with the 'interface' param. - the 'overrides' param replaces circ/circulation.pl's 'forceallow', following the 'overrides' param of the hold availability classes (bug 42386): a hashref of blocker keys, or { any => 1 }. When the user has circulate.force_checkout, the overridden blockers (but unknown_barcode, no_open_days and statistical_patron, and the holds when AllowHoldCheckoutOverride is disabled) are relaxed like OnSiteCheckoutsForce does: reported as warnings and recorded as forced, so AddIssue logs them. to_api lists them under 'forced'. Confirmations are not affected, they still need the token. - the 'library' param sets the library the check is done for. It defaults to the user environment's library, which CanBookBeIssued reads, and is restored afterwards. Checking availability doesn't write anything. CanBookBeIssued records a 'localuse' statistic and updates datelastseen for statistical patrons, so they are detected up front and a statistical_patron blocker is returned without calling CanBookBeIssued. This leaves CanBookBeIssued and its callers (SIP, ILS-DI, curbside pickup, ILL, SCO) untouched. The result's token is bound to the item, the patron and the user, so a confirmation obtained for one patron cannot be used for another one. Callers are not changed yet, that will be done in a follow-up. Test plan: 1. Apply this patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Koha/Item/Availability/Checkout.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #10 from David Nind <david@davidnind.com> --- Created attachment 212434 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212434&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) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #11 from David Nind <david@davidnind.com> --- Created attachment 212435 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212435&action=edit Bug 33711: (follow-up) Refer to other patrons by id only CanBookBeIssued returns the name and cardnumber of the patron the item is checked out to (issued_*) or on hold for (res*). The availability payloads passed them on, next to the patron_id, without checking if the user is allowed to see that patron (library groups 'Hide patron info', IndependentBranches). The staff routes exposed them through the API. This patch makes the issued_to_another and hold payloads carry the patron_id only, as the API definition already described: callers fetch or embed the patrons, so the information the user is not allowed to see is redacted. Test plan: 1. Apply this patch 2. Run: $ ktd --shell k$ restart_all k$ prove t/db_dependent/Koha/Item/Availability/Checkout.t \ t/db_dependent/api/v1/checkouts.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #12 from David Nind <david@davidnind.com> --- Created attachment 212436 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212436&action=edit Bug 33711: (follow-up) Do not find patrons the user cannot see GET /checkouts/availability and POST /checkouts looked the patron up with Koha::Patrons->find, so a staff user could check the availability for, and check out to, a patron they are not allowed to see (library groups 'Hide patron info', IndependentBranches). circ/circulation.pl refuses that. This patch makes the patron the pivot: it is looked up through Koha::Patrons->search_limited, like GET /patrons/{patron_id} does, and patrons the user cannot see return 404. The existing get_availability() and add() tests are about circulation, not patron visibility: their staff users are given the view_borrower_infos_from_any_libraries permission, and the IndependentBranches tests use a patron from the librarian's library. A new subtest covers the visibility rules. 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 \ xt/api.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are on the CC list for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=33711 --- Comment #13 from David Nind <david@davidnind.com> --- Created attachment 212437 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212437&action=edit Bug 33711: (follow-up) Use snake_case error codes on POST /checkouts The staff POST /checkouts route contract changes on this bug, and it still returned the uppercase error codes from bug 23336, and no error_code when AddIssue fails. This patch renames them, as the API coding guidelines require: - MISSING_OR_WRONG_PARAMETERS => item_id_or_external_id_required - ITEM_ID_NOT_MATCHING_EXTERNAL_ID => item_id_not_matching_external_id - the 500 returned when AddIssue fails carries internal_server_error The public route (POST /public/patrons/{patron_id}/checkouts) keeps its codes, as it is left unchanged on this bug. 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 \ xt/api.t => SUCCESS: Tests pass! 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes. You are on the CC list for the bug.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org