From ff4b12c2e99c131029d538e6e5283fc480377a79 Mon Sep 17 00:00:00 2001 From: ngqile Date: Tue, 1 Dec 2026 16:07:34 +0800 Subject: [PATCH] docs(openspec): propose uppercase-company-codes Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM --- .../uppercase-company-codes/.openspec.yaml | 2 ++ .../uppercase-company-codes/proposal.md | 27 +++++++++++++++ .../specs/company-scoping/spec.md | 30 +++++++++++++++++ .../sql/01-uppercase-codes.sql | 9 +++++ .../sql/99-rollback.sql | 8 +++++ .../changes/uppercase-company-codes/tasks.md | 33 +++++++++++++++++++ 6 files changed, 109 insertions(+) create mode 100644 openspec/changes/uppercase-company-codes/.openspec.yaml create mode 100644 openspec/changes/uppercase-company-codes/proposal.md create mode 100644 openspec/changes/uppercase-company-codes/specs/company-scoping/spec.md create mode 100644 openspec/changes/uppercase-company-codes/sql/01-uppercase-codes.sql create mode 100644 openspec/changes/uppercase-company-codes/sql/99-rollback.sql create mode 100644 openspec/changes/uppercase-company-codes/tasks.md diff --git a/openspec/changes/uppercase-company-codes/.openspec.yaml b/openspec/changes/uppercase-company-codes/.openspec.yaml new file mode 100644 index 0000000..785b150 --- /dev/null +++ b/openspec/changes/uppercase-company-codes/.openspec.yaml @@ -0,0 +1,2 @@ +schema: spec-driven +created: 2026-12-01 diff --git a/openspec/changes/uppercase-company-codes/proposal.md b/openspec/changes/uppercase-company-codes/proposal.md new file mode 100644 index 0000000..1b3a3a1 --- /dev/null +++ b/openspec/changes/uppercase-company-codes/proposal.md @@ -0,0 +1,27 @@ +## Why + +Company codes are stored and shown in lowercase (`ins`, `cv`). The owner wants them in capitals (`INS`, `CV`), and the Companies screen cannot change `cv` to `CV`: the portal treats a case-only change as no change, and services-system lowercases every code it saves. + +## What Changes + +- Company codes are stored and shown in capitals: 2 to 20 characters of `A-Z`, `0-9` and `-`. Any code entered is turned to capitals before it is checked and saved. +- Sign-in keeps ignoring case: staff can type `cv`, `Cv` or `CV`. +- Staff login names follow the code (`sales9@CV`). +- A one-off SQL turns the existing codes and staff login names to capitals. + +## Capabilities + +### New Capabilities + +None. + +### Modified Capabilities + +- `company-scoping`: the code format of the Companies requirement becomes capitals. + +## Impact + +- **services-system:** `CompanyService` code validation and normalisation. +- **mobile-api:** the admin login builds the login name with the code in capitals. +- **portal:** the Companies code fields show and send capitals. A case-only rename is no longer treated as no change. +- **Data:** `sql/01-uppercase-codes.sql` on `service-system`. Signed-in staff must sign in again after it runs, as after any code change. diff --git a/openspec/changes/uppercase-company-codes/specs/company-scoping/spec.md b/openspec/changes/uppercase-company-codes/specs/company-scoping/spec.md new file mode 100644 index 0000000..569ff9b --- /dev/null +++ b/openspec/changes/uppercase-company-codes/specs/company-scoping/spec.md @@ -0,0 +1,30 @@ +# Spec Delta + +## MODIFIED 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 capital letters, digits and hyphens. A code entered in any case SHALL be stored in capitals, and codes SHALL be 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 with code `CV` +- **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 + +#### Scenario: Sign-in ignores case + +- **GIVEN** company code `CV` and its user `sales9` +- **WHEN** they sign in with company `cv` +- **THEN** they are signed in as `sales9` of CV diff --git a/openspec/changes/uppercase-company-codes/sql/01-uppercase-codes.sql b/openspec/changes/uppercase-company-codes/sql/01-uppercase-codes.sql new file mode 100644 index 0000000..93f157a --- /dev/null +++ b/openspec/changes/uppercase-company-codes/sql/01-uppercase-codes.sql @@ -0,0 +1,9 @@ +-- Co-Lite change uppercase-company-codes: company codes and staff login names in capitals. +-- Target: `service-system`. Signed-in staff must sign in again afterwards. Idempotent. +USE `service-system`; + +UPDATE `user` u JOIN `company` c ON c.`id` = u.`company_id` +SET u.`username` = CONCAT(SUBSTRING(u.`username`, 1, CHAR_LENGTH(u.`username`) - CHAR_LENGTH(c.`code`) - 1), '@', UPPER(c.`code`)) +WHERE u.`type` = 'A' AND u.`username` LIKE CONCAT('%@', c.`code`) AND BINARY u.`username` <> BINARY CONCAT(SUBSTRING(u.`username`, 1, CHAR_LENGTH(u.`username`) - CHAR_LENGTH(c.`code`) - 1), '@', UPPER(c.`code`)); + +UPDATE `company` SET `code` = UPPER(`code`) WHERE BINARY `code` <> BINARY UPPER(`code`); diff --git a/openspec/changes/uppercase-company-codes/sql/99-rollback.sql b/openspec/changes/uppercase-company-codes/sql/99-rollback.sql new file mode 100644 index 0000000..83ebc0f --- /dev/null +++ b/openspec/changes/uppercase-company-codes/sql/99-rollback.sql @@ -0,0 +1,8 @@ +-- Co-Lite change uppercase-company-codes: rollback to lowercase codes and login names. +USE `service-system`; + +UPDATE `user` u JOIN `company` c ON c.`id` = u.`company_id` +SET u.`username` = CONCAT(SUBSTRING(u.`username`, 1, CHAR_LENGTH(u.`username`) - CHAR_LENGTH(c.`code`) - 1), '@', LOWER(c.`code`)) +WHERE u.`type` = 'A' AND u.`username` LIKE CONCAT('%@', c.`code`); + +UPDATE `company` SET `code` = LOWER(`code`); diff --git a/openspec/changes/uppercase-company-codes/tasks.md b/openspec/changes/uppercase-company-codes/tasks.md new file mode 100644 index 0000000..180f403 --- /dev/null +++ b/openspec/changes/uppercase-company-codes/tasks.md @@ -0,0 +1,33 @@ +# Tasks + +Serial. One implementer, in this session. + +## 1. Data + +- [ ] 1.1 `sql/01-uppercase-codes.sql` and `sql/99-rollback.sql`; change the codes in `local/seed/03-colite.sql` to `INS` and `CV` (the `@ins` login names it builds follow); apply 01 to the local database. + - Depends on: none + - Scope: `local/seed/**`, `openspec/changes/uppercase-company-codes/sql/**` + - Verify: `SELECT code FROM company` gives `INS`, `CV`; staff login names end in `@INS` or `@CV`. + +## 2. Backend + +- [ ] 2.1 services-system `CompanyService` stores codes in capitals (`^[A-Z0-9-]{2,20}$`, entered value trimmed and turned to capitals); mobile-api admin login and forgot-password build the login name with the code in capitals. + - Depends on: 1.1 + - Tests first: create with `cv` stores `CV`; rename `cv` to `CV` on a company whose code is `cv` succeeds; `ins` is taken when `INS` exists; an invalid code is refused; login with company `cv` looks up `user@CV`. + - Scope: `solvway-services-system/src/**`, `solvway-mobile-api/src/**` + - Verify: `mvn -T 1C -q -pl solvway-services-system,solvway-mobile-api verify` + +## 3. Portal + +- [ ] 3.1 Companies: code inputs show capitals as typed and the rename compares case-sensitively, so `cv` to `CV` is a change. + - Depends on: 2.1 + - Tests first: typing `cv` shows `CV`; renaming `cv` to `CV` sends the request. + - Scope: `solvway-admin-portal/app/**` + - Verify: `cd solvway-admin-portal && npm run lint; echo L=$?; npx tsc --noEmit; echo T=$?; npx vitest run; echo V=$?` + +## 4. Release + +- [ ] 4.1 `docs/deployment.md` notes the SQL and that staff sign in again; Playwright: Companies shows `INS` and `CV`, sign in as `sales9` with company `cv` works. + - Depends on: 3.1 + - Scope: `docs/deployment.md`, `openspec/changes/uppercase-company-codes/tasks.md` + - Verify: the 2.1 and 3.1 verifies.