From 70c9d06832b63fcff55a8ccdbaa9a3432efca30f Mon Sep 17 00:00:00 2001 From: Michael Drury Date: Wed, 5 Apr 2023 20:51:47 +0100 Subject: [PATCH] Adding group management to background user/group sync. --- packages/server/src/sdk/app/applications/sync.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/packages/server/src/sdk/app/applications/sync.ts b/packages/server/src/sdk/app/applications/sync.ts index 3572e047e6..ce59740f2a 100644 --- a/packages/server/src/sdk/app/applications/sync.ts +++ b/packages/server/src/sdk/app/applications/sync.ts @@ -8,6 +8,7 @@ import { roles, } from "@budibase/backend-core" import { User, ContextUser } from "@budibase/types" +import { sdk as proSdk } from "@budibase/pro" import sdk from "../../" import { getGlobalUsers, updateAppRole } from "../../../utilities/global" import { generateUserMetadataID, InternalTables } from "../../../db/utils" @@ -107,10 +108,15 @@ export function initUserGroupSync() { docUpdates.process(types, async update => { const docId = update.id const isGroup = docId.startsWith(constants.DocumentType.GROUP) + let userIds: string[] if (isGroup) { - // TODO: get the group, get users in the group then run the function + const group = await proSdk.groups.get(docId) + userIds = group.users?.map(user => user._id) || [] } else { - await syncUsersToAllApps([docId]) + userIds = [docId] + } + if (userIds.length > 0) { + await syncUsersToAllApps(userIds) } }) }