From b480552d3f6bb4737bd7b1841ce6b742b2c6f718 Mon Sep 17 00:00:00 2001 From: Denis Bykhov Date: Mon, 6 Mar 2023 21:43:46 +0600 Subject: [PATCH] Dont allow reactivate merged accounts (#2714) Signed-off-by: Denis Bykhov --- server/account/src/index.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/server/account/src/index.ts b/server/account/src/index.ts index 0dee5bebf7..e5e55133dc 100644 --- a/server/account/src/index.ts +++ b/server/account/src/index.ts @@ -74,6 +74,7 @@ const accountPlugin = plugin(accountId, { WorkspaceNotFound: '' as StatusCode<{ workspace: string }>, InvalidPassword: '' as StatusCode<{ account: string }>, AccountAlreadyExists: '' as StatusCode<{ account: string }>, + AccountWasMerged: '' as StatusCode<{ account: string }>, WorkspaceAlreadyExists: '' as StatusCode<{ workspace: string }>, ProductIdMismatch: '' as StatusCode<{ productId: string }> }, @@ -556,15 +557,15 @@ export async function setRole (email: string, workspace: string, productId: stri */ export async function assignWorkspace (db: Db, productId: string, email: string, workspace: string): Promise { const { workspaceId, accountId } = await getWorkspaceAndAccount(db, productId, email, workspace) + const account = await db.collection(ACCOUNT_COLLECTION).findOne({ _id: accountId }) + + if (account !== null) await createEmployeeAccount(account, productId, workspace) + // Add account into workspace. await db.collection(WORKSPACE_COLLECTION).updateOne({ _id: workspaceId }, { $addToSet: { accounts: accountId } }) // Add workspace to account await db.collection(ACCOUNT_COLLECTION).updateOne({ _id: accountId }, { $addToSet: { workspaces: workspaceId } }) - - const account = await db.collection(ACCOUNT_COLLECTION).findOne({ _id: accountId }) - - if (account !== null) await createEmployeeAccount(account, productId, workspace) } async function createEmployee (ops: TxOperations, name: string, email: string): Promise> { @@ -618,6 +619,11 @@ async function createEmployeeAccount (account: Account, productId: string, works employee: employeeId }) } else if (!employee.active) { + if (employee.mergedTo !== undefined) { + throw new PlatformError( + new Status(Severity.ERROR, accountPlugin.status.AccountWasMerged, { account: account.email }) + ) + } await ops.update(employee, { active: true })