From 4c4ae76ecee3e695df51fbb20553b017e0260c78 Mon Sep 17 00:00:00 2001 From: CJ Lynce Date: Mon, 18 Aug 2025 19:02:41 +0000 Subject: [PATCH] Bug 36536: Make REST APIs validateUserAndPassword update borrowers.lastseen This patch added the option to update borrowers.lastseen when a patron username and password is verified via the REST API. This can be enabled or disabled selectively using the TrackLastPatronActivityTriggers system preference using the [ ] Patron authentication via API option.. To test: 1. Create a new user, ensuring to set the Username and password fields. *Import to do this first* 2. Edit the TrackLastPatronActivityTriggers syspref and check 'login 3. Ensure the RESTBasicAuth syspref is set to Enable. 4. Check the lastseen date of your new user using a SQL report SELECT borrowernumber, userid, lastseen FROM borrowers WHERE userid = 'USERNAME' (Replace USERNAME with your chosen username for the new patron) 5. The lastseen for your new user should be null 6. Run the attached api_verify_lastseen.pl test script **Change P_USERNAME and P_PASSWORD to the username and password of your new user. (script contains expected output for successful verification) 7. Re-check the lastseen date of your new user again via SQL (step 4) The lastseen should still be null. 8. Apply Patch 9. Edit the TrackLastPatronActivityTriggers syspref and check the '[ ] Patron authentication via API' option 10. Rerun the api_verify_lastseen.pl 11. Re-check the lastseen date of your new user again via SQL (step 4) The lastseen should now be updated to the time of the last script run. For good measure: 12. Edit the TrackLastPatronActivityTriggers syspref and **UNcheck** the '[ ] Patron authentication via API' option 13. Rerun the api_verify_lastseen.pl 14. Re-check the lastseen date of your new user again via SQL (step 4) The lastseen should have remained the same as previous. Sponsored-by: Westlake Porter Public Library --- Koha/REST/V1/Auth/Password.pm | 3 +++ .../prog/en/modules/admin/preferences/patrons.pref | 1 + 2 files changed, 4 insertions(+) diff --git a/Koha/REST/V1/Auth/Password.pm b/Koha/REST/V1/Auth/Password.pm index d1af05f962..20a5e550c1 100644 --- a/Koha/REST/V1/Auth/Password.pm +++ b/Koha/REST/V1/Auth/Password.pm @@ -80,6 +80,9 @@ sub validate { ); } + #record patron activity + $patron->update_lastseen('api_verify'); + return $c->render( status => 201, openapi => { diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref index 5a84a24557..2cf9001222 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/patrons.pref @@ -110,6 +110,7 @@ Patrons: check_in: "Checking in an item" hold: "Placing a hold on an item" article: "Placing an article request" + api_verify: "Patron authentication via API" - - pref: AutoApprovePatronProfileSettings choices: -- 2.39.5