[Bug 44230] New: Allow overriding NotifyPasswordChange in POST /patrons/{patron_id}/password
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 Bug ID: 44230 Summary: Allow overriding NotifyPasswordChange in POST /patrons/{patron_id}/password 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: tomascohen@gmail.com QA Contact: tomascohen@gmail.com CC: tomascohen@gmail.com Target Milestone: --- POST /patrons/{patron_id}/password always follows the NotifyPasswordChange system preference: if it is enabled, the patron gets the PASSWORD_CHANGE notice, otherwise they do not. API consumers (e.g. identity management / account provisioning integrations doing bulk or initial password sets) need to decide per request whether the patron should be notified, independently of the system preference. This bug adds support for the x-koha-override header on this endpoint, following the pattern already used by POST /patrons (welcome_yes / welcome_no): * notify_yes: send the PASSWORD_CHANGE notice even if NotifyPasswordChange is disabled * notify_no: never send the notice for this request * no override: current behaviour (follow NotifyPasswordChange) If both are passed, notify_yes takes precedence (same as welcome_yes). The existing conditions still apply when sending: the password must actually change and the patron must have a notice email address. Koha::Patron->set_password gets an optional "notify" parameter to support this. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212402 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212402&action=edit Bug 44230: Add 'notify' to POST /patrons/{patron_id}/password This patch adds an optional `notify` boolean attribute to the request body of POST /patrons/{patron_id}/password so API consumers can decide, per request, whether the patron gets the PASSWORD_CHANGE notice: * notify: true -> send the notice, even if NotifyPasswordChange is disabled * notify: false -> do not send the notice, even if NotifyPasswordChange is enabled * not passed -> current behavior (NotifyPasswordChange decides) To support it, Koha::Patron->set_password gets an optional `notify` parameter that, when defined, takes precedence over the NotifyPasswordChange system preference. The existing conditions still apply: the notice is only sent if the password actually changes and the patron has a notice email address. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ yarn api:bundle k$ prove xt/api.t \ t/db_dependent/Koha/Patron.t \ t/db_dependent/Koha/Patrons.t \ t/db_dependent/api/v1/patrons_password.t => SUCCESS: Tests pass! 3. Restart services: k$ restart_all 4. Enable RESTBasicAuth and NotifyPasswordChange, and pick a patron with an email address 5. Change the patron's password, passing "notify": false: $ curl -u koha:koha -X POST \ http://localhost:8081/api/v1/patrons/<patron_id>/password \ -H 'Content-Type: application/json' \ -d '{"password":"Abcd1234!","password_2":"Abcd1234!","notify":false}' 6. Check the patron's notices tab => SUCCESS: No 'Password change' notice was generated 7. Repeat 5 with a new password and without "notify" => SUCCESS: A 'Password change' notice was generated 8. Disable NotifyPasswordChange and repeat 5 with a new password and "notify": true => SUCCESS: A 'Password change' notice was generated 9. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Summary|Allow overriding |Add 'notify' option to POST |NotifyPasswordChange in |/patrons/{patron_id}/passwo |POST |rd |/patrons/{patron_id}/passwo | |rd | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | Status|NEW |Needs Signoff QA Contact|tomascohen@gmail.com |testopia@bugs.koha-communit | |y.org -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212406 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212406&action=edit Bug 44230: Add suppress_password_change_notice permission This patch adds a new `borrowers` subpermission: `suppress_password_change_notice`. It will be required for explicitly preventing the PASSWORD_CHANGE notice from being sent when setting a patron's password through the API. Test plan: 1. Apply patch 2. Run the DB update: $ ktd --shell k$ updatedatabase => SUCCESS: "Added new permission 'suppress_password_change_notice'" is displayed 3. Run it again => SUCCESS: No errors (update is idempotent) 4. Go to a staff patron's 'More > Set permissions' page 5. Expand 'Add, modify and view patron information (borrowers)' => SUCCESS: 'Change patron passwords without sending the password change notice (suppress_password_change_notice)' is listed 6. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 --- Comment #3 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212407 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212407&action=edit Bug 44230: (follow-up) Require permission to suppress the notice and log it The PASSWORD_CHANGE notice is how patrons learn about unexpected password changes. Allowing any API caller to suppress it would let leaked integration credentials take over accounts silently. This patch: * Requires the new `borrowers.suppress_password_change_notice` permission for passing `notify: false` to POST /patrons/{patron_id}/password. The check is done early in the controller, which returns 403 with `error_code: no_permission_for_notice_suppression` otherwise. * Changes the endpoint authorization from the full `borrowers` module to `borrowers.edit_borrowers`, matching the staff interface (members/member-password.pl). Holding the full module implies every `borrowers` subpermission, so with the previous requirement the new permission could never be withheld. * Makes Koha::Patron->set_password always log the password change when the notice is explicitly suppressed, even if BorrowersLog is disabled. The log entry has 'PASSWORD_CHANGE notice suppressed' as info and records who did it. * Documents the requirements in the endpoint description. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ updatedatabase k$ yarn api:bundle k$ prove xt/api.t \ t/db_dependent/Koha/Patron.t \ t/db_dependent/Koha/Patrons.t \ t/db_dependent/api/v1/patrons_password.t => SUCCESS: Tests pass! 3. Restart services: k$ restart_all 4. Enable RESTBasicAuth, disable BorrowersLog 5. Create a staff user with only the 'edit_borrowers' permission and set a password for them 6. Using that user, set a patron's password passing "notify": false: $ curl -u <user>:<password> -X POST \ http://localhost:8081/api/v1/patrons/<patron_id>/password \ -H 'Content-Type: application/json' \ -d '{"password":"Abcd1234!","password_2":"Abcd1234!","notify":false}' => SUCCESS: 403, error_code is no_permission_for_notice_suppression 7. Repeat 6 without "notify" => SUCCESS: 200, the password is changed 8. Grant the user the 'suppress_password_change_notice' permission and repeat 6 => SUCCESS: 200, no 'Password change' notice is generated 9. Go to Tools > Log viewer, filter by module 'Patrons' => SUCCESS: The 'CHANGE PASS' entry for the patron says 'PASSWORD_CHANGE notice suppressed' and the librarian is recorded, even though BorrowersLog is disabled 10. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |nick@bywatersolutions.com -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44230 --- Comment #4 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Design update: the final implementation differs from the original description. 1. Body attribute instead of x-koha-override The request body of this endpoint is not a resource representation (unlike POST /patrons, which is why welcome_yes/welcome_no had to be headers), so the option is now an optional boolean in the body: { "password": "...", "password_2": "...", "notify": true|false } * notify: true -> send PASSWORD_CHANGE even if NotifyPasswordChange is disabled * notify: false -> do not send it, even if NotifyPasswordChange is enabled * omitted -> NotifyPasswordChange decides (current behavior) The notice is still only sent if the password actually changes and the patron has a notice email address. Koha::Patron->set_password gets a matching optional 'notify' parameter. 2. Suppressing the notice is permission-gated and always logged The PASSWORD_CHANGE notice is how patrons find out about unexpected password changes, so silently suppressing it would make account takeovers with leaked integration credentials invisible. Therefore: * notify: false requires the new borrowers.suppress_password_change_notice permission. It is checked early in the controller; otherwise the endpoint returns 403 with error_code 'no_permission_for_notice_suppression'. * Explicit suppression is always recorded in the action logs (MEMBERS / CHANGE PASS, info 'PASSWORD_CHANGE notice suppressed', with the acting user), even if BorrowersLog is disabled. * notify: true needs no extra permission. 3. Endpoint authorization changed to borrowers.edit_borrowers The endpoint used to require the full 'borrowers' module, which implies every borrowers subpermission, so the new permission could never be withheld. It now requires borrowers.edit_borrowers, the same as the staff interface (members/member-password.pl). Note this means staff with only edit_borrowers can now use the endpoint, matching what they can already do in the staff interface. The public (patron self-service) password endpoint is unchanged and does not accept 'notify'. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org