fix: auto accept (#15975)
* fix: auto accept * Update packages/lib/server/repository/organization.ts Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> --------- Co-authored-by: Hariom Balhara <hariombalhara@gmail.com>
This commit is contained in:
co-authored by
Hariom Balhara
parent
4d0b417925
commit
92d0fc6eb4
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user