Commit 5e166d7
authored
feat(organizations): always-create workspace + suggestedJoin hint (drop onboarding limbo) (#3680)
* feat(organizations): canonical email-domain normalization helper
* feat(organizations): always-create workspace + suggestedJoin hint, drop autoCreate footgun
Spec D5 — every signup provisions an active workspace. autoCreate config flag is a
deprecated no-op; no path returns organizationSetupRequired or pendingJoin.
- handleSignupOrganization: delete autoCreate:false footgun branch entirely; all enabled
paths call createOrganizationForUser returning {organization, membership}.
- Domain-match branch: drop createJoinRequest+pendingJoin; return suggestedJoin:
{orgId,orgName} name-only hint alongside the newly created workspace.
- Use A1 isPublicDomain for the public-domain gate (hardcoded list + config overrides).
- Naming: domainMatching+corporate domain → domain-based name; all other cases
(domainMatching off, public domain) → "{firstName}'s organization".
- signupGrant: credited inside createOrganizationForUser, once per real new org,
never double-credited. Preserved exactly from pre-A2.
- Auth controller: no change needed — uses ||false/||null fallbacks on removed keys.
- Test updates (required 0-failure): emailVerification, domainJoin E2E, auth signup
integration + auth E2E updated to assert new always-create contract.
- New unit test: organizations.service.signup.unit.tests.js — all config combos,
suggestedJoin shape (name-only), signupGrant credited once, createJoinRequest never.
* fix(organizations): remove dead imports + harden signup test mock isolation
- I1: remove unused MembershipService import and dead sanitizeOrg helper (both
orphaned by A2); file is now lint-clean (no-unused-vars: 0)
- I2: replace clearAllMocks() with resetAllMocks() + explicit defaults in top-level
beforeEach; prevents mockReturnValue leaking across describe blocks
- m1: hoist triple `orgConfig.domainMatching && !domainIsPublic` into const
isCorporateDomain; used at all 3 call sites, behavior identical
- m2: reword misleading e2e comment on suggestedOrganization:null to state actual
controller contract and reference A2b for wiring
* fix(organizations): normalize domain on write + exact-match read via canonical normalizeEmailDomain
replace extractDomain(user.email) with normalizeEmailDomain (A1) at the two signup
sites in handleSignupOrganization: the repository list query (read) and the domain
passed to createOrganizationForUser (write). both now use the single canonical
lowercased/trimmed/null-safe path from organizations.domain.js.
guard isCorporateDomain against null domain (malformed email → normalizeEmailDomain
returns null → treated as non-corporate, falls through to personal workspace).
extractDomain kept as exported public API for non-signup callers; not modified.
tests (A3): mixed-case write normalization, case-insensitive match, subdomain
non-match (eu.acme.com ≠ acme.com), public-domain gate with mixed-case email.
* refactor(organizations): drop dead extractDomain + simplify public-domain guard
Remove extractDomain (def + JSDoc + export entry) — fully superseded by
normalizeEmailDomain since A3; 0 callers in repo. Drop stale "kept for
non-signup callers" comment (was factually wrong). Simplify domainIsPublic
to `isPublicDomain(domain) || publicDomains.includes(domain ?? '')` —
normalizeEmailDomain guarantees a lowercased string or null, so the
redundant ?. chain is gone. Fix stale RED label in A3 test to describe
the canonical-normalization contract it actually asserts.
* fix(organizations): idempotent retry-safe signup provisioning (spec C1 / A4)
Add convergence guard in handleSignupOrganization: if the user already holds
an active membership (partial-failure retry scenario), return the existing
org+membership without calling createOrganizationForUser — preventing duplicate
workspaces and double-crediting signupGrant on retried signups.
Uses MembershipRepository.findOne({ userId, status: ACTIVE }) — same canonical
read as autoSetCurrentOrganization. Guard fires after the email-verification
early-return and before Case 1/Case 2 always-create paths. signupGrant stays
once-only because it lives inside createOrganizationForUser, which is skipped.
* refactor(organizations): dedupe signup result builder + lock email-verif ordering test
* feat(auth): forward suggestedJoin through signup HTTP response (A2b)
Controller now serializes `suggestedJoin: { orgId, orgName } | null`
from orgResult into the signup response body alongside the existing keys.
`suggestedOrganization` kept as always-null with deprecation comment
(additive — breaking removal deferred to next release).
TDD: two integration tests (shape assert + null path), auth 1579 / orgs 1469 green.
* fix(organizations): address CodeRabbit + Copilot review findings
- domain: reject multiple-@ malformed emails in normalizeEmailDomain
- service: JSDoc for buildResult @param/@returns (CR+Copilot)
- service: update @returns to reflect null org/membership on mailer path
- e2e: add explicit suggestedJoin assertion on domain-match signup path
- e2e: fix stale A2b comment (now shipped in this PR)
- unit: remove stale "RED" test-driven header comment
- unit: cover multiple-@ rejection in domain tests1 parent 77acdad commit 5e166d7
9 files changed
Lines changed: 842 additions & 160 deletions
File tree
- modules
- auth
- controllers
- tests
- organizations
- services
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
| 147 | + | |
147 | 148 | | |
| 149 | + | |
148 | 150 | | |
149 | 151 | | |
150 | 152 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
122 | 124 | | |
123 | 125 | | |
124 | 126 | | |
| |||
139 | 141 | | |
140 | 142 | | |
141 | 143 | | |
142 | | - | |
| 144 | + | |
143 | 145 | | |
144 | 146 | | |
145 | 147 | | |
| |||
153 | 155 | | |
154 | 156 | | |
155 | 157 | | |
156 | | - | |
| 158 | + | |
157 | 159 | | |
158 | | - | |
159 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
160 | 164 | | |
161 | | - | |
162 | | - | |
| 165 | + | |
| 166 | + | |
163 | 167 | | |
164 | | - | |
165 | | - | |
| 168 | + | |
| 169 | + | |
166 | 170 | | |
167 | | - | |
| 171 | + | |
| 172 | + | |
168 | 173 | | |
169 | | - | |
170 | | - | |
| 174 | + | |
| 175 | + | |
171 | 176 | | |
172 | 177 | | |
173 | | - | |
| 178 | + | |
174 | 179 | | |
175 | | - | |
| 180 | + | |
176 | 181 | | |
177 | 182 | | |
178 | 183 | | |
| |||
Lines changed: 42 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
116 | 116 | | |
117 | 117 | | |
118 | 118 | | |
119 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
120 | 122 | | |
121 | 123 | | |
122 | | - | |
123 | 124 | | |
124 | 125 | | |
125 | | - | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
143 | 143 | | |
144 | 144 | | |
145 | 145 | | |
146 | | - | |
| 146 | + | |
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | | - | |
163 | | - | |
164 | | - | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
165 | 166 | | |
166 | | - | |
| 167 | + | |
167 | 168 | | |
168 | 169 | | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
169 | 183 | | |
170 | 184 | | |
171 | 185 | | |
| |||
215 | 229 | | |
216 | 230 | | |
217 | 231 | | |
218 | | - | |
| 232 | + | |
219 | 233 | | |
220 | 234 | | |
221 | 235 | | |
222 | | - | |
223 | 236 | | |
224 | 237 | | |
225 | 238 | | |
| |||
235 | 248 | | |
236 | 249 | | |
237 | 250 | | |
238 | | - | |
| 251 | + | |
239 | 252 | | |
240 | 253 | | |
241 | 254 | | |
242 | 255 | | |
243 | | - | |
| 256 | + | |
244 | 257 | | |
245 | 258 | | |
246 | 259 | | |
| |||
254 | 267 | | |
255 | 268 | | |
256 | 269 | | |
257 | | - | |
258 | | - | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
259 | 274 | | |
260 | 275 | | |
261 | 276 | | |
262 | | - | |
263 | 277 | | |
264 | 278 | | |
265 | 279 | | |
| |||
275 | 289 | | |
276 | 290 | | |
277 | 291 | | |
278 | | - | |
279 | | - | |
280 | | - | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
281 | 297 | | |
282 | | - | |
| 298 | + | |
283 | 299 | | |
284 | 300 | | |
285 | 301 | | |
| |||
312 | 328 | | |
313 | 329 | | |
314 | 330 | | |
315 | | - | |
| 331 | + | |
316 | 332 | | |
317 | 333 | | |
318 | 334 | | |
319 | | - | |
| 335 | + | |
| 336 | + | |
320 | 337 | | |
321 | 338 | | |
322 | 339 | | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
323 | 343 | | |
324 | 344 | | |
325 | 345 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
0 commit comments