feat: company scoping (INS and CV, super admins see all) #25

Merged
ngqile merged 24 commits from add-company-scoping into main 2026-11-30 13:38:08 +00:00
Owner

OpenSpec change add-company-scoping (design: docs/superpowers/specs/2026-11-30-company-scoping-design.md).

What

  • Two companies at go-live (INS, CV). Staff sign in with company + username + password; the stored login name is username@code. Super admins leave Company blank, belong to no company and see everything.
  • Companies screen (super admin only): create, edit name/status, rename code (renames staff login names and ends their sessions). Deactivating a company blocks its sign-in and ends its sessions.
  • Every /api/admin/** handler is scoped through AdminCompanyScope: lists and exports filter by the caller's company (super admin: chosen company or all); another company's record answers 404; creates need a concrete company.
  • Roles, interests (now one shared list), lockout settings and password rules: read for staff, write for super admins only.
  • Events and emails carry a company; login history and audit log are scoped (no-company rows only for super admins).
  • Portal: Company field on login/forgot-password, header company picker and Company column for super admins, company fields on create forms, read-only shared screens for staff.

Database

openspec/changes/add-company-scoping/sql/01..03 (+ 99-rollback.sql), mirrored in local/seed/03-colite.sql. 03 ends every admin session. See docs/deployment.md sections 3 and 10.

Verification

  • mvn -T 1C -B verify (all modules): BUILD SUCCESS — mobile-api 712, services-system 166, services-counter 148 tests.
  • Portal: vitest 1349 passed, tsc 0, lint 0 errors, next build 0.
  • Live check on the local stack: INS and CV users with the same username each see only their own events, users, leads, emails, audit log and login history; admin sees both; a CV event/user by id answers 404 to INS.
  • Playwright (1280 px and 360 px): picker switching All/INS/CV, CV user created through the form, INS opening a CV event URL sees not-found, renaming CV's code signs the CV user out, deactivating CV blocks its sign-in.
  • Live check found and fixed: missing gateway route for /company/**, numeric companyId in String-valued backend filters, login history without the company, Company column blank when companies load after rows.

Known follow-ups (reviewed, accepted for now)

  • AdminCompanyScope.scope is fail-open for a company-less admin without role 1 (such users cannot be saved and none exist after the migration).
  • AppAccessAspect module bypass checks role 1 only.
  • Don't reuse a renamed company code while old sessions may be valid (documented).
  • Super-admin lead capture finds the event's company among the first 100 enabled events.

🤖 Generated with Claude Code

https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM

OpenSpec change `add-company-scoping` (design: `docs/superpowers/specs/2026-11-30-company-scoping-design.md`). ## What - Two companies at go-live (INS, CV). Staff sign in with **company + username + password**; the stored login name is `username@code`. Super admins leave Company blank, belong to no company and see everything. - Companies screen (super admin only): create, edit name/status, rename code (renames staff login names and ends their sessions). Deactivating a company blocks its sign-in and ends its sessions. - Every `/api/admin/**` handler is scoped through `AdminCompanyScope`: lists and exports filter by the caller's company (super admin: chosen company or all); another company's record answers 404; creates need a concrete company. - Roles, interests (now one shared list), lockout settings and password rules: read for staff, write for super admins only. - Events and emails carry a company; login history and audit log are scoped (no-company rows only for super admins). - Portal: Company field on login/forgot-password, header company picker and Company column for super admins, company fields on create forms, read-only shared screens for staff. ## Database `openspec/changes/add-company-scoping/sql/01..03` (+ `99-rollback.sql`), mirrored in `local/seed/03-colite.sql`. `03` ends every admin session. See `docs/deployment.md` sections 3 and 10. ## Verification - `mvn -T 1C -B verify` (all modules): BUILD SUCCESS — mobile-api 712, services-system 166, services-counter 148 tests. - Portal: vitest 1349 passed, `tsc` 0, lint 0 errors, `next build` 0. - Live check on the local stack: INS and CV users with the same username each see only their own events, users, leads, emails, audit log and login history; `admin` sees both; a CV event/user by id answers 404 to INS. - Playwright (1280 px and 360 px): picker switching All/INS/CV, CV user created through the form, INS opening a CV event URL sees not-found, renaming CV's code signs the CV user out, deactivating CV blocks its sign-in. - Live check found and fixed: missing gateway route for `/company/**`, numeric companyId in String-valued backend filters, login history without the company, Company column blank when companies load after rows. ## Known follow-ups (reviewed, accepted for now) - `AdminCompanyScope.scope` is fail-open for a company-less admin without role 1 (such users cannot be saved and none exist after the migration). - `AppAccessAspect` module bypass checks role 1 only. - Don't reuse a renamed company code while old sessions may be valid (documented). - Super-admin lead capture finds the event's company among the first 100 enabled events. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile added 24 commits 2026-11-30 13:38:03 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
The services-system and services-counter property maps are String-valued;
a numeric companyId failed the cast there and the scoped lists came back empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
The table caches accessor values per row, so a code looked up before the
companies list arrived stayed blank; render it in the cell instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
ngqile merged commit 66904869cf into main 2026-11-30 13:38:08 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ngqile/co-lite#25