Admin can set a new password for a user #226

Closed
opened 2026-11-15 16:53:03 +00:00 by vivy · 7 comments
Owner

PATCH /users/{id} accepts only name, group_id and campus_id. There is no way to change a user's password, so a forgotten password locks the colleague out.

Expected: Users > Edit has "Set new password" (admin types it twice, same length rules as create). Server: a password field on PATCH (or a separate endpoint), hashed the same way as create, and the user's other sessions are ended. Only roles that may manage that user can do it. Tests.

`PATCH /users/{id}` accepts only name, group_id and campus_id. There is no way to change a user's password, so a forgotten password locks the colleague out. Expected: Users > Edit has "Set new password" (admin types it twice, same length rules as create). Server: a password field on PATCH (or a separate endpoint), hashed the same way as create, and the user's other sessions are ended. Only roles that may manage that user can do it. Tests.
Member

Read the current code: crates/server/src/users.rs matches this issue's description exactly. UpdateUserRequest on PATCH /api/v1/users/{user_id} has only name, group_id, campus_id — no password field, and no admin password-reset path exists anywhere (backend or frontend). users.manage is a global permission with no device/campus scope (Permission::accepts_device_scope puts UsersManage in the unscoped group), so "only roles that may manage that user" is already exactly what require_users_manage enforces — there is no narrower "manage that user" grant in this app to add.

I checked the whole repo (crates/server/tests, frontend-web/src) for any existing test or stub for this — none. Per our process, implementation starts from tests the QA engineer writes, not from this description alone, so I'm not coding yet.

Proposed shape, so a test can be written against something concrete — CTO, please confirm or redirect:

  • Extend the existing PATCH /users/{user_id} with an optional password: Option<String> field (reuse the endpoint rather than add a new one — it already carries one other mutable field (name) with the same "absent = unchanged" convention).
  • Validation: same rule as create_user — reject under 8 characters (weak_password).
  • Hash with the existing PasswordHasher extension, same as creation.
  • On a successful password change, delete every row in sessions for that user_id (needs a new auth::store function; none exists today beyond single-token delete_session) — so the target's other active sessions end, per the issue.
  • No current-password confirmation — this is an admin reset of someone else's password, not a self-service change.
  • Gate: require_users_manage, already in update_user.

Candidate acceptance tests for the QA engineer:

  1. Admin sets a new password for another user → 200, and the target can log in with the new password.
  2. The old password is then refused.
  3. The target's existing session cookie (acquired before the reset) no longer authenticates.
  4. A password under 8 characters is rejected (400 weak_password), and nothing changes.
  5. A caller without users.manage gets 403.
  6. An unknown user_id gets 404.
  7. Absent password field leaves the password unchanged (consistent with name/group_id/campus_id's existing "absent = unchanged" behaviour).

Marking this blocked on the CTO so the QA engineer can write the acceptance tests (or confirm the shape above and send tests over); I'll implement against them as soon as they land.

Read the current code: `crates/server/src/users.rs` matches this issue's description exactly. `UpdateUserRequest` on `PATCH /api/v1/users/{user_id}` has only `name`, `group_id`, `campus_id` — no password field, and no admin password-reset path exists anywhere (backend or frontend). `users.manage` is a global permission with no device/campus scope (`Permission::accepts_device_scope` puts `UsersManage` in the unscoped group), so "only roles that may manage that user" is already exactly what `require_users_manage` enforces — there is no narrower "manage that user" grant in this app to add. I checked the whole repo (`crates/server/tests`, `frontend-web/src`) for any existing test or stub for this — none. Per our process, implementation starts from tests the QA engineer writes, not from this description alone, so I'm not coding yet. Proposed shape, so a test can be written against something concrete — CTO, please confirm or redirect: - Extend the existing `PATCH /users/{user_id}` with an optional `password: Option<String>` field (reuse the endpoint rather than add a new one — it already carries one other mutable field (`name`) with the same "absent = unchanged" convention). - Validation: same rule as `create_user` — reject under 8 characters (`weak_password`). - Hash with the existing `PasswordHasher` extension, same as creation. - On a successful password change, delete every row in `sessions` for that `user_id` (needs a new `auth::store` function; none exists today beyond single-token `delete_session`) — so the target's other active sessions end, per the issue. - No current-password confirmation — this is an admin reset of someone else's password, not a self-service change. - Gate: `require_users_manage`, already in `update_user`. Candidate acceptance tests for the QA engineer: 1. Admin sets a new password for another user → 200, and the target can log in with the new password. 2. The old password is then refused. 3. The target's existing session cookie (acquired before the reset) no longer authenticates. 4. A password under 8 characters is rejected (400 `weak_password`), and nothing changes. 5. A caller without `users.manage` gets 403. 6. An unknown `user_id` gets 404. 7. Absent `password` field leaves the password unchanged (consistent with `name`/`group_id`/`campus_id`'s existing "absent = unchanged" behaviour). Marking this blocked on the CTO so the QA engineer can write the acceptance tests (or confirm the shape above and send tests over); I'll implement against them as soon as they land.
Member

The issue has two halves, and they are in two pull requests:

  • Server: #256 (Nyssa). PATCH /users/{id} takes an optional password. It is hashed the same way as on create and refused under 8 characters (weak_password), only users.manage may do it, and all of the user's sessions are ended.
  • Panel: #258 (me). Users > Edit has a "Set new password" section with New password and Repeat new password. The panel refuses the save when the two differ or when the password is under 8 characters. Empty fields leave the password as it is. After a successful set, a status line says the user is signed out everywhere. The four acceptance tests are in their own commit (93622df), before the code (9fc4978). local-gates.sh --frontend-only passed every gate.

Merge order: #256 before #258. Without #256 the server silently ignores password, and the panel would report success when nothing changed. CI is running on both. This issue closes when both are in dev.

The issue has two halves, and they are in two pull requests: - **Server:** #256 (Nyssa). `PATCH /users/{id}` takes an optional `password`. It is hashed the same way as on create and refused under 8 characters (`weak_password`), only `users.manage` may do it, and all of the user's sessions are ended. - **Panel:** #258 (me). Users > Edit has a "Set new password" section with *New password* and *Repeat new password*. The panel refuses the save when the two differ or when the password is under 8 characters. Empty fields leave the password as it is. After a successful set, a status line says the user is signed out everywhere. The four acceptance tests are in their own commit (93622df), before the code (9fc4978). `local-gates.sh --frontend-only` passed every gate. **Merge order: #256 before #258.** Without #256 the server silently ignores `password`, and the panel would report success when nothing changed. CI is running on both. This issue closes when both are in dev.
Member

QA review of the two GRI-2105 PRs for this issue.

#256 (Nyssa, backend) — fail-first verified, CI green

Tests map 1:1 to the candidate acceptance tests in comment 13177 (1+2 combined into one test):

  • an_admin_password_reset_lets_the_target_log_in_with_the_new_password_and_refuses_the_old_one — AC 1+2
  • an_admin_password_reset_ends_the_targets_other_sessions — AC 3
  • an_admin_password_reset_rejects_a_password_under_eight_characters — AC 4
  • a_caller_without_users_manage_cannot_reset_a_password — AC 5
  • a_password_reset_on_an_unknown_user_returns_404 — AC 6
  • an_absent_password_field_leaves_the_password_unchanged — AC 7

I checked out the tests-only commit (ab3a3b4, before the implementation commit 2b79c3c) in a scratch working tree and ran the three behaviour-changing tests against it with a real database:

test an_admin_password_reset_rejects_a_password_under_eight_characters ... FAILED (left: 200, right: 400)
test an_admin_password_reset_lets_the_target_log_in_with_the_new_password_and_refuses_the_old_one ... FAILED (left: 401, right: 200)
test an_admin_password_reset_ends_the_targets_other_sessions ... FAILED (left: 200, right: 401)
test result: FAILED. 3 passed; 3 failed

The other three pass trivially pre-implementation (404 on unknown user, 403 without users.manage, and an ignored unknown field leaving things unchanged are all pre-existing behaviour) — that's expected, not a gap. CI on 2b79c3c9 is fully green.

#258 (Soulwarden, panel) — good AAA tests, CI green

Four tests in UsersScreen.test.tsx, committed before the implementation (93622df before 9fc4978), one per criterion: sets the password, mismatch is refused, too-short is refused, empty fields leave it alone. Tests assert on visible text/roles, not internals. CI green.

Verdict: both ready. Merge #256 before #258, as both PR bodies already say (the panel's test suite doesn't exercise a live server, so the ordering is only a correctness/sequencing concern for the real deploy, not something that would show up as a CI failure).

QA review of the two GRI-2105 PRs for this issue. ## #256 (Nyssa, backend) — fail-first verified, CI green Tests map 1:1 to the candidate acceptance tests in comment 13177 (1+2 combined into one test): - `an_admin_password_reset_lets_the_target_log_in_with_the_new_password_and_refuses_the_old_one` — AC 1+2 - `an_admin_password_reset_ends_the_targets_other_sessions` — AC 3 - `an_admin_password_reset_rejects_a_password_under_eight_characters` — AC 4 - `a_caller_without_users_manage_cannot_reset_a_password` — AC 5 - `a_password_reset_on_an_unknown_user_returns_404` — AC 6 - `an_absent_password_field_leaves_the_password_unchanged` — AC 7 I checked out the tests-only commit (`ab3a3b4`, before the implementation commit `2b79c3c`) in a scratch working tree and ran the three behaviour-changing tests against it with a real database: ``` test an_admin_password_reset_rejects_a_password_under_eight_characters ... FAILED (left: 200, right: 400) test an_admin_password_reset_lets_the_target_log_in_with_the_new_password_and_refuses_the_old_one ... FAILED (left: 401, right: 200) test an_admin_password_reset_ends_the_targets_other_sessions ... FAILED (left: 200, right: 401) test result: FAILED. 3 passed; 3 failed ``` The other three pass trivially pre-implementation (404 on unknown user, 403 without `users.manage`, and an ignored unknown field leaving things unchanged are all pre-existing behaviour) — that's expected, not a gap. CI on `2b79c3c9` is fully green. ## #258 (Soulwarden, panel) — good AAA tests, CI green Four tests in `UsersScreen.test.tsx`, committed before the implementation (`93622df` before `9fc4978`), one per criterion: sets the password, mismatch is refused, too-short is refused, empty fields leave it alone. Tests assert on visible text/roles, not internals. CI green. **Verdict: both ready.** Merge #256 before #258, as both PR bodies already say (the panel's test suite doesn't exercise a live server, so the ordering is only a correctness/sequencing concern for the real deploy, not something that would show up as a CI failure).
Member

Both halves pass forge CI (22:20Z): server PR #256 on dee5dfe4 and the Users > Edit 'Set new password' panel PR #258 on 9fc4978, both fj ci exit 0, both mergeable into dev. Merge order matters: #256 first, then #258. Without #256 the server ignores the password field and the panel would report a false success. I close this issue once both are in dev.

Both halves pass forge CI (22:20Z): server PR #256 on dee5dfe4 and the Users > Edit 'Set new password' panel PR #258 on 9fc4978, both fj ci exit 0, both mergeable into dev. Merge order matters: #256 first, then #258. Without #256 the server ignores the password field and the panel would report a false success. I close this issue once both are in dev.
Member

Update at 22:51Z. The server half, #256, is in dev. Vivy merged it at 22:21Z (merge 4ccc194).

The panel half, #258, is the only part still open. dev was merged into it as 0a8516c9. CI on that commit passed (fj ci 258 exit 0), and the forge says it can be merged into dev.

@vivy: #258 is ready for you to merge. Since #256 is already in dev, merging it now is safe.

Update at 22:51Z. The server half, #256, is in `dev`. Vivy merged it at 22:21Z (merge 4ccc194). The panel half, #258, is the only part still open. `dev` was merged into it as 0a8516c9. CI on that commit passed (`fj ci 258` exit 0), and the forge says it can be merged into `dev`. @vivy: #258 is ready for you to merge. Since #256 is already in `dev`, merging it now is safe.
Author
Owner

Both halves are in dev: server #256, panel #258. Closing.

Both halves are in dev: server #256, panel #258. Closing.
vivy closed this issue 2026-11-15 23:15:59 +00:00
Member

Done. Both halves are in dev, measured at 23:22Z: fj landed GRI-2105 exit 0, ahead=0. Server side (#256, Nyssa): PATCH /users/{id} takes an optional password. It is hashed like create, uses the same weak_password rule, requires users.manage, and ends the target user's sessions. Vivy merged it at 22:21Z (4ccc194). Panel (#258): Users > Edit has 'Set new password', typed twice, with the same length rule. Vivy merged it at 22:55Z (e0f6e211). CI was green on both before the merge, and the acceptance tests went in their own commits before the code (ab3a3b4, 93622df).

Done. Both halves are in dev, measured at 23:22Z: `fj landed GRI-2105` exit 0, ahead=0. Server side (#256, Nyssa): PATCH /users/{id} takes an optional password. It is hashed like create, uses the same weak_password rule, requires users.manage, and ends the target user's sessions. Vivy merged it at 22:21Z (4ccc194). Panel (#258): Users > Edit has 'Set new password', typed twice, with the same length rule. Vivy merged it at 22:55Z (e0f6e211). CI was green on both before the merge, and the acceptance tests went in their own commits before the code (ab3a3b4, 93622df).
Sign in to join this conversation.
No project
No assignees
4 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Grimoirix/grimoire-of-digital-signage#226
No description provided.