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
No files matched your search
|
Before Width: | Height: | Size: 105 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 47 KiB |
|
Before Width: | Height: | Size: 49 KiB After Width: | Height: | Size: 49 KiB |
|
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 38 KiB After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 58 KiB After Width: | Height: | Size: 58 KiB |
|
Before Width: | Height: | Size: 50 KiB After Width: | Height: | Size: 50 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
|
Before Width: | Height: | Size: 99 KiB After Width: | Height: | Size: 99 KiB |
|
Before Width: | Height: | Size: 29 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 98 KiB |
|
Before Width: | Height: | Size: 56 KiB After Width: | Height: | Size: 56 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 33 KiB After Width: | Height: | Size: 33 KiB |
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||