Adding group management to background user/group sync.

This commit is contained in:
Michael Drury 2023-04-05 20:51:47 +01:00
parent 0803b08217
commit 70c9d06832
1 changed files with 8 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import {
roles, roles,
} from "@budibase/backend-core" } from "@budibase/backend-core"
import { User, ContextUser } from "@budibase/types" import { User, ContextUser } from "@budibase/types"
import { sdk as proSdk } from "@budibase/pro"
import sdk from "../../" import sdk from "../../"
import { getGlobalUsers, updateAppRole } from "../../../utilities/global" import { getGlobalUsers, updateAppRole } from "../../../utilities/global"
import { generateUserMetadataID, InternalTables } from "../../../db/utils" import { generateUserMetadataID, InternalTables } from "../../../db/utils"
@ -107,10 +108,15 @@ export function initUserGroupSync() {
docUpdates.process(types, async update => { docUpdates.process(types, async update => {
const docId = update.id const docId = update.id
const isGroup = docId.startsWith(constants.DocumentType.GROUP) const isGroup = docId.startsWith(constants.DocumentType.GROUP)
let userIds: string[]
if (isGroup) { 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 { } else {
await syncUsersToAllApps([docId]) userIds = [docId]
}
if (userIds.length > 0) {
await syncUsersToAllApps(userIds)
} }
}) })
} }