[Bug 42998] New: Allow a requested due date when renewing a checkout via the REST API
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Bug ID: 42998 Summary: Allow a requested due date when renewing a checkout via the REST API 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: martin.renvoize@openfifth.co.uk QA Contact: testopia@bugs.koha-community.org CC: tomascohen@gmail.com Target Milestone: --- Depends on bug 42997 (booking/checkout due date synchronisation). This patch extends the checkout renewal endpoints so API consumers can renew a checkout through to a specific date: - an optional request body may carry a due_date (RFC3339); it is used in place of the due date calculated from the circulation rules and is validated against any bookings for the item via CanBookBeRenewed. When the checkout is linked to a booking, AddRenewal keeps the booking end date in sync (bug 42997) - a new renewal_limit value is accepted in the x-koha-override header, skipping renewal count limits when AllowRenewalLimitOverride is enabled - intended for staff explicitly authorising an extension of a booked loan - the 403 error response now carries the CanBookBeRenewed error as a machine-readable error_code (e.g. 'booked', 'too_many') The requested due date is a body attribute rather than a query parameter or override: the POST creates a renewal resource and the date is data about that renewal. The existing 'seen' query parameter predates the current guidelines and has been left untouched. Both /checkouts/{checkout_id}/renewal and the newer /checkouts/{checkout_id}/renewals route to the same controller, so the body is accepted and documented on both. Test plan: 1. yarn api:bundle && restart_all 2. Run t/db_dependent/api/v1/checkouts.t -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |42997 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42997 [Bug 42997] Keep booking end dates in sync with checkout due dates at issue and renewal -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |42790 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42790 [Bug 42790] Clarify and unify bookings actions to 'Edit, Cancel, Checkout, Extend' shown appropriate per status and permission -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Patch complexity|--- |Small patch Sponsorship status|--- |Unsponsored Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk Status|NEW |Needs Signoff -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 201548 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=201548&action=edit Bug 42998: Allow a requested due date on the checkout renewal endpoints This patch extends the checkout renewal endpoints so API consumers can renew a checkout through to a specific date, providing the server-side pathway for extending issued bookings through their linked checkout (bug 42997, bug 42790): * an optional request body may carry a `due_date` (RFC3339); it is passed through to CanBookBeRenewed - so it is validated against bookings for the item - and then to AddRenewal, which keeps any linked booking's end_date in sync * a new `renewal_limit` value is accepted in the x-koha-override header, skipping renewal count limits when AllowRenewalLimitOverride is enabled - staff extending a booked loan should not be blocked by the renewal count * the 403 error response now carries the CanBookBeRenewed error as a machine-readable `error_code` (e.g. 'booked', 'too_many') Both /checkouts/{checkout_id}/renewal and the newer /checkouts/{checkout_id}/renewals route to the same controller, so the body and override are accepted and documented on both. The requested due date is a body attribute rather than a query parameter or override: the POST creates a renewal resource and the date is data about that renewal. The existing 'seen' query parameter predates the current guidelines and has been left untouched. Test plan: 1) yarn api:bundle && restart_all 2) Run t/db_dependent/api/v1/checkouts.t and confirm the new 'renew() with requested due_date and bookings' subtest passes -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Sponsorship status|Unsponsored |Sponsored Status|Needs Signoff |Signed Off Comma delimited| |OpenFifth list of Sponsors| |<https://openfifth.co.uk/\> | |, Westminster City Council | |<https://www.westminster.go | |v.uk/\> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #201548|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #2 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 202371 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202371&action=edit Bug 42998: Allow a requested due date on the checkout renewal endpoints This patch extends the checkout renewal endpoints so API consumers can renew a checkout through to a specific date, providing the server-side pathway for extending issued bookings through their linked checkout (bug 42997, bug 42790): * an optional request body may carry a `due_date` (RFC3339); it is passed through to CanBookBeRenewed - so it is validated against bookings for the item - and then to AddRenewal, which keeps any linked booking's end_date in sync * a new `renewal_limit` value is accepted in the x-koha-override header, skipping renewal count limits when AllowRenewalLimitOverride is enabled - staff extending a booked loan should not be blocked by the renewal count * the 403 error response now carries the CanBookBeRenewed error as a machine-readable `error_code` (e.g. 'booked', 'too_many') Both /checkouts/{checkout_id}/renewal and the newer /checkouts/{checkout_id}/renewals route to the same controller, so the body and override are accepted and documented on both. The requested due date is a body attribute rather than a query parameter or override: the POST creates a renewal resource and the date is data about that renewal. The existing 'seen' query parameter predates the current guidelines and has been left untouched. Test plan: 1) yarn api:bundle && restart_all 2) Run t/db_dependent/api/v1/checkouts.t and confirm the new 'renew() with requested due_date and bookings' subtest passes Sponsored-by: OpenFifth <https://openfifth.co.uk/\> Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/\> Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Signed Off |Passed QA QA Contact|testopia@bugs.koha-communit |paul.derscheid@lmscloud.de |y.org | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #202371|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #3 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 202497 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=202497&action=edit Bug 42998: Allow a requested due date on the checkout renewal endpoints This patch extends the checkout renewal endpoints so API consumers can renew a checkout through to a specific date, providing the server-side pathway for extending issued bookings through their linked checkout (bug 42997, bug 42790): * an optional request body may carry a `due_date` (RFC3339); it is passed through to CanBookBeRenewed - so it is validated against bookings for the item - and then to AddRenewal, which keeps any linked booking's end_date in sync * a new `renewal_limit` value is accepted in the x-koha-override header, skipping renewal count limits when AllowRenewalLimitOverride is enabled - staff extending a booked loan should not be blocked by the renewal count * the 403 error response now carries the CanBookBeRenewed error as a machine-readable `error_code` (e.g. 'booked', 'too_many') Both /checkouts/{checkout_id}/renewal and the newer /checkouts/{checkout_id}/renewals route to the same controller, so the body and override are accepted and documented on both. The requested due date is a body attribute rather than a query parameter or override: the POST creates a renewal resource and the date is data about that renewal. The existing 'seen' query parameter predates the current guidelines and has been left untouched. Test plan: 1) yarn api:bundle && restart_all 2) Run t/db_dependent/api/v1/checkouts.t and confirm the new 'renew() with requested due_date and bookings' subtest passes Sponsored-by: OpenFifth <https://openfifth.co.uk/\> Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/\> Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #4 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205298 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205298&action=edit Bug 42998: (QA follow-up) Reject a malformed requested due_date cleanly A due_date that passes the swagger date-time format check (which permits an instant with no timezone offset) but fails Koha's own stricter RFC3339 parser was falling through to dt_from_string's uncaught exception, producing a generic 500 instead of a clear 400. Wrap the parse and return render_invalid_parameter_value on failure, and cover it with a test. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #202497|0 |1 is obsolete| | Attachment #205298|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #5 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205479 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205479&action=edit Bug 42998: Allow a requested due date on the checkout renewal endpoints This patch extends the checkout renewal endpoints so API consumers can renew a checkout through to a specific date, providing the server-side pathway for extending issued bookings through their linked checkout (bug 42997, bug 42790): * an optional request body may carry a `due_date` (RFC3339); it is passed through to CanBookBeRenewed - so it is validated against bookings for the item - and then to AddRenewal, which keeps any linked booking's end_date in sync * a new `renewal_limit` value is accepted in the x-koha-override header, skipping renewal count limits when AllowRenewalLimitOverride is enabled - staff extending a booked loan should not be blocked by the renewal count * the 403 error response now carries the CanBookBeRenewed error as a machine-readable `error_code` (e.g. 'booked', 'too_many') Both /checkouts/{checkout_id}/renewal and the newer /checkouts/{checkout_id}/renewals route to the same controller, so the body and override are accepted and documented on both. The requested due date is a body attribute rather than a query parameter or override: the POST creates a renewal resource and the date is data about that renewal. The existing 'seen' query parameter predates the current guidelines and has been left untouched. Test plan: 1) yarn api:bundle && restart_all 2) Run t/db_dependent/api/v1/checkouts.t and confirm the new 'renew() with requested due_date and bookings' subtest passes Sponsored-by: OpenFifth <https://openfifth.co.uk/\> Sponsored-by: Westminster City Council <https://www.westminster.gov.uk/\> Signed-off-by: Hannah Dunne-Howrie <hdunne-howrie@westminster.gov.uk> Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #6 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205480 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205480&action=edit Bug 42998: (QA follow-up) Reject a malformed requested due_date cleanly A due_date that passes the swagger date-time format check (which permits an instant with no timezone offset) but fails Koha's own stricter RFC3339 parser was falling through to dt_from_string's uncaught exception, producing a generic 500 instead of a clear 400. Wrap the parse and return render_invalid_parameter_value on failure, and cover it with a test. Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #7 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 205481 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=205481&action=edit Bug 42998: (QA follow-up) Document error_code values on the renew endpoints The requested-due-date work added error_code to the renew endpoints' 400/403 responses (Checkouts.pm's render_invalid_parameter_value and the CanBookBeRenewed error passthrough), but the swagger docs still just said "Bad request" / "Cannot renew checkout". Enumerate the values, matching the style already used for the booking endpoints in this same series. Signed-off-by: Martin Renvoize <martin.renvoize@openfifth.co.uk> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Lucas Gass (lukeg) <lucas@bywatersolutions.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |lucas@bywatersolutions.com Keywords| |release-notes-needed -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Passed QA |Failed QA CC| |pedro.amorim@openfifth.co.u | |k --- Comment #8 from Pedro Amorim (ammopt) <pedro.amorim@openfifth.co.uk> --- Hi all, 2 small things, steps below. Setup: Inside KTD, rebuild the API bundle and restart plack: $ ktd --shell k$ yarn api:bundle k$ koha-plack --restart kohadev Set these system preferences, clicking the save button under each one: 'AllowRenewalLimitOverride' to 'Allow', click 'Save all Circulation preferences': http://localhost:8081/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=AllowRenewalLimitOverride 'RenewalLog' to 'Log', click 'Save all Logging preferences': http://localhost:8081/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RenewalLog 'RestrictionBlockRenewing' to 'block', click 'Save all Circulation preferences': http://localhost:8081/cgi-bin/koha/admin/preferences.pl?op=search&searchfield=RestrictionBlockRenewing Check out item '3999900000001' to patron '42': http://localhost:8081/cgi-bin/koha/circ/circulation.pl?findborrower=42 Grab the checkout id: k$ koha-mysql kohadev -e "SELECT issue_id FROM issues WHERE borrowernumber=(SELECT borrowernumber FROM borrowers WHERE cardnumber='42') ORDER BY issue_id DESC LIMIT 1" 1. The renewal_limit override isn't recorded in the action log The staff interface adds 'RENEWAL_LIMIT' to the renewal log's confirmations when the limit is overridden (svc/renew and circ/renew.pl). The API passes no confirmations to AddRenewal, so overrides made through the API leave no audit trail. 1) Renew through the API with the override (replace <id>): k$ curl -s -o /dev/null -w '%{http_code}\n' -u koha:koha -X POST -H 'x-koha-override: renewal_limit' http://localhost:8081/api/v1/checkouts/<id>/renewal 2) Confirm 201 3) Check the log entry: k$ koha-mysql kohadev -e "SELECT info FROM action_logs WHERE module='CIRCULATION' AND action='RENEWAL' ORDER BY action_id DESC LIMIT 1" 4) Confirm '"confirmations" : []', no 'RENEWAL_LIMIT' 2. The spec understates what renewal_limit bypasses (it also bypasses RestrictionBlockRenewing) The spec says renewal_limit "skips the renewal count limits", but it sets override_limit in CanBookBeRenewed, which also skips restrictions, overdues, fines, the auto-renewal checks and 'too_soon'. The behaviour matches the staff interface override, only the description is wrong. 1) On patron '42''s page, go to the 'Restrictions' tab, click 'Add manual restriction', then 'Add restriction' 2) Renew without the override: k$ curl -s -u koha:koha -X POST http://localhost:8081/api/v1/checkouts/<id>/renewal 3) Confirm 403 with 'error_code' 'restriction' 4) Renew with the override: k$ curl -s -o /dev/null -w '%{http_code}\n' -u koha:koha -X POST -H 'x-koha-override: renewal_limit' http://localhost:8081/api/v1/checkouts/<id>/renewal 5) Confirm 201: the restriction was bypassed -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #9 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Hi Pedro, good finds. I will take a look at this. -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 Paul Derscheid <paul.derscheid@lmscloud.de> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Failed QA |Passed QA -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #10 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 209881 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209881&action=edit Bug 42998: (QA follow-up) Log the renewal_limit override in the renewal log The staff interface records RENEWAL_LIMIT in the renewal log's confirmations when the limit is overridden. The API passed none, so overrides made through it left no audit trail. - Pass RENEWAL_LIMIT to AddRenewal when the override is in effect, as circ/renew.pl does - Test both the overridden and plain renewal log entries Test plan: 1. prove t/db_dependent/api/v1/checkouts.t Assisted-by: Claude Opus 5.5 (Anthropic) Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #11 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Created attachment 209882 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=209882&action=edit Bug 42998: (QA follow-up) Describe what the renewal_limit override bypasses Assisted-by: Claude Opus 5.5 (Anthropic) Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=42998 --- Comment #12 from Paul Derscheid <paul.derscheid@lmscloud.de> --- Hi Pedro, I think this should do it. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org