diff --git a/packages/backend-core/src/db/utils.ts b/packages/backend-core/src/db/utils.ts index 8a50efbca9..8ab6fa6e98 100644 --- a/packages/backend-core/src/db/utils.ts +++ b/packages/backend-core/src/db/utils.ts @@ -124,6 +124,10 @@ export function generateTemplateID(ownerId: any) { return `${DocumentTypes.TEMPLATE}${SEPARATOR}${ownerId}${SEPARATOR}${newid()}` } +export function generateAppUserID(prodAppId: string, userId: string) { + return `${prodAppId}${SEPARATOR}${userId}` +} + /** * Gets parameters for retrieving templates. Owner ID must be specified, either global or a workspace level. */ diff --git a/packages/backend-core/src/users.js b/packages/backend-core/src/users.js index ad42443910..34d546a8bb 100644 --- a/packages/backend-core/src/users.js +++ b/packages/backend-core/src/users.js @@ -1,6 +1,11 @@ -const { ViewNames, getUsersByAppParams, getProdAppID } = require("./db/utils") +const { + ViewNames, + getUsersByAppParams, + getProdAppID, + generateAppUserID, +} = require("./db/utils") const { queryGlobalView } = require("./db/views") -const { UNICODE_MAX, SEPARATOR } = require("./db/constants") +const { UNICODE_MAX } = require("./db/constants") /** * Given an email address this will use a view to search through @@ -38,7 +43,7 @@ exports.getGlobalUserByAppPage = (appId, user) => { if (!user) { return } - return `${getProdAppID(appId)}${SEPARATOR}${user._id}` + return generateAppUserID(getProdAppID(appId), user._id) } /** diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index b908c2f88e..1cb140c15a 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -100,6 +100,7 @@ export const buildUser = async ( opts: SaveUserOpts = { hashPassword: true, requirePassword: true, + bulkCreate: false, }, tenantId: string, dbUser?: any @@ -297,7 +298,6 @@ export const bulkCreate = async (newUsersRequested: any[], groups: any) => { delete user.password await eventHelpers.handleSaveEvents(user, null) await apps.syncUserInApps(user._id) - await addTenant(tenantId, user._id, user.email) } return usersToBulkSave