Skip to content

Commit a9a9715

Browse files
authored
Prevent duplicate organization creation via website check (#1514)
1 parent 484dc58 commit a9a9715

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

backend/src/services/organizationService.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,14 @@ export default class OrganizationService extends LoggerBase {
329329
}
330330

331331
let record
332+
let existing
332333

333-
const existing = await OrganizationRepository.findByIdentity(primaryIdentity, this.options)
334+
// check if organization already exists using website or primary identity
335+
if (data.website) {
336+
existing = await OrganizationRepository.findByDomain(data.website, this.options)
337+
} else {
338+
existing = await OrganizationRepository.findByIdentity(primaryIdentity, this.options)
339+
}
334340

335341
if (existing) {
336342
await OrganizationRepository.checkIdentities(data, this.options, existing.id)

services/apps/data_sink_worker/src/service/organization.service.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,14 @@ export class OrganizationService extends LoggerBase {
115115
}
116116
}
117117

118-
// now check if exists in this tenant using the primary identity
119-
const existing = await txRepo.findByIdentity(tenantId, primaryIdentity)
118+
let existing
119+
120+
// now check if exists in this tenant using the website or primary identity
121+
if (data.website) {
122+
existing = await txRepo.findByDomain(tenantId, segmentId, data.website)
123+
} else {
124+
existing = await txRepo.findByIdentity(tenantId, primaryIdentity)
125+
}
120126

121127
let attributes = existing?.attributes
122128

0 commit comments

Comments
 (0)