Merge pull request 'docs(openspec): archive add-company-scoping' (#26) from archive-add-company-scoping into main
CI / build-and-publish (push) Failing after 0s
CI / build-and-publish (push) Failing after 0s
This commit was merged in pull request #26.
This commit is contained in:
commit
7d29d89b3f
20 files changed
+213
-41
No files matched your search
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
@@ -8,20 +8,26 @@ Staff log in to the Co-Lite admin portal, and every admin page and `/api/admin/*
|
||||
|
||||
### 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.
|
||||
The system SHALL let an active admin user log in through the admin portal with company code, username and password, or with username and password and no company for a super admin, and SHALL return the user's name, roles, company, 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
|
||||
- **GIVEN** an active admin user `sales1` of active company `ins`
|
||||
- **WHEN** they submit company `ins`, username `sales1` and their password 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: Super admin
|
||||
|
||||
- **GIVEN** the super admin `admin`, who belongs to no company
|
||||
- **WHEN** they submit username `admin` and their password with the company left empty
|
||||
- **THEN** they are signed in
|
||||
|
||||
#### 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
|
||||
- **AND** the login page shows an invalid-credentials message without saying whether the company or username exists
|
||||
|
||||
#### Scenario: Deactivated user
|
||||
|
||||
@@ -53,19 +59,19 @@ The system SHALL require a user whose password is temporary (new user or reset)
|
||||
|
||||
### 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.
|
||||
The system SHALL let a user request a temporary password by entering their company code, username and email on a public forgot-password page; a super admin leaves the company empty. The response SHALL be the same whether or not the details 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`
|
||||
- **GIVEN** an active admin user `sales1` of company `ins` with email `sales1@example.com`
|
||||
- **WHEN** someone submits company `ins`, username `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
|
||||
- **WHEN** someone submits a company, 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
|
||||
|
||||
|
||||
@@ -89,16 +89,22 @@ The system SHALL refuse sign-in for a locked username before checking the passwo
|
||||
|
||||
### Requirement: Unlock
|
||||
|
||||
The system SHALL let an admin with `BO_LOGIN_SECURITY` list the usernames that are locked now, with their failure count, last failure time and when the lock ends, and SHALL let that admin unlock one. Unlocking SHALL save an `UNLOCK_RESET` record naming the admin who unlocked.
|
||||
The system SHALL let an admin with `BO_LOGIN_SECURITY` list the usernames of their own company that are locked now, with their failure count, last failure time and when the lock ends, and SHALL let that admin unlock one of them. A super admin SHALL see and unlock locked usernames of every company, including attempts that match no company. Unlocking SHALL save an `UNLOCK_RESET` record naming the admin who unlocked.
|
||||
|
||||
#### Scenario: Unlock a locked username
|
||||
|
||||
- **GIVEN** `sales1` is locked
|
||||
- **WHEN** an admin with `BO_LOGIN_SECURITY` unlocks `sales1`
|
||||
- **GIVEN** INS user `sales1` is locked
|
||||
- **WHEN** an INS admin with `BO_LOGIN_SECURITY` unlocks `sales1`
|
||||
- **THEN** `sales1` no longer appears in the locked list
|
||||
- **AND** `sales1` can sign in with the right password
|
||||
- **AND** an `UNLOCK_RESET` record for `sales1` names the admin
|
||||
|
||||
#### Scenario: Another company's locked user
|
||||
|
||||
- **GIVEN** CV user `sales2` is locked
|
||||
- **WHEN** an INS admin with `BO_LOGIN_SECURITY` lists locked users or unlocks `sales2` of CV
|
||||
- **THEN** `sales2` is not listed and the unlock answers 404
|
||||
|
||||
### Requirement: Login history screen
|
||||
|
||||
The system SHALL let an admin with `BO_LOGIN_SECURITY` read the login history, newest first and paged, filtered by username, event and date range.
|
||||
@@ -115,19 +121,24 @@ The system SHALL let an admin with `BO_LOGIN_SECURITY` read the login history, n
|
||||
|
||||
### Requirement: Lockout and password-rule settings
|
||||
|
||||
The system SHALL let an admin with `BO_LOGIN_SECURITY` read and change the lockout settings (on/off, maximum attempts, period, time unit) and the admin password rules (each rule's on/off status and value). The system SHALL reject a maximum below 1 or above 1000, a period below 1 or above 10000, and a time unit other than S, M, H or D. Password rules SHALL only be edited, never added or removed. Every change SHALL write a log line naming the admin.
|
||||
The system SHALL let an admin with `BO_LOGIN_SECURITY` read the lockout settings and the admin password rules, and SHALL let only a super admin change them, because they apply to every company. The system SHALL reject a maximum below 1 or above 1000, a period below 1 or above 10000, and a time unit other than S, M, H or D. Password rules SHALL only be edited, never added or removed. Every change SHALL write a log line naming the admin.
|
||||
|
||||
#### Scenario: Change the lockout settings
|
||||
|
||||
- **WHEN** an admin sets the maximum to 3 and the period to 30 minutes
|
||||
- **THEN** the next lock decision uses 3 attempts in 30 minutes
|
||||
- **WHEN** a super admin sets the maximum to 3 and the period to 30 minutes
|
||||
- **THEN** the next lock decision in every company uses 3 attempts in 30 minutes
|
||||
|
||||
#### Scenario: Invalid setting
|
||||
|
||||
- **WHEN** an admin sets the maximum to 0
|
||||
- **WHEN** a super admin sets the maximum to 0
|
||||
- **THEN** the change is refused with a validation error and the settings stay as they were
|
||||
|
||||
#### Scenario: Change a password rule
|
||||
|
||||
- **WHEN** an admin sets the minimum length rule to 10
|
||||
- **WHEN** a super admin sets the minimum length rule to 10
|
||||
- **THEN** a new password of 9 characters is refused by every admin password check
|
||||
|
||||
#### Scenario: Company user changes settings
|
||||
|
||||
- **WHEN** an INS user with `BO_LOGIN_SECURITY` changes a lockout setting or a password rule
|
||||
- **THEN** the change is refused with 403 and the settings stay as they were
|
||||
@@ -8,35 +8,40 @@ Admins with the Roles module define roles and choose which back-office modules e
|
||||
|
||||
### 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).
|
||||
The system SHALL let any admin with `BO_ROLES` list admin roles, and SHALL let only a super admin create and rename them, because roles are shared by every company. 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
|
||||
- **WHEN** a super admin creates role `ROLE_SALES`
|
||||
- **THEN** it appears in the role list and can be assigned to users of any company
|
||||
|
||||
#### Scenario: Duplicate name
|
||||
|
||||
- **GIVEN** role `ROLE_SALES` exists
|
||||
- **WHEN** an admin creates another role named `ROLE_SALES`
|
||||
- **WHEN** a super admin creates another role named `ROLE_SALES`
|
||||
- **THEN** the save is refused with a message
|
||||
|
||||
#### Scenario: Company user edits a role
|
||||
|
||||
- **WHEN** an INS user with `BO_ROLES` creates or renames a role
|
||||
- **THEN** the request is refused with 403 and nothing changes
|
||||
|
||||
### 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.
|
||||
The system SHALL let only a super admin 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. Admins with `BO_ROLES` who are not super admins SHALL see the grants read-only.
|
||||
|
||||
#### 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
|
||||
- **WHEN** a super admin grants `BO_USERS` to `ROLE_SALES` and saves
|
||||
- **THEN** users with `ROLE_SALES` in every company 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
|
||||
- **GIVEN** an INS user who is not super admin and holds `ROLE_SALES` and `BO_ROLES`
|
||||
- **WHEN** they change the module grants of `ROLE_SALES`, or of any other role
|
||||
- **THEN** the save is refused with 403 and the grants stay as they were
|
||||
|
||||
### Requirement: Back-office module set
|
||||
|
||||
|
||||
@@ -18,22 +18,27 @@ The system SHALL list admin users only (never members), paginated on the server,
|
||||
|
||||
### Requirement: Create user
|
||||
|
||||
The system SHALL let an admin with `BO_USERS` create an admin user with name, username, email, one or more roles, and an initial password with its confirmation. Username and email SHALL be unique. The password SHALL match its confirmation and pass the admin password rules. The new user SHALL be saved with a pending password change, SHALL belong to the creating admin's company, and SHALL NOT be sent an email.
|
||||
The system SHALL let an admin with `BO_USERS` create an admin user with name, username, email, one or more roles, and an initial password with its confirmation. Username and email SHALL be unique within the user's company, so the same username or email may exist in another company. A username SHALL NOT contain `@`. The password SHALL match its confirmation and pass the admin password rules. The new user SHALL be saved with a pending password change and SHALL NOT be sent an email.
|
||||
|
||||
#### Scenario: New user
|
||||
|
||||
- **WHEN** an admin creates user `sales1` with email `sales1@example.com`, role Sales and a valid initial password
|
||||
- **THEN** the user is saved as active with a pending password change
|
||||
- **AND** `sales1` can sign in with that password and must choose a new password before anything else
|
||||
- **WHEN** an INS admin creates user `sales1` with email `sales1@example.com`, role Sales and a valid initial password
|
||||
- **THEN** the user is saved as active in INS with a pending password change
|
||||
- **AND** `sales1` can sign in with company `ins` and that password and must choose a new password before anything else
|
||||
- **AND** no email is sent
|
||||
- **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`
|
||||
- **GIVEN** a user `sales1` exists in INS
|
||||
- **WHEN** an admin creates another INS user with username `sales1`
|
||||
- **THEN** the save is refused and the form shows that the username is taken
|
||||
|
||||
#### Scenario: Same username in another company
|
||||
|
||||
- **GIVEN** a user `sales1` exists in INS
|
||||
- **WHEN** a CV admin creates user `sales1` in CV
|
||||
- **THEN** the user is created
|
||||
|
||||
#### Scenario: Weak or mismatched initial password
|
||||
|
||||
- **WHEN** an admin creates a user with a password that fails the admin password rules, or that does not match its confirmation
|
||||
@@ -97,12 +102,17 @@ The system SHALL let an admin with `BO_USERS` give an active admin user a new pa
|
||||
|
||||
### 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.
|
||||
Every admin user other than a super admin SHALL belong to exactly one company. A company user's new user SHALL belong to the creating user's company, whatever the request says. A super admin SHALL choose the company of a new user, or no company to create another super admin.
|
||||
|
||||
#### 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
|
||||
- **WHEN** an INS user's create-user request carries the CV company id
|
||||
- **THEN** the new user belongs to INS
|
||||
|
||||
#### Scenario: Super admin chooses the company
|
||||
|
||||
- **WHEN** a super admin creates a user and chooses CV
|
||||
- **THEN** the new user belongs to CV
|
||||
|
||||
### Requirement: Temporary password refusals
|
||||
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
# company-scoping Specification
|
||||
|
||||
## Purpose
|
||||
|
||||
Separate the data of each company using Co-Lite (INS and CV at go-live): staff sign in with their company code and see only their own company's records, while company-less super admins manage companies and see every company.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement: Companies
|
||||
|
||||
The system SHALL let a super admin list, create and edit companies, each with a name, a unique code and an active or inactive status. A code SHALL be 2 to 20 characters of lowercase letters, digits and hyphens, compared ignoring case. Companies SHALL NOT be deletable. The Companies screen and its endpoints SHALL be available to super admins only.
|
||||
|
||||
#### Scenario: Create a company
|
||||
|
||||
- **WHEN** a super admin creates company `CV` with code `cv`
|
||||
- **THEN** it is listed as active
|
||||
- **AND** staff can be created in it
|
||||
|
||||
#### Scenario: Duplicate code
|
||||
|
||||
- **GIVEN** a company with code `ins`
|
||||
- **WHEN** a super admin creates or renames another company to code `INS`
|
||||
- **THEN** the save is refused and the code is reported as taken
|
||||
|
||||
#### Scenario: Not a super admin
|
||||
|
||||
- **WHEN** company staff open the Companies page or call a companies endpoint
|
||||
- **THEN** the page shows not-authorised and the endpoint responds 403
|
||||
|
||||
### Requirement: Company sign-in
|
||||
|
||||
The system SHALL sign company staff in with company code, username and password, and SHALL sign super admins in with username and password and no company. The answer SHALL be the same for a wrong or unknown company, an inactive company, an unknown user and a wrong password. A user's sessions SHALL end when their company is deactivated or its code is changed.
|
||||
|
||||
#### Scenario: Staff sign-in
|
||||
|
||||
- **GIVEN** an active user `john` in active company `ins`
|
||||
- **WHEN** they sign in with company `ins`, username `john` and the right password
|
||||
- **THEN** they are signed in as `john` of INS
|
||||
|
||||
#### Scenario: Same username in two companies
|
||||
|
||||
- **GIVEN** a user `john` in INS and a different user `john` in CV
|
||||
- **WHEN** someone signs in with company `cv`, username `john` and CV John's password
|
||||
- **THEN** they are signed in as CV's John and see only CV data
|
||||
|
||||
#### Scenario: Wrong company
|
||||
|
||||
- **WHEN** INS's `john` signs in with company `cv` or a code that does not exist
|
||||
- **THEN** login is refused with the same invalid-credentials answer as a wrong password
|
||||
|
||||
#### Scenario: Inactive company
|
||||
|
||||
- **GIVEN** company CV is deactivated
|
||||
- **WHEN** a CV user signs in with the right password, or uses an existing session
|
||||
- **THEN** the sign-in is refused with the invalid-credentials answer and the session ends
|
||||
|
||||
#### Scenario: Code changed
|
||||
|
||||
- **GIVEN** a signed-in user of the company with code `ins`
|
||||
- **WHEN** a super admin changes that code to `ins-my`
|
||||
- **THEN** the user's session ends
|
||||
- **AND** they sign in again with company `ins-my`
|
||||
|
||||
### Requirement: Super admins
|
||||
|
||||
A super admin SHALL be an admin user who belongs to no company and holds the super admin role. Only a super admin SHALL create another super admin. The super admin role SHALL NOT be granted to a user who belongs to a company, and every admin user who is not a super admin SHALL belong to a company.
|
||||
|
||||
#### Scenario: Create a second super admin
|
||||
|
||||
- **WHEN** a super admin creates a user with no company
|
||||
- **THEN** the user is created as a super admin and signs in without a company
|
||||
|
||||
#### Scenario: Super admin role for company staff
|
||||
|
||||
- **WHEN** anyone assigns the super admin role to a user of INS
|
||||
- **THEN** the save is refused with a message
|
||||
|
||||
### Requirement: Company data is separated
|
||||
|
||||
The system SHALL limit every admin list, search, export, detail, create, edit and action to the caller's company for: users, events, event teams, event leads, leads, emails, login history, locked users and audit events. A record of another company SHALL answer 404, as if it did not exist.
|
||||
|
||||
#### Scenario: Lists show own company only
|
||||
|
||||
- **GIVEN** leads, events and users in INS and in CV
|
||||
- **WHEN** an INS user with the matching modules opens Leads, Events or Users
|
||||
- **THEN** only INS records are listed
|
||||
- **AND** an export contains only INS leads
|
||||
|
||||
#### Scenario: Another company's record by id
|
||||
|
||||
- **GIVEN** a CV lead, event, user or email
|
||||
- **WHEN** an INS user requests it, edits it or acts on it by its id
|
||||
- **THEN** the answer is 404 and nothing changes
|
||||
|
||||
#### Scenario: Same phone in two companies
|
||||
|
||||
- **GIVEN** INS has a lead with mobile `+60123456789`
|
||||
- **WHEN** a CV user captures a lead with the same mobile at a CV event
|
||||
- **THEN** a new CV lead is created and flagged New
|
||||
- **AND** the INS lead is unchanged
|
||||
|
||||
### Requirement: Super admin sees all companies
|
||||
|
||||
The system SHALL show super admins every company's records by default, SHALL let them narrow any scoped list to one company, and SHALL show each record's company in mixed lists. Creating a company-owned record (user, event, event lead) SHALL require a super admin to choose the company.
|
||||
|
||||
#### Scenario: Mixed list
|
||||
|
||||
- **WHEN** a super admin opens Leads with all companies selected
|
||||
- **THEN** INS and CV leads are listed together with a Company column
|
||||
|
||||
#### Scenario: Pick a company
|
||||
|
||||
- **WHEN** a super admin picks CV in the company picker
|
||||
- **THEN** scoped lists show CV records only
|
||||
|
||||
#### Scenario: Create without a company
|
||||
|
||||
- **WHEN** a super admin creates an event without choosing a company
|
||||
- **THEN** the save is refused and the form asks for a company
|
||||
|
||||
### Requirement: Company of login and audit records
|
||||
|
||||
An audit event and a login-history record SHALL belong to the company of the user who acted, or of the user who tried to sign in when the given company and username match a user. Records with no company SHALL be visible to super admins only.
|
||||
|
||||
#### Scenario: Super admin edits a company record
|
||||
|
||||
- **WHEN** a super admin edits an INS lead
|
||||
- **THEN** the audit event has no company
|
||||
- **AND** INS staff with Audit log do not see it, and super admins do
|
||||
|
||||
#### Scenario: Failed sign-in with an unknown company
|
||||
|
||||
- **WHEN** someone fails to sign in with a company code that does not exist
|
||||
- **THEN** the login-history record has no company and only super admins see it
|
||||
@@ -8,25 +8,31 @@ Admins with the Interests module maintain the list of products and services that
|
||||
|
||||
### Requirement: Interest list
|
||||
|
||||
The system SHALL let an admin with `BO_INTERESTS` list, add, rename, reorder, deactivate and reactivate interests for their company. An interest name SHALL be required, at most 100 characters, and unique within the company ignoring case. Interests SHALL NOT be deletable.
|
||||
The system SHALL keep one interest list shared by all companies. Admins with `BO_INTERESTS` SHALL see the list, and only a super admin SHALL add, rename, reorder, deactivate and reactivate interests. An interest name SHALL be required, at most 100 characters, and unique ignoring case. Interests SHALL NOT be deletable.
|
||||
|
||||
#### Scenario: Add interest
|
||||
|
||||
- **WHEN** an admin with `BO_INTERESTS` adds `Kitchen appliances`
|
||||
- **WHEN** a super admin adds `Kitchen appliances`
|
||||
- **THEN** it is listed as active
|
||||
- **AND** staff of every company can tag leads with it
|
||||
|
||||
#### Scenario: Duplicate name
|
||||
|
||||
- **GIVEN** an interest `Kitchen appliances`
|
||||
- **WHEN** an admin adds `kitchen APPLIANCES`
|
||||
- **WHEN** a super admin adds `kitchen APPLIANCES`
|
||||
- **THEN** the save is refused and the name is reported as a duplicate
|
||||
|
||||
#### Scenario: Deactivate
|
||||
|
||||
- **GIVEN** an active interest `Cookware`
|
||||
- **WHEN** an admin deactivates it
|
||||
- **WHEN** a super admin deactivates it
|
||||
- **THEN** it is still listed, marked inactive
|
||||
- **AND** it is no longer offered when capturing a lead
|
||||
- **AND** it is no longer offered when capturing a lead in any company
|
||||
|
||||
#### Scenario: Company user edits
|
||||
|
||||
- **WHEN** an INS user with `BO_INTERESTS` adds, renames or deactivates an interest
|
||||
- **THEN** the request is refused with 403 and the list is unchanged
|
||||
|
||||
#### Scenario: No module
|
||||
|
||||
|
||||
Reference in new issue
Block a user