Add user management #18

Open
opened 2026-10-07 21:19:39 +03:00 by ars9 · 0 comments
Owner

Summary

Users and their roles can only be managed with CLI commands (#15, #17). Add a REST API and a UI page for managing users: list, create, edit, delete, reset passwords and set roles.

Managing roles themselves (creating, updating or deleting roles and their operations) is out of scope and stays CLI-only. The API only exposes a read-only list of roles, so the UI can offer them when assigning roles to a user.

User management is intentionally not exposed as MCP tools.

Requirements

Operations

Add to the operations list from #17:

Entity Modes Covers
user read, create, update, delete, grant_role, grant_admin update covers editing user details (login) and resetting another user's password; grant_role covers setting a user's roles; grant_admin is additionally required to give the admin role
role read listing roles and their operations
  • user:update does not allow changing roles.
  • user:grant_role does not imply user:grant_admin, and user:grant_admin does not imply user:grant_role. Giving a user admin requires both.
  • admin (*:*) gets these automatically; nobody doesn't.

API

Available only when auth is enabled; with auth disabled these endpoints return 404. Responses never include password hashes.

  • GET /api/v1/users (user:read) - lists users: id, login, roles, timestamps.
  • GET /api/v1/users/:id (user:read) - one user.
  • POST /api/v1/users (user:create) - body { login, password, roles? }.
    • Same rules as user:create in the CLI: password hashed with scrypt; nobody if roles is omitted or empty.
    • Passing a non-empty roles also requires user:grant_role, and user:grant_admin if it includes admin.
    • 409 if the login exists, 400 for an unknown role.
  • PATCH /api/v1/users/:id (user:update) - body { login }, edits user details. Roles and password can't be changed here.
    • Renaming is safe because tokens identify users by id (#15).
    • 409 if the new login is taken.
  • PUT /api/v1/users/:id/password (user:update) - body { password }, sets another user's password without the old one.
    • 400 for your own account: changing your own password goes through #16, which requires the old password.
  • PUT /api/v1/users/:id/roles (user:grant_role, plus user:grant_admin if the user doesn't have admin yet and the new list adds it) - body { roles: [name, ...] }.
    • Replaces the user's roles, with the same semantics as user:set_roles in #17, including for an empty list.
    • 400 for an unknown role, 409 if the change would leave no admin.
  • DELETE /api/v1/users/:id (user:delete) - deletes the user and their role assignments.
    • 400 when deleting your own account.
    • 409 if it would leave no admin.
  • GET /api/v1/roles (role:read) - lists roles: id, name, builtIn, operation patterns. Read-only.
  • 404 for an unknown user id.
  • Tokens of a deleted user stop working on their next request (401), because the user id in the token no longer resolves.
  • All endpoints are documented in Swagger.

Client

  • A new "Users" page, shown in the navigation only when auth is enabled and the user has user:read.
    • Table: login, roles, created date.
    • "Create user" form: login, password, repeat password, and roles (multi-select from GET /roles, defaulting to nobody).
    • Edit user: login.
    • Edit roles: a multi-select of all roles; built-in roles are marked.
    • Reset password: a form with new password and repeat new password fields.
    • Delete user, with a confirmation dialog.
  • Password fields have visibility toggle buttons, like on the change password page (#16).
  • Each action is shown only if the user has the matching operation:
    • Edit user and reset password need user:update; edit roles needs user:grant_role and role:read.
    • Roles are shown read-only otherwise.
    • The roles field in the create form appears only with user:grant_role and role:read. Without them, new users get nobody.
    • admin isn't selectable without user:grant_admin.
    • Reset password and delete aren't offered for your own account.
  • API errors (409 last admin, 409 login exists, 400 unknown role, 400 own account, 403 missing operation) are shown as readable messages.
  • New strings in en.json; Storybook stories for any new client/src/ui/ components.

Docs

  • docs/architecture.md: the user management API and the new operations, including how user:update, user:grant_role and user:grant_admin relate.

Acceptance criteria

  • An admin can list, create, edit and delete users, reset their passwords and set their roles from the UI.
  • A user with user:update but without user:grant_role:
    • can rename users and reset their passwords
    • gets 403 when setting roles or creating a user with roles
  • A user with user:grant_role but without user:grant_admin:
    • can set non-admin roles
    • gets 403 when adding admin to a user or creating a user with admin
  • A user with user:grant_admin but without user:grant_role can't set any roles.
  • A user with only user:read (and role:read) sees the Users page read-only; write endpoints return 403.
  • A user without user:read doesn't see the page, and GET /users returns 403.
  • Creating a user without roles gives them nobody. Duplicate logins and unknown roles are rejected.
  • After a rename, the user logs in with the new login and their existing tokens keep working.
  • Removing admin from, or deleting, the last admin is rejected with 409.
  • Deleting your own account, or resetting your own password through this endpoint, is rejected with 400.
  • After a password reset, the user can log in only with the new password.
  • After deletion, the user's existing tokens return 401.
  • With auth disabled, the endpoints return 404 and the page is hidden.
  • Server tests cover each endpoint's success, permission (403) and validation cases.
## Summary Users and their roles can only be managed with CLI commands (#15, #17). Add a REST API and a UI page for managing users: list, create, edit, delete, reset passwords and set roles. Managing roles themselves (creating, updating or deleting roles and their operations) is out of scope and stays CLI-only. The API only exposes a read-only list of roles, so the UI can offer them when assigning roles to a user. User management is intentionally **not** exposed as MCP tools. ## Requirements ### Operations Add to the operations list from #17: | Entity | Modes | Covers | |---|---|---| | `user` | `read`, `create`, `update`, `delete`, `grant_role`, `grant_admin` | `update` covers editing user details (login) and resetting another user's password; `grant_role` covers setting a user's roles; `grant_admin` is additionally required to give the `admin` role | | `role` | `read` | listing roles and their operations | - `user:update` does **not** allow changing roles. - `user:grant_role` does **not** imply `user:grant_admin`, and `user:grant_admin` does not imply `user:grant_role`. Giving a user `admin` requires both. - `admin` (`*:*`) gets these automatically; `nobody` doesn't. ### API Available only when auth is enabled; with auth disabled these endpoints return `404`. Responses never include password hashes. - `GET /api/v1/users` (`user:read`) - lists users: `id`, `login`, roles, timestamps. - `GET /api/v1/users/:id` (`user:read`) - one user. - `POST /api/v1/users` (`user:create`) - body `{ login, password, roles? }`. - Same rules as `user:create` in the CLI: password hashed with scrypt; `nobody` if `roles` is omitted or empty. - Passing a non-empty `roles` also requires `user:grant_role`, and `user:grant_admin` if it includes `admin`. - `409` if the login exists, `400` for an unknown role. - `PATCH /api/v1/users/:id` (`user:update`) - body `{ login }`, edits user details. Roles and password can't be changed here. - Renaming is safe because tokens identify users by `id` (#15). - `409` if the new login is taken. - `PUT /api/v1/users/:id/password` (`user:update`) - body `{ password }`, sets another user's password without the old one. - `400` for your own account: changing your own password goes through #16, which requires the old password. - `PUT /api/v1/users/:id/roles` (`user:grant_role`, plus `user:grant_admin` if the user doesn't have `admin` yet and the new list adds it) - body `{ roles: [name, ...] }`. - Replaces the user's roles, with the same semantics as `user:set_roles` in #17, including for an empty list. - `400` for an unknown role, `409` if the change would leave no admin. - `DELETE /api/v1/users/:id` (`user:delete`) - deletes the user and their role assignments. - `400` when deleting your own account. - `409` if it would leave no admin. - `GET /api/v1/roles` (`role:read`) - lists roles: `id`, `name`, `builtIn`, operation patterns. Read-only. - `404` for an unknown user id. - Tokens of a deleted user stop working on their next request (`401`), because the user id in the token no longer resolves. - All endpoints are documented in Swagger. ### Client - A new "Users" page, shown in the navigation only when auth is enabled and the user has `user:read`. - Table: login, roles, created date. - "Create user" form: login, password, repeat password, and roles (multi-select from `GET /roles`, defaulting to `nobody`). - Edit user: login. - Edit roles: a multi-select of all roles; built-in roles are marked. - Reset password: a form with new password and repeat new password fields. - Delete user, with a confirmation dialog. - Password fields have visibility toggle buttons, like on the change password page (#16). - Each action is shown only if the user has the matching operation: - Edit user and reset password need `user:update`; edit roles needs `user:grant_role` and `role:read`. - Roles are shown read-only otherwise. - The roles field in the create form appears only with `user:grant_role` and `role:read`. Without them, new users get `nobody`. - `admin` isn't selectable without `user:grant_admin`. - Reset password and delete aren't offered for your own account. - API errors (`409` last admin, `409` login exists, `400` unknown role, `400` own account, `403` missing operation) are shown as readable messages. - New strings in `en.json`; Storybook stories for any new `client/src/ui/` components. ### Docs - `docs/architecture.md`: the user management API and the new operations, including how `user:update`, `user:grant_role` and `user:grant_admin` relate. ## Acceptance criteria - An `admin` can list, create, edit and delete users, reset their passwords and set their roles from the UI. - A user with `user:update` but without `user:grant_role`: - can rename users and reset their passwords - gets `403` when setting roles or creating a user with roles - A user with `user:grant_role` but without `user:grant_admin`: - can set non-admin roles - gets `403` when adding `admin` to a user or creating a user with `admin` - A user with `user:grant_admin` but without `user:grant_role` can't set any roles. - A user with only `user:read` (and `role:read`) sees the Users page read-only; write endpoints return `403`. - A user without `user:read` doesn't see the page, and `GET /users` returns `403`. - Creating a user without roles gives them `nobody`. Duplicate logins and unknown roles are rejected. - After a rename, the user logs in with the new login and their existing tokens keep working. - Removing `admin` from, or deleting, the last admin is rejected with `409`. - Deleting your own account, or resetting your own password through this endpoint, is rejected with `400`. - After a password reset, the user can log in only with the new password. - After deletion, the user's existing tokens return `401`. - With auth disabled, the endpoints return `404` and the page is hidden. - Server tests cover each endpoint's success, permission (`403`) and validation cases.
ars9 added this to the User management milestone 2026-10-07 21:20:40 +03:00
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ars9/liqa#18