forked from baron/baron-sso
테넌트 import 규칙 개선
This commit is contained in:
@@ -150,6 +150,27 @@ describe("tenantCsvImport", () => {
|
||||
expect(csv).not.toContain("local-tenant-id");
|
||||
});
|
||||
|
||||
|
||||
it("preserves source tenant_id when a create resolution does not override it", () => {
|
||||
const exportedTenantId = "11111111-2222-4333-8444-555555555555";
|
||||
const rows = parseTenantCSV(
|
||||
`tenant_id,name,type,parent_tenant_id,parent_tenant_slug,slug,memo,email_domain
|
||||
${exportedTenantId},Tenant With UUID,COMPANY,,,tenant-with-uuid,Memo,tenant-with-uuid.example.com
|
||||
`,
|
||||
);
|
||||
const preview = buildTenantImportPreview(rows, tenants);
|
||||
const csv = serializeTenantImportCSV(preview, {
|
||||
2: {
|
||||
mode: "create",
|
||||
slug: "tenant-with-uuid",
|
||||
},
|
||||
});
|
||||
|
||||
expect(csv).toContain(
|
||||
`${exportedTenantId},Tenant With UUID,COMPANY,,,tenant-with-uuid,Memo,tenant-with-uuid.example.com`,
|
||||
);
|
||||
});
|
||||
|
||||
it("remaps child parent_tenant_id from source ids to selected staging ids", () => {
|
||||
const rows = parseTenantCSV(
|
||||
[
|
||||
|
||||
@@ -325,12 +325,15 @@ function buildTargetTenantIds(
|
||||
continue;
|
||||
}
|
||||
|
||||
const sourceTenantId = isUUIDLikeTenantId(preview.row.tenantId)
|
||||
? preview.row.tenantId
|
||||
: "";
|
||||
const targetTenantId =
|
||||
typeof resolution === "string"
|
||||
? resolution || preview.row.tenantId
|
||||
? resolution || sourceTenantId
|
||||
: resolution.mode === "existing"
|
||||
? resolution.tenantId
|
||||
: resolution.tenantId || createTenantImportId();
|
||||
: resolution.tenantId || sourceTenantId || createTenantImportId();
|
||||
const targetSlug =
|
||||
typeof resolution === "object" && resolution.mode === "create"
|
||||
? resolution.slug || preview.defaultCreateSlug
|
||||
@@ -400,6 +403,13 @@ function createTenantImportId() {
|
||||
.padEnd(12, "0")}`;
|
||||
}
|
||||
|
||||
|
||||
function isUUIDLikeTenantId(value: string) {
|
||||
return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(
|
||||
value,
|
||||
);
|
||||
}
|
||||
|
||||
function findTenantImportConflicts(
|
||||
row: TenantCSVRow,
|
||||
tenants: TenantSummary[],
|
||||
|
||||
Reference in New Issue
Block a user