# Spec Delta ## Purpose Admins with the Users module manage staff accounts: who can log in, which roles they hold, and which company they belong to. ## ADDED 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. #### 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 ### 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. #### 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 ### 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