10 Commits

Author SHA1 Message Date
d-robotics
2335bf16f3 ✨ Add supplier authorization and shared final acceptance pool 2026-09-29 22:04:45 -07:00
eust-w
106235bb02 ✨ Remove Email field, complete phone-only account identity (ticket 05)
Contract step of the account-phone-login expand-migrate-contract rollout.
Phone is now the sole account identifier end to end:

- domain.UserRecord/CreateUserInput: delete Email, drop Phone's omitempty
  (required going forward).
- store: delete email_unique Mongo index; phone_unique is now non-sparse
  (unique, not sparse) since every account creation path requires a phone.
  Delete FindUserByEmail, ensureUserEmailAvailableLocked, and
  ErrDuplicateUserEmail (confirmed dead via grep - all real call sites were
  already migrated to the *Phone equivalents by tickets 01-03). Mongo
  duplicate-key fallback and the account-mutation-guard's stale-write
  snapshot/filter now key off Phone instead of Email.
- api: drop the now-impossible ErrDuplicateUserEmail branch in
  renderUserMutationError. The account-hierarchy audit endpoint and the
  supplier-deletion receipt struct both switch their identifying field from
  Email to Phone, since both are populated fresh from current account state
  (not frozen historical snapshots) - continuing to read a "email" key would
  silently go blank for every account created after this change.
- frontend: src/types.ts User.phone is now required (email removed);
  AccountHierarchyIssue.email -> .phone in services/api/users.ts and
  pages/Users.tsx to match the backend audit endpoint's renamed field.
- Rewrote the wide blast radius of Go test fixtures that constructed users
  by email across internal/api/*_test.go and internal/store/*_test.go,
  including the two dedicated memory-store uniqueness tests (merged into
  phone-only equivalents) and several opt-in "live" acceptance-fixture
  tests gated behind env vars for real Fanyu deployments.

Repo-wide grep of Go and TS/TSX for Email/email/邮箱 turned up no remaining
account-identifier references outside of a few harmless test-only cosmetic
labels (e.g. "Email Tenant" as an org display name in a seed helper) and
assertions that explicitly check "邮箱" text is absent from API responses.

go build/vet clean. go test ./internal/api/... ./internal/store/...
./internal/domain/... : 75 failures, identical test names to the
pre-ticket-05 baseline (diffed against a throwaway worktree at the prior
tip). npm run lint:web (tsc --noEmit) clean. npm run test:frontend:
599/586/13, matching the stated baseline exactly.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 14:30:50 +08:00
eust-w
412c94fa70 ✨ Switch account management create/edit to phone identifier (ticket 02)
Wires the Phone field/validation/uniqueness helpers added in ticket 01
into the account-management create/edit path, per the
account-phone-login migration spec.

Backend (internal/api/server.go, internal/domain/types.go,
internal/store/{memory,mongo}.go, internal/api/store_errors.go):
- handleUsersCreate/handleUsersUpdate now validate and enforce phone
  (^1[3-9]\d{9}$, uniqueness) instead of email; duplicate-phone errors
  return field "phone" with no "邮箱" wording.
- CreateUserInput gained a Phone field, wired through both store
  backends' CreateUser.
- Email remains on UserRecord (still used by login/self-profile,
  untouched here) but is no longer required/validated on account
  create/edit.

Frontend (src/pages/Users.tsx, src/services/api/users.ts,
src/types.ts, src/context/UserContext.tsx):
- Account management create/edit form, search box, and table column
  switch from email to phone (type="tel", client-side
  ^1[3-9]\d{9}$ validation, Chinese labels updated to "手机号").
- User type gained an optional `phone` field; usersApi.create's
  payload field renamed from email to phone to match.
- UserContext's createUser helper type/impl updated to match (dead
  code today, unused by any caller, but kept building); login/session
  bootstrap logic in UserContext.tsx is untouched.

Explicitly out of scope, per the research notes' scope boundary and
spec decision 7: the real "存量账号迁移" (migrating Fanyu's live
accounts to real phone numbers) is a human-supervised, deployment-time
operation, not something this session executed. No production Fanyu
Mongo/kubeconfig was touched. This ticket only makes the admin
UI/API *capable* of setting a phone number on new or existing
accounts, verified against the in-memory store and local fixtures.

Also left untouched, per scope: login page/flow, auth.ts,
UserContext's login/session logic (ticket 03); Sidebar.tsx,
ProjectMembersPanel.tsx, UserBootstrapPanel.tsx (ticket 04).

Verified: go build ./... clean; go vet ./... clean; gofmt clean on
touched files; go test ./internal/api/... and ./internal/store/...
produce the exact same 75 pre-existing failing test names as the
ticket-01 baseline (only two account/edit-adjacent tests updated to
assert phone instead of email behavior, plus a new
TestUserPhoneValidationAndUniquenessOnCreateAndEdit covering
create/edit phone format + uniqueness + role/supplier preservation);
npm run lint:web (tsc --noEmit) clean; node --test
tests/frontend/*.test.mjs matches the pre-existing baseline exactly
(599 tests, 586 pass, 13 fail, identical failing test names).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-09-22 12:28:58 +08:00
eust-w
026912a35c 🐛 Separate account deletion from disabling and preserve audit identity 2026-09-21 16:58:04 +08:00
eust-w
a8830a6161 🗑️ Add resumable supplier cascade deletion with shared-data protection 2026-09-21 15:09:48 +08:00
eust-w
9fc2586af3 🔒 Support standalone MongoDB account mutations and audit Fanyu rollout 2026-09-21 11:48:37 +08:00
eust-w
c92bca168d 👥 Unify supplier account management and enforce single account roles 2026-09-21 11:30:03 +08:00
eust-w
db9040ccb2 🔐 Enforce supplier account permissions and protect administrator lifecycle 2026-09-21 00:30:28 +08:00
eust-w
add1b0e7ac 🔒 Fix employee supplier ownership at creation and simplify membership routing 2026-09-14 15:47:44 +08:00
eust-w
34733b4b57 🔐 Normalize duplicate identity errors 2026-06-18 12:41:01 +08:00