From 92d0fc6eb425a77bac3f853ad7e882b4ba2dec31 Mon Sep 17 00:00:00 2001 From: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Date: Mon, 29 Jul 2024 15:18:55 +0100 Subject: [PATCH] fix: auto accept (#15975) * fix: auto accept * Update packages/lib/server/repository/organization.ts Co-authored-by: Hariom Balhara --------- Co-authored-by: Hariom Balhara --- .../lib/server/repository/organization.test.ts | 15 ++++++++++----- packages/lib/server/repository/organization.ts | 6 ++++++ 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/lib/server/repository/organization.test.ts b/packages/lib/server/repository/organization.test.ts index d59df04ab3..3038858e14 100644 --- a/packages/lib/server/repository/organization.test.ts +++ b/packages/lib/server/repository/organization.test.ts @@ -25,8 +25,8 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => { }); it("should throw an error if multiple organizations match the email domain", async () => { - await createOrganization({ name: "Test Org 1", orgAutoAcceptEmail: "example.com" }); - await createOrganization({ name: "Test Org 2", orgAutoAcceptEmail: "example.com" }); + await createReviewedOrganization({ name: "Test Org 1", orgAutoAcceptEmail: "example.com" }); + await createReviewedOrganization({ name: "Test Org 2", orgAutoAcceptEmail: "example.com" }); await expect( OrganizationRepository.findUniqueByMatchingAutoAcceptEmail({ email: "test@example.com" }) @@ -34,7 +34,10 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => { }); it("should return the parsed organization if a single match is found", async () => { - const organization = await createOrganization({ name: "Test Org", orgAutoAcceptEmail: "example.com" }); + const organization = await createReviewedOrganization({ + name: "Test Org", + orgAutoAcceptEmail: "example.com", + }); const result = await OrganizationRepository.findUniqueByMatchingAutoAcceptEmail({ email: "test@example.com", @@ -54,7 +57,7 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => { }); it("should correctly match orgAutoAcceptEmail", async () => { - await createOrganization({ name: "Test Org", orgAutoAcceptEmail: "noexample.com" }); + await createReviewedOrganization({ name: "Test Org", orgAutoAcceptEmail: "noexample.com" }); const result = await OrganizationRepository.findUniqueByMatchingAutoAcceptEmail({ email: "test@example.com", @@ -64,7 +67,7 @@ describe("Organization.findUniqueByMatchingAutoAcceptEmail", () => { }); }); -async function createOrganization({ +async function createReviewedOrganization({ name = "Test Org", orgAutoAcceptEmail, }: { @@ -78,6 +81,8 @@ async function createOrganization({ organizationSettings: { create: { orgAutoAcceptEmail, + isOrganizationVerified: true, + isAdminReviewed: true, }, }, }, diff --git a/packages/lib/server/repository/organization.ts b/packages/lib/server/repository/organization.ts index 26fa8a97d9..3bb8ade09f 100644 --- a/packages/lib/server/repository/organization.ts +++ b/packages/lib/server/repository/organization.ts @@ -172,10 +172,16 @@ export class OrganizationRepository { isOrganization: true, organizationSettings: { orgAutoAcceptEmail: emailDomain, + isOrganizationVerified: true, + isAdminReviewed: true, }, }, }); if (orgs.length > 1) { + logger.error( + "Multiple organizations found with the same auto accept email domain", + safeStringify({ orgs, emailDomain }) + ); // Detect and fail just in case this situation arises. We should really identify the problem in this case and fix the data. throw new Error("Multiple organizations found with the same auto accept email domain"); }