From dfbbd5dfe2ee806d2e447dc7bcb5c3f1ef928193 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 all options. 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) NOTE: **Ensure the cache expiry of the SQL report is set to 0** 5. The lastseen for your new user should be null 6. 'restart_all' Koha services to clear plack cache. 7. 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) 8. Re-check the lastseen date of your new user again via SQL (step 4) The lastseen should still be null. 9. Apply Patch 10. 'restart_all' Koha services 11. Edit the TrackLastPatronActivityTriggers syspref and check the '[ ] Patron authentication via API' option 12. Rerun the api_verify_lastseen.pl 13. 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: 14. Edit the TrackLastPatronActivityTriggers syspref and **UNcheck** the '[ ] Patron authentication via API' option 15. 'restart_all' Koha services to clear plack cache. 16. Rerun the api_verify_lastseen.pl 17. 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