feat(api): M8 7.14 — classification ladder + groups entity (CLS-02/03 + §12 amendments) #200

Merged
amiryahaya merged 3 commits from feat/m8-714-groups-clearance into main 2026-11-14 03:47:15 +01:00
Owner

First code of M8 — Groups & Classification Lattice (#158), under the amended §3.18 (PR #199's STRIDE amendments, adopted by silence).

Scope (7.14 server slice)

  • Per-tenant ladder classification_levels — name+rank unique per tenant, platform-provisioned at flag-enable (§12 CLS-T1 binding: no tenant edit surface; one-way enable, no disable endpoint)
  • tenants.ClassificationEnabled (CLS-01) — default off = byte-identical behavior
  • user_tenants.ClearanceLevelId (CLS-02) — per-tenant personal clearance, backfilled to Internal on enable
  • groups + group_memberships (CLS-03) — floor FK (Restrict), unique (tenant,name) + (group,user)
  • Admin surface (F-CLS4, SuperAdmin-gated, AuthzMatrix rows added): enable, ladder GET, clearance PUT with no-self-change (§12 CLS-E2), groups CRUD, member add/remove/list with the floor rule, floor-raise auto-removal (§12 CLS-E3) and floor-lowering refusal
  • Auto-removal engine: both directions audited (group_membership_auto_removed) + in-app notification; GET /members now carries clearance

Deliberate scope call

Share-to-group targeting moves to 7.15 — it is intrinsically tied to the lattice filter + per-principal access-time resolution (encrypted-key distribution mechanics) and has no flag-off behavior; landing the Share schema changes without consumers adds risk for zero behavior. Noted on epic #158.

TDD notes (3 EF gotchas hit and encoded as comments)

  1. ExecuteUpdateAsync backfill must run after SaveChanges — the FK target (Internal row) must exist in the DB
  2. DB-side rank queries must run after the triggering mutation is saved (context ≠ DB — hit in both enable and floor-raise paths)
  3. Floor-raise violation is a member-side rank check (clearance < newFloorRank); clearance-downgrade is a group-side check (floorRank > newClearance) — the two directions have different predicate homes

Verification

  • 11 new ClassificationGroupsTests (ladder + backfill, 409s, no-self-change, floor rule both directions with audit + notification assertions)
  • Full suite locally: 1049 total, 0 failed, 39 skipped (known set)
  • Flag-off zero-delta: every classification endpoint 409s; no existing behavior touched except GET /members gaining an additive clearance field

Closes the 7.14 server portion of #158 (admin-portal UI = next slice; share-target = 7.15).

First code of **M8 — Groups & Classification Lattice (#158)**, under the amended §3.18 (PR #199's STRIDE amendments, adopted by silence). ## Scope (7.14 server slice) - **Per-tenant ladder** `classification_levels` — name+rank unique per tenant, **platform-provisioned at flag-enable** (§12 CLS-T1 binding: no tenant edit surface; one-way enable, no disable endpoint) - **`tenants.ClassificationEnabled`** (CLS-01) — default off = byte-identical behavior - **`user_tenants.ClearanceLevelId`** (CLS-02) — per-tenant personal clearance, backfilled to Internal on enable - **`groups` + `group_memberships`** (CLS-03) — floor FK (Restrict), unique (tenant,name) + (group,user) - **Admin surface** (F-CLS4, SuperAdmin-gated, AuthzMatrix rows added): enable, ladder GET, clearance PUT with **no-self-change** (§12 CLS-E2), groups CRUD, member add/remove/list with the floor rule, **floor-raise auto-removal** (§12 CLS-E3) and floor-lowering refusal - **Auto-removal engine**: both directions audited (`group_membership_auto_removed`) + in-app notification; `GET /members` now carries clearance ## Deliberate scope call **Share-to-group targeting moves to 7.15** — it is intrinsically tied to the lattice filter + per-principal access-time resolution (encrypted-key distribution mechanics) and has no flag-off behavior; landing the Share schema changes without consumers adds risk for zero behavior. Noted on epic #158. ## TDD notes (3 EF gotchas hit and encoded as comments) 1. `ExecuteUpdateAsync` backfill must run **after** SaveChanges — the FK target (Internal row) must exist in the DB 2. DB-side rank queries must run **after** the triggering mutation is saved (context ≠ DB — hit in both enable and floor-raise paths) 3. Floor-raise violation is a **member-side** rank check (`clearance < newFloorRank`); clearance-downgrade is a group-side check (`floorRank > newClearance`) — the two directions have different predicate homes ## Verification - 11 new `ClassificationGroupsTests` (ladder + backfill, 409s, no-self-change, floor rule both directions with audit + notification assertions) - Full suite locally: **1049 total, 0 failed, 39 skipped** (known set) - Flag-off zero-delta: every classification endpoint 409s; no existing behavior touched except `GET /members` gaining an additive `clearance` field Closes the 7.14 server portion of #158 (admin-portal UI = next slice; share-target = 7.15).
feat(api): M8 7.14 — classification ladder + groups entity (CLS-02/03 + §12 amendments)
All checks were successful
Security CI / security-scan (pull_request) Successful in 3m14s
API CI / build-and-test (pull_request) Successful in 6m3s
b5901082e3
Schema:
- classification_levels: per-tenant ordered ladder, name+rank unique per
  tenant, platform-provisioned at flag-enable (§12 CLS-T1 — no tenant
  edit surface)
- tenants.ClassificationEnabled (CLS-01, default off = zero delta)
- user_tenants.ClearanceLevelId (CLS-02: per-tenant personal clearance,
  NULL until enable + backfill to Internal)
- groups + group_memberships (CLS-03): floor FK with Restrict, unique
  (tenant,name) and (group,user); membership cascade on group/user

Admin surface (F-CLS4, SuperAdmin-gated; AuthzMatrix rows added):
- POST /tenants/{id}/classification/enable — provisions the 4-row ladder
  + backfills members to Internal; one-way (no disable endpoint, §12)
- GET /tenants/{id}/classification — flag + ladder
- PUT /tenants/{id}/members/{uid}/clearance — CLS-E2 no-self-change
  (setter != target), assigned-vs-changed audit, downgrade auto-removal
- groups CRUD + member add/remove/list — floor rule at add-time
  (classification_insufficient 400), floor raise auto-removal
  (§12 CLS-E3, member-side rank check), floor lowering refused
- GET /tenants/{id}/members now carries clearance (F-CLS4 column)

Auto-removal engine (ClassificationRules): both directions — clearance
downgrade (group-side rank filter) and floor raise (member-side rank
filter) — each removal audited (group_membership_auto_removed) + in-app
notification. EF gotchas encoded in comments: ExecuteUpdate backfill
must follow SaveChanges (FK target must exist); DB-side rank queries
must run after the triggering mutation is saved (context vs DB).

Share-to-group targeting is deliberately deferred to 7.15 — it is
intrinsically tied to the lattice filter + per-principal resolution
(encrypted-key distribution mechanics) and has no flag-off behavior.

Tests: ClassificationGroupsTests (11) — ladder provisioning + backfill,
double-enable 409, flag-off 409s, clearance raise/audit, self-change
403, unknown level 404, group lifecycle + dup-name + unknown floor,
below-floor 400 / at-floor 200, already-in-group 409, downgrade
auto-removal with audit+notification, floor-raise auto-removal +
lowering refusal. Full suite 1049/0/39.
feat(ci): #196 — real-Postgres migration smoke test in api-ci
Some checks failed
API CI / migrations (pull_request) Failing after 2m7s
Security CI / security-scan (pull_request) Successful in 2m42s
API CI / build-and-test (pull_request) Has been cancelled
e8f25d6022
MigrationSmokeTests applies the FULL EF migration chain to a fresh
postgres:17 service container, asserts defined == applied (a migration
whose SQL fails — the PR #195 '"Users"-vs-users' 42P01 class — breaks
the chain before this line), re-runs MigrateAsync for idempotency, and
pins the snake_case-tables schema convention so a model rename can't
silently split from the live schema.

Skipped via Assert.Skip when MIGRATION_DB is unset (local + main suite);
new api-ci 'migrations' job sets it against the service container.

Local verify: fresh postgres:17 container — all 45 migrations apply,
idempotent re-run clean, schema assertions pass. Suite 1050/0/40.
feat(admin): M8 7.14 — F-CLS4 clearance + groups management in the admin portal
Some checks failed
Security CI / security-scan (pull_request) Successful in 1m47s
API CI / migrations (pull_request) Failing after 1m52s
API CI / build-and-test (pull_request) Successful in 5m59s
Admin CI / build-and-test (pull_request) Successful in 12m8s
c261943cca
TenantDetailPage gains:
- ClassificationPanel: one-way enable flow (typed confirm; disabled
  tenants blocked), ladder chips (Internal → Top Secret), groups table
  with create (name + floor), floor select (server refuses lowers),
  member-count link → members dialog, delete with confirm
- GroupMembersDialog: member list + remove, add-member list split into
  eligible (clearance ≥ floor) and ineligible-disabled-with-reason
  rows (F-CLS4 transparency wording)
- Members table: Clearance column — inline level select per member
  (hidden while classification is off; server re-checks, incl.
  no-self-change 403 surfacing via alert)

Store: classification/groups/groupMembers state + actions; api gains
put(). Test mocks extended (adminStore + TenantDetailPage + KillMember
fixtures carry clearance; api mock gains put).

tsc -b clean; vitest 244/244 (20 files).
Sign in to join this conversation.
No description provided.