From d034800c76cdac40d350f41bc3e8a53cb5c3f56c Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 2 Nov 2022 09:58:38 +0000 Subject: [PATCH 1/3] Email onboarding not respecting group selection --- packages/frontend-core/src/api/user.js | 2 +- packages/worker/src/sdk/users/users.ts | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/api/user.js b/packages/frontend-core/src/api/user.js index 39d9359e91..5c4f070802 100644 --- a/packages/frontend-core/src/api/user.js +++ b/packages/frontend-core/src/api/user.js @@ -158,7 +158,7 @@ export const buildUserEndpoints = API => ({ userInfo: { admin: user.admin ? { global: true } : undefined, builder: user.admin || user.builder ? { global: true } : undefined, - groups: user.groups, + userGroups: user.groups, }, })), }) diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index 775514ea5e..8afd398d91 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -184,7 +184,9 @@ export const save = async ( ): Promise => { const tenantId = tenancy.getTenantId() const db = tenancy.getGlobalDB() - let { email, _id } = user + + let { email, _id, userGroups = [] } = user + if (!email && !_id) { throw new Error("_id or email is required") } @@ -220,8 +222,16 @@ export const save = async ( let builtUser = await buildUser(user, opts, tenantId, dbUser) // make sure we set the _id field for a new user + // Also if this is a new user, associate groups with them + let groupPromises = [] if (!_id) { _id = builtUser._id! + + if (userGroups.length > 0) { + for (let groupId of userGroups) { + groupPromises.push(groupsSdk.addUsers(groupId, [_id])) + } + } } try { @@ -235,6 +245,8 @@ export const save = async ( // let server know to sync user await apps.syncUserInApps(_id) + await Promise.all(groupPromises) + return { _id: response.id, _rev: response.rev, @@ -557,12 +569,13 @@ export const invite = async ( successful: [], unsuccessful: [], } - + console.log(users) const matchedEmails = await searchExistingEmails(users.map(u => u.email)) const newUsers = [] // separate duplicates from new users for (let user of users) { + console.log(user) if (matchedEmails.includes(user.email)) { response.unsuccessful.push({ email: user.email, reason: "Unavailable" }) } else { From d1f9b8048c3070186191ad372a3fe4daeef47ca5 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 2 Nov 2022 10:35:04 +0000 Subject: [PATCH 2/3] remove log --- packages/worker/src/sdk/users/users.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index 8afd398d91..f47a5216d6 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -569,13 +569,12 @@ export const invite = async ( successful: [], unsuccessful: [], } - console.log(users) + const matchedEmails = await searchExistingEmails(users.map(u => u.email)) const newUsers = [] // separate duplicates from new users for (let user of users) { - console.log(user) if (matchedEmails.includes(user.email)) { response.unsuccessful.push({ email: user.email, reason: "Unavailable" }) } else { From df72037eaceb8613f434cf7754869fe2f7f164fd Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 2 Nov 2022 12:15:03 +0000 Subject: [PATCH 3/3] fix issue with datepicker --- packages/bbui/src/Form/Core/DatePicker.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bbui/src/Form/Core/DatePicker.svelte b/packages/bbui/src/Form/Core/DatePicker.svelte index 9e7d44dbc3..379f41b284 100644 --- a/packages/bbui/src/Form/Core/DatePicker.svelte +++ b/packages/bbui/src/Form/Core/DatePicker.svelte @@ -41,7 +41,7 @@ time_24hr: time24hr || false, altFormat: timeOnly ? "H:i" : enableTime ? "F j Y, H:i" : "F j, Y", wrap: true, - mode: range ? "range" : null, + mode: range ? "range" : "single", appendTo, disableMobile: "true", onReady: () => {