feat(auth): lazily re-home default-tenant users to their org tenant (PMS-243) #177
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/mapps-243-rehome"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What
Implements PMS-243: lazily re-home users still parked in the shared default tenant to their real org tenant. Follow-up to PMS-240 (#175, now merged).
How
On the first org-claimed login, the bunyip path moves the user's
usersrow out of the default tenant before the org-tenant lookup.AuthService::rehome_user_between_tenants(user, from, to)runsUPDATE users SET tenant_id = to WHERE id = user AND tenant_id = from- scoped tofrom_tenant(a correctly-placed user is never moved) and idempotent (no-op once moved). The middleware calls it only when the resolved tenant differs from the default.Also a correctness fix for PMS-240
upsert_user_from_oidcdoesON CONFLICT (id) DO UPDATEwithout touchingtenant_id. So an existing default-tenant user presenting abunyip_org_idclaim would have: missed the org-tenant lookup, fallen through the JIT upsert (row stays in default), missed the re-lookup, and been dropped by the bunyip path - unable to log in. The re-home closes that gap.Scope (per PMS-243 decision)
Only the
usersrow moves. Data created while many orgs shared the default tenant is co-mingled and can't be auto-attributed to one org, so it stays put for separate triage.Forward-compatible
Inert until Bunyip emits
bunyip_org_id(BUNYIP-95): with no claim the resolved tenant IS the default, so the re-home guard is skipped.Verification
cargo check --all-targets,cargo clippy --all-targets: clean.tests/tenants.rs: newrehome_moves_default_tenant_user_to_org_tenant_once(move once -> idempotent no-op). tenants + auth suites green.🤖 Generated with Claude Code