From 0771ec55fbee2578daf2e42bff476ad764432ad1 Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 5 Apr 2023 21:22:50 +0100 Subject: [PATCH] Small change to make sure no duplicates ever occur. --- packages/server/src/sdk/users/utils.ts | 7 ++++++- packages/types/src/documents/app/user.ts | 1 + 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/server/src/sdk/users/utils.ts b/packages/server/src/sdk/users/utils.ts index a3982fd45b..7f7f0b4809 100644 --- a/packages/server/src/sdk/users/utils.ts +++ b/packages/server/src/sdk/users/utils.ts @@ -75,14 +75,19 @@ export async function syncGlobalUsers() { toWrite.push(combined) } } + let foundEmails: string[] = [] for (let data of metadata) { if (!data._id) { continue } + const alreadyExisting = data.email && foundEmails.indexOf(data.email) !== -1 const globalId = getGlobalIDFromUserMetadataID(data._id) - if (!users.find(user => user._id === globalId)) { + if (!users.find(user => user._id === globalId) || alreadyExisting) { toWrite.push({ ...data, _deleted: true }) } + if (data.email) { + foundEmails.push(data.email) + } } await db.bulkDocs(toWrite) } diff --git a/packages/types/src/documents/app/user.ts b/packages/types/src/documents/app/user.ts index b5f31ca349..4defd4a414 100644 --- a/packages/types/src/documents/app/user.ts +++ b/packages/types/src/documents/app/user.ts @@ -2,4 +2,5 @@ import { Document } from "../document" export interface UserMetadata extends Document { roleId: string + email?: string }