feature/account-phone-login #7

Merged
longtao.wu merged 14 commits from feature/account-phone-login into dev 2026-09-22 15:00:18 +08:00
Owner
No description provided.
longtao.wu added 3 commits 2026-09-22 12:00:27 +08:00
Requirements gathering for replacing email with a phone-number account
identifier (format-only validation, no SMS). Spec and five expand-migrate
-contract tickets ready for implementation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Author
Owner

📝 进度说明

规格与工单拆分已完成:

  • 规格:.scratch/account-phone-login/spec.md
  • 5 张工单(expand → migrate → contract):.scratch/account-phone-login/issues/01–05

当前状态:01 号工单(新增手机号字段与校验)正在独立 worktree 中实现,尚未合并。02/03/04/05 按依赖关系依次跟进。这个 PR 目前还没有实际功能改动,暂不建议部署到 Fanyu;会在全部工单完成、代码评审通过、合并回 dev 后走正常发布流程部署。

📝 **进度说明** 规格与工单拆分已完成: - 规格:`.scratch/account-phone-login/spec.md` - 5 张工单(expand → migrate → contract):`.scratch/account-phone-login/issues/01`–`05` 当前状态:01 号工单(新增手机号字段与校验)正在独立 worktree 中实现,尚未合并。02/03/04/05 按依赖关系依次跟进。**这个 PR 目前还没有实际功能改动**,暂不建议部署到 Fanyu;会在全部工单完成、代码评审通过、合并回 `dev` 后走正常发布流程部署。
longtao.wu added 2 commits 2026-09-22 12:10:08 +08:00
Expand step of the account-phone-login migration (ticket 01): adds
UserRecord.Phone, a sparse phone_unique Mongo index, a China mainland
mobile regex validator (^1[3-9]\d{9}$), FindUserByPhone (Mongo +
memory), and phone uniqueness helpers (ensureUserPhoneAvailableLocked,
validateUserPhoneAvailable) mirroring the existing Email plumbing.

Nothing wires Phone into login, account creation, or account editing
yet — Email remains the sole identifier used by existing flows, so
behavior is unchanged from a user's perspective. That's tickets
02/03/05.

Verified: go build ./... clean; new tests
(TestMemoryStoreFindUserByPhoneAndEnforcesUniqueness,
TestIsValidChinaMobilePhone, TestValidateUserPhoneAvailable) pass;
full internal/api suite has the same 75 pre-existing failures
(identical names) before and after this change.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Expand step of the email→phone identifier migration. Adds Phone
alongside Email without touching any existing login/account behavior.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
longtao.wu added 2 commits 2026-09-22 12:22:20 +08:00
Renames the shared User.email/ProjectMember.userEmail fields to phone/
userPhone and updates every display and field reference outside the
account-management page (src/pages/Users.tsx, ticket 02) and the login
flow (src/services/api/auth.ts + UserContext/UserBootstrapPanel's login
call signature, ticket 03): project member list, sidebar profile,
bootstrap panel copy, and the candidate-user pickers in Projects.tsx,
ObjectSync.tsx, and SupplierDeletionDialog.tsx.

AccountHierarchyIssue.email in services/api/users.ts is left as-is: it
mirrors a read-only historical audit field the backend still returns
under the "email" key, matching the spec's carve-out for legacy
audit-log data.

Note: internal/api/project_members.go does not yet copy user.Phone into
the project-member view response, so ProjectMembersPanel will show a
blank phone until that backend field is wired up (flagged separately).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Sidebar, ProjectMembersPanel, UserBootstrapPanel, UserContext (non-login
fields), types.ts, users.ts payloads. Login flow and Users.tsx account
management left untouched (tickets 03/02).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
longtao.wu added 2 commits 2026-09-22 13:35:36 +08:00
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>
Admin account-management UI and API now validate/enforce phone instead
of email on create/edit. Production Fanyu data migration deferred to
deployment time per spec decision 7 — not executed here.

Merge conflict resolution + gap fixes found while reconciling 02 and 04:
- src/types.ts / UserContext.tsx / users.ts: kept Email required + Phone
  optional (matches current migration state — login still uses email
  until ticket 03); createUser/updateCurrentUser signatures reconciled
  to the versions that are actually wired to real backend behavior.
- internal/api/project_members.go: projectMemberView never exposed
  Phone (ticket 04's frontend rename to userPhone had nothing to read).
  Renamed UserEmail->UserPhone and populated it from user.Phone.
- internal/store/memory.go + mongo.go: ListProjectMemberUsers's field
  whitelist projection dropped Phone entirely (pre-existed the Phone
  field, never updated) — same root cause as project_members.go, one
  layer down.
- internal/api/auth.go: handleCurrentUserProfileUpdate/
  currentUserProfilePatch still only supported Email; self-service
  profile edit silently no-opped on phone. Wired to phone validation
  mirroring the ticket-02 admin create/edit pattern.
- Updated 3 tests whose expectations depended on the self-profile-update
  gap above (TestSessionAuthTenantIsolationAndRolePermissions,
  TestUserEmailUniquenessValidation, TestProjectMemberDisplayScopedBatch)
  to phone; verified full internal/api suite back to the 75-failure
  baseline (byte-identical failing test names) and frontend suite at
  599/586/13 baseline.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
longtao.wu added 2 commits 2026-09-22 14:06:44 +08:00
- handleAuthLogin now authenticates via store.FindUserByPhone instead of
  FindUserByEmail; the login/bootstrap-super-admin request payload field
  is now `phone`. Old email addresses are no longer valid login credentials.
- bootstrap-super-admin now validates phone format (isValidChinaMobilePhone)
  instead of net/mail.ParseAddress; net/mail is fully removed from
  internal/api.
- Same-class gap fix: handleAdminOrganizationUsersCreate (the legacy
  per-organization admin endpoint, not touched by ticket 02) still created
  users by email only, which would have left them unable to log in under
  the new phone-only login. Switched it to phone validation/uniqueness too,
  and removed the now-dead normalizeUserInput/validateUserEmailAvailable
  helpers.
- Frontend: authApi.login, UserContext's login signature, and
  UserBootstrapPanel's submit handler now send `phone` instead of `email`
  (the form/labels were already phone-based from ticket 04).
- Updated ~20 Go test files whose fixtures/helpers logged in via
  user.Email; adminCreateUser/loginSession/bootstrapSuperAdminSession now
  work in terms of phone (deterministically derived from existing
  email-shaped test identities via testPhoneFromSeed, to avoid rewriting
  every call site). Added internal/api/auth_phone_login_test.go covering
  phone login success/failure and old-email rejection.

go test ./internal/api/... and npm run test:frontend match their
pre-ticket baselines exactly (75 Go failures / 599 frontend tests with
586 pass, 13 fail) by failing test name, not just count.
handleAuthLogin, bootstrap-super-admin, and the login UI now use phone
instead of email. Also converts the legacy
/api/admin/organizations/{id}/users account-creation endpoint to phone
(same-class gap as found while merging ticket 02/04 — it would have
created accounts unable to log in once login became phone-only).
net/mail is now fully removed from internal/api.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
longtao.wu added 2 commits 2026-09-22 14:32:50 +08:00
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>
Contract step: UserRecord.Email deleted, phone_unique tightened from
sparse to non-sparse, dead email-specific store/API code removed.
Account-hierarchy/supplier-deletion identifying fields switched to
Phone (they reflect live account state on every request, not frozen
history, so this isn't the historical-audit exception the spec allows).
~35 test files migrated off email fixtures.

Closes the account-phone-login spec and all five tickets.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
longtao.wu added 1 commit 2026-09-22 14:37:59 +08:00
Standards + Spec review (two parallel sub-agents against dev) both
independently caught the same real regression, plus three smaller
issues:

- internal/store/supplier_deletion.go: supplierDeletionProjection's
  "users" case still projected "email" instead of "phone", so
  supplier-deletion audit plans silently showed an empty phone for
  every account on the real Mongo store (memory store was unaffected,
  which is why tests didn't catch it). Same bug class as the
  ListProjectMemberUsers gap fixed while merging ticket 02 — missed
  in the sweep.
- internal/store/mongo.go: ListProjectMemberUsers's projection still
  listed a stray "email": 1 for a field that no longer exists on
  UserRecord since ticket 05. Harmless but dead.
- src/lib/phone.ts (new): extracted the phone regex/validator that had
  been duplicated (RegExp in Users.tsx, a re-typed string literal in
  its own JSX pattern attribute) into one shared module.
- src/components/Sidebar.tsx: the self-profile phone edit form (wired
  during the ticket-03 merge, not by any single ticket) had no
  client-side format validation, unlike the account-management form —
  now uses the same shared pattern/validator.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Author
Owner

✅ 全部完成,可以评审了

5 张工单全部实现并合并(01→02→03→04→05,expand-migrate-contract),标准/规格两轴代码评审已跑完,发现的问题都已修复并重新验证。

实现内容:

  • 手机号(^1[3-9]\d{9}$)彻底替换邮箱,作为账号登录标识
  • Email 字段、email_unique 索引、net/mail 校验代码全部删除
  • 账号管理创建/编辑、登录、自助资料修改、项目成员展示、供应商删除审计全部改用手机号
  • 顺手转换了一个遗漏的旧接口(/api/admin/organizations/{id}/users),避免建出无法登录的账号

代码评审修复:两个并行子agent独立发现同一个真实回归——supplier_deletion.go 的 Mongo 字段投影漏了 phone,导致真实库上供应商删除审计会显示空手机号;另外清理了一处死代码、把重复的手机号正则提取成共享模块、给资料自助编辑表单补上了跟账号管理页一致的前端校验。

验证:go build/go vet 全干净;go test ./internal/api/... ./internal/store/... ./internal/domain/... 失败数与合并前基线(75项)逐条比对完全一致,无回归;前端 tsc --noEmit 干净,test:frontend 599/586/13 与基线一致。

明确没做的:泛宇生产环境真实账号数据迁移——按规格决策 7,这是代码评审通过、合并到 dev 之后的独立部署时操作,本次 PR 全程没有连接过任何生产 MongoDB 或 kubeconfig。

✅ **全部完成,可以评审了** 5 张工单全部实现并合并(01→02→03→04→05,expand-migrate-contract),标准/规格两轴代码评审已跑完,发现的问题都已修复并重新验证。 **实现内容**: - 手机号(`^1[3-9]\d{9}$`)彻底替换邮箱,作为账号登录标识 - `Email` 字段、`email_unique` 索引、`net/mail` 校验代码全部删除 - 账号管理创建/编辑、登录、自助资料修改、项目成员展示、供应商删除审计全部改用手机号 - 顺手转换了一个遗漏的旧接口(`/api/admin/organizations/{id}/users`),避免建出无法登录的账号 **代码评审修复**:两个并行子agent独立发现同一个真实回归——`supplier_deletion.go` 的 Mongo 字段投影漏了 `phone`,导致真实库上供应商删除审计会显示空手机号;另外清理了一处死代码、把重复的手机号正则提取成共享模块、给资料自助编辑表单补上了跟账号管理页一致的前端校验。 **验证**:`go build`/`go vet` 全干净;`go test ./internal/api/... ./internal/store/... ./internal/domain/...` 失败数与合并前基线(75项)逐条比对完全一致,无回归;前端 `tsc --noEmit` 干净,`test:frontend` 599/586/13 与基线一致。 **明确没做的**:泛宇生产环境真实账号数据迁移——按规格决策 7,这是代码评审通过、合并到 `dev` 之后的独立部署时操作,本次 PR 全程没有连接过任何生产 MongoDB 或 kubeconfig。
longtao.wu merged commit 7fc303bd2f into dev 2026-09-22 15:00:18 +08:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: longtao.wu/droboticflow#7
No description provided.