From 4acfaff8e5e7f70a0d1ef07749de772e3885bd6e Mon Sep 17 00:00:00 2001 From: ngqile Date: Thu, 26 Nov 2026 22:40:58 +0800 Subject: [PATCH] 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 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../.openspec.yaml | 0 .../design.md | 0 .../proposal.md | 0 .../specs/admin-access/spec.md | 0 .../specs/admin-roles/spec.md | 0 .../specs/admin-users/spec.md | 0 .../sql/01-company.sql | 0 .../sql/02-bo-modules.sql | 0 .../sql/99-rollback.sql | 0 .../tasks.md | 0 .../verification/01-login-wrong-password.png | Bin .../verification/02-users-list.png | Bin .../verification/03-role-create.png | Bin .../verification/04-role-duplicate.png | Bin .../verification/05-role-grant-users.png | Bin .../verification/06-user-created.png | Bin .../verification/07-own-account-locked.png | Bin .../verification/08-first-login-weak.png | Bin .../verification/09-sales-home.png | Bin .../verification/10-not-authorised.png | Bin .../11-deactivated-signed-out.png | Bin .../verification/12-forgot-password.png | Bin .../verification/13-login-copy.png | Bin .../verification/14-role-duplicate.png | Bin .../verification/15-user-created-banner.png | Bin .../verification/16-reset-password-hint.png | Bin openspec/specs/admin-access/spec.md | 121 ++++++++++++++++++ openspec/specs/admin-roles/spec.md | 48 +++++++ openspec/specs/admin-users/spec.md | 85 ++++++++++++ 29 files changed, 254 insertions(+) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/.openspec.yaml (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/design.md (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/proposal.md (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/specs/admin-access/spec.md (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/specs/admin-roles/spec.md (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/specs/admin-users/spec.md (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/sql/01-company.sql (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/sql/02-bo-modules.sql (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/sql/99-rollback.sql (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/tasks.md (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/01-login-wrong-password.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/02-users-list.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/03-role-create.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/04-role-duplicate.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/05-role-grant-users.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/06-user-created.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/07-own-account-locked.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/08-first-login-weak.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/09-sales-home.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/10-not-authorised.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/11-deactivated-signed-out.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/12-forgot-password.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/13-login-copy.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/14-role-duplicate.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/15-user-created-banner.png (100%) rename openspec/changes/{add-admin-auth-users-roles => archive/2026-11-26-add-admin-auth-users-roles}/verification/16-reset-password-hint.png (100%) create mode 100644 openspec/specs/admin-access/spec.md create mode 100644 openspec/specs/admin-roles/spec.md create mode 100644 openspec/specs/admin-users/spec.md diff --git a/openspec/changes/add-admin-auth-users-roles/.openspec.yaml b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/.openspec.yaml similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/.openspec.yaml rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/.openspec.yaml diff --git a/openspec/changes/add-admin-auth-users-roles/design.md b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/design.md similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/design.md rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/design.md diff --git a/openspec/changes/add-admin-auth-users-roles/proposal.md b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/proposal.md similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/proposal.md rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/proposal.md diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-access/spec.md b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/specs/admin-access/spec.md similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/specs/admin-access/spec.md rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/specs/admin-access/spec.md diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/specs/admin-roles/spec.md similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/specs/admin-roles/spec.md rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/specs/admin-roles/spec.md diff --git a/openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/specs/admin-users/spec.md similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/specs/admin-users/spec.md rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/specs/admin-users/spec.md diff --git a/openspec/changes/add-admin-auth-users-roles/sql/01-company.sql b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/sql/01-company.sql similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/sql/01-company.sql rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/sql/01-company.sql diff --git a/openspec/changes/add-admin-auth-users-roles/sql/02-bo-modules.sql b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/sql/02-bo-modules.sql similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/sql/02-bo-modules.sql rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/sql/02-bo-modules.sql diff --git a/openspec/changes/add-admin-auth-users-roles/sql/99-rollback.sql b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/sql/99-rollback.sql similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/sql/99-rollback.sql rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/sql/99-rollback.sql diff --git a/openspec/changes/add-admin-auth-users-roles/tasks.md b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/tasks.md similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/tasks.md rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/tasks.md diff --git a/openspec/changes/add-admin-auth-users-roles/verification/01-login-wrong-password.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/01-login-wrong-password.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/01-login-wrong-password.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/01-login-wrong-password.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/02-users-list.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/02-users-list.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/02-users-list.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/02-users-list.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/03-role-create.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/03-role-create.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/03-role-create.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/03-role-create.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/04-role-duplicate.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/04-role-duplicate.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/04-role-duplicate.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/04-role-duplicate.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/05-role-grant-users.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/05-role-grant-users.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/05-role-grant-users.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/05-role-grant-users.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/06-user-created.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/06-user-created.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/06-user-created.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/06-user-created.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/07-own-account-locked.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/07-own-account-locked.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/07-own-account-locked.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/07-own-account-locked.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/08-first-login-weak.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/08-first-login-weak.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/08-first-login-weak.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/08-first-login-weak.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/09-sales-home.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/09-sales-home.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/09-sales-home.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/09-sales-home.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/10-not-authorised.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/10-not-authorised.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/10-not-authorised.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/10-not-authorised.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/11-deactivated-signed-out.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/11-deactivated-signed-out.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/11-deactivated-signed-out.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/11-deactivated-signed-out.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/12-forgot-password.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/12-forgot-password.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/12-forgot-password.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/12-forgot-password.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/13-login-copy.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/13-login-copy.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/13-login-copy.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/13-login-copy.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/14-role-duplicate.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/14-role-duplicate.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/14-role-duplicate.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/14-role-duplicate.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/15-user-created-banner.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/15-user-created-banner.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/15-user-created-banner.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/15-user-created-banner.png diff --git a/openspec/changes/add-admin-auth-users-roles/verification/16-reset-password-hint.png b/openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/16-reset-password-hint.png similarity index 100% rename from openspec/changes/add-admin-auth-users-roles/verification/16-reset-password-hint.png rename to openspec/changes/archive/2026-11-26-add-admin-auth-users-roles/verification/16-reset-password-hint.png diff --git a/openspec/specs/admin-access/spec.md b/openspec/specs/admin-access/spec.md new file mode 100644 index 0000000..8ef39c2 --- /dev/null +++ b/openspec/specs/admin-access/spec.md @@ -0,0 +1,121 @@ +# admin-access Specification + +## Purpose + +Staff log in to the Co-Lite admin portal, and every admin page and `/api/admin/**` endpoint admits only active staff holding the module it needs. + +## Requirements + +### Requirement: Staff login + +The system SHALL let an active admin user log in with username and password through the admin portal, and SHALL return the user's name, roles, menu and whether a password change is required. + +#### Scenario: Correct credentials + +- **GIVEN** an active admin user `admin` with password `colite-dev-admin` +- **WHEN** they submit those credentials on the login page +- **THEN** they are signed in and land on the portal home +- **AND** the sidebar shows only the menu entries their roles grant + +#### Scenario: Wrong password + +- **WHEN** a user submits a wrong password +- **THEN** `/api/admin/auth/login` responds 401 +- **AND** the login page shows an invalid-credentials message without saying whether the username exists + +#### Scenario: Deactivated user + +- **GIVEN** an admin user whose account is deactivated +- **WHEN** they submit their correct password +- **THEN** login is refused with a 401 and the page shows the same invalid-credentials message + +#### Scenario: Member account + +- **WHEN** a member (non-admin) account submits its correct credentials to the admin login +- **THEN** login is refused with a 401 + +### Requirement: First-login password change + +The system SHALL require a user whose password is temporary (new user or reset) to set a new password before using any other admin page or endpoint. + +#### Scenario: Pending change confines the session + +- **GIVEN** a user logged in with a temporary password +- **WHEN** they open any portal page other than the password-change page +- **THEN** they are sent to the password-change page +- **AND** any `/api/admin/**` call other than first-login and logout responds 403 + +#### Scenario: Password changed + +- **GIVEN** a user on the password-change page +- **WHEN** they submit a new password that meets the password rules +- **THEN** the password is saved, the temporary flag clears, and they can use the portal + +### Requirement: Forgot password + +The system SHALL let a user request a temporary password by entering their username and email on a public forgot-password page. The response SHALL be the same whether or not the username and email match an active admin user. + +#### Scenario: Matching username and email + +- **GIVEN** an active admin user with username `sales1` and email `sales1@example.com` +- **WHEN** someone submits `sales1` and `sales1@example.com` +- **THEN** a temporary password is emailed to `sales1@example.com` +- **AND** the user must change it at next login +- **AND** the page shows "If the details match an account, we have emailed a temporary password." + +#### Scenario: Non-matching details + +- **WHEN** someone submits a username and email that do not match an active admin user +- **THEN** no password changes and no email is sent +- **AND** the page shows the same message as for a match + +### Requirement: Logout + +The system SHALL end the session on logout, and SHALL reject the logged-out token on every later `/api/admin/**` call even before it expires. + +#### Scenario: Token used after logout + +- **GIVEN** a user who logged out +- **WHEN** a request reuses their old token on `/api/admin/me` +- **THEN** it responds 401 + +### Requirement: Admin endpoint guard + +Every `/api/admin/**` endpoint except login and forgot password SHALL require a valid admin token, and SHALL require at least one of the back-office modules the endpoint declares, granted to one of the caller's roles. A user with the super admin role SHALL pass every module check. An endpoint that declares no module SHALL be denied to everyone except super admin. + +#### Scenario: No token + +- **WHEN** `/api/admin/users` is called without a token +- **THEN** it responds 401 + +#### Scenario: Member token on an admin path + +- **WHEN** a valid member token calls `/api/admin/me` +- **THEN** it responds 403 + +#### Scenario: Missing module + +- **GIVEN** an admin user whose roles do not grant `BO_USERS` +- **WHEN** they call `GET /api/admin/users` +- **THEN** it responds 403 + +#### Scenario: Granted module + +- **GIVEN** an admin user whose role grants `BO_USERS` +- **WHEN** they call `GET /api/admin/users` +- **THEN** it responds 200 + +### Requirement: Page guard + +The admin portal SHALL show a not-authorised page when a signed-in user opens a page whose module their roles do not grant, and SHALL send a signed-out visitor to the login page for every page except login and forgot password. + +#### Scenario: Signed-out visitor + +- **WHEN** a signed-out visitor opens `/users` +- **THEN** they are sent to the login page and return to `/users` after logging in + +#### Scenario: Page without the module + +- **GIVEN** a signed-in user without `BO_ROLES` +- **WHEN** they open `/roles` +- **THEN** the not-authorised page is shown and no role data is loaded diff --git a/openspec/specs/admin-roles/spec.md b/openspec/specs/admin-roles/spec.md new file mode 100644 index 0000000..f0429d0 --- /dev/null +++ b/openspec/specs/admin-roles/spec.md @@ -0,0 +1,48 @@ +# admin-roles Specification + +## Purpose + +Admins with the Roles module define roles and choose which back-office modules each role grants, which controls the menus and endpoints its users reach. + +## Requirements + +### Requirement: Role list and edit + +The system SHALL let an admin with `BO_ROLES` list, create and rename admin roles. Role names SHALL be unique. The member role and `ROLE_ADMIN` SHALL NOT appear in the list (`ROLE_ADMIN` is attached to every admin automatically and grants no modules). + +#### Scenario: Create role + +- **WHEN** an admin with `BO_ROLES` creates role `ROLE_SALES` +- **THEN** it appears in the role list and can be assigned to users + +#### Scenario: Duplicate name + +- **GIVEN** role `ROLE_SALES` exists +- **WHEN** an admin creates another role named `ROLE_SALES` +- **THEN** the save is refused with a message + +### Requirement: Role permissions + +The system SHALL let an admin with `BO_ROLES` choose, for a role, which back-office modules it grants, shown as the module tree. Saving SHALL replace the role's module grants with the chosen set. The grants of the super admin role and of `ROLE_ADMIN` SHALL NOT be editable. An admin who is not super admin SHALL NOT change the grants of a role they hold. + +#### Scenario: Grant Users module + +- **GIVEN** role `ROLE_SALES` without `BO_USERS` +- **WHEN** an admin grants `BO_USERS` to `ROLE_SALES` and saves +- **THEN** users with `ROLE_SALES` see Users in the sidebar after their next login or session refresh +- **AND** `GET /api/admin/users` responds 200 for them + +#### Scenario: Own role + +- **GIVEN** an admin who is not super admin and holds `ROLE_SALES` +- **WHEN** they change the module grants of `ROLE_SALES` and save +- **THEN** the save is refused with a message, so no admin can widen their own access or lock themselves out of role management + +### Requirement: Back-office module set + +The system SHALL hold Co-Lite's back-office modules in the module table, with a root entry and one entry per admin screen. This change SHALL add `BO_USERS` (Users) and `BO_ROLES` (Roles). Later changes add their own modules. + +#### Scenario: Seeded modules + +- **WHEN** the local stack starts from an empty database +- **THEN** the super admin's sidebar shows Users and Roles and no Tastefully back-office entries diff --git a/openspec/specs/admin-users/spec.md b/openspec/specs/admin-users/spec.md new file mode 100644 index 0000000..113d062 --- /dev/null +++ b/openspec/specs/admin-users/spec.md @@ -0,0 +1,85 @@ +# 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