Files
co-lite/openspec/specs/admin-users/spec.md
T
ngqileandClaude Opus 5.5 4acfaff8e5 docs(openspec): archive add-admin-auth-users-roles
Adds the admin-access, admin-users and admin-roles main specs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
2026-11-26 22:40:58 +08:00

86 lines
3.6 KiB
Markdown

# admin-users Specification
## Purpose
Admins with the Users module manage staff accounts: who can log in, which roles they hold, and which company they belong to.
## Requirements
### Requirement: User list
The system SHALL list admin users only (never members), paginated on the server, searchable by name, username or email, filterable by active state, and sortable by column.
#### Scenario: Search
- **GIVEN** admin users `sales1` and `sales2` and a member `m100`
- **WHEN** an admin with `BO_USERS` searches for `sales`
- **THEN** the list shows `sales1` and `sales2` and not `m100`
### Requirement: Create user
The system SHALL let an admin with `BO_USERS` create an admin user with name, username, email and one or more roles. Username and email SHALL be unique. The new user SHALL receive a temporary password by email and SHALL belong to the creating admin's company.
#### Scenario: New user
- **WHEN** an admin creates user `sales1` with email `sales1@example.com` and role Sales
- **THEN** the user is saved as active with a pending password change
- **AND** a temporary password is emailed to `sales1@example.com`
- **AND** the user's company is the creating admin's company
#### Scenario: Duplicate username
- **GIVEN** a user `sales1` exists
- **WHEN** an admin creates another user with username `sales1`
- **THEN** the save is refused and the form shows that the username is taken
### Requirement: Edit and deactivate user
The system SHALL let an admin with `BO_USERS` change a user's name, email, roles and active state. A deactivated user SHALL NOT be able to log in, and a session they already hold SHALL be refused on its next `/api/admin/**` call. An admin SHALL NOT be able to deactivate their own account. An admin who is not super admin SHALL NOT change the roles on their own account. No admin SHALL assign `ROLE_ADMIN` or `ROLE_MEMBER` when creating or editing a user.
#### Scenario: Deactivate
- **GIVEN** user `sales1` is signed in
- **WHEN** an admin deactivates `sales1`
- **THEN** `sales1`'s next `/api/admin/**` call responds 401
- **AND** `sales1` can no longer log in
#### Scenario: Self-deactivation
- **WHEN** an admin tries to deactivate their own account
- **THEN** the save is refused with a message
#### Scenario: Own roles
- **GIVEN** an admin who is not super admin and holds `ROLE_SALES`
- **WHEN** they save their own account with a different set of roles
- **THEN** the save is refused with a message and their roles are unchanged
#### Scenario: Hidden roles
- **WHEN** an admin creates or edits a user with `ROLE_ADMIN` or `ROLE_MEMBER` in the roles
- **THEN** the save is refused with a message
### Requirement: Admin-triggered password reset
The system SHALL let an admin with `BO_USERS` reset another user's password, which emails the user a temporary password and requires a change at next login. The system SHALL NOT let an admin set another user's password to a value the admin chooses.
#### Scenario: Reset
- **WHEN** an admin resets `sales1`'s password
- **THEN** `sales1`'s old password stops working
- **AND** a temporary password is emailed to `sales1`'s email address
#### Scenario: No direct password set
- **WHEN** an admin calls `POST /api/admin/users/{id}/changePassword`
- **THEN** the endpoint does not exist and no password changes
### Requirement: Company membership
Every admin user SHALL belong to exactly one company. The company SHALL be set by the system from the creating admin, never from the request.
#### Scenario: Company in the request is ignored
- **WHEN** a create-user request carries a company id different from the admin's own
- **THEN** the new user gets the admin's company