diff --git a/packages/backend-core/src/events/publishers/group.ts b/packages/backend-core/src/events/publishers/group.ts index d300873725..b4fd0d1469 100644 --- a/packages/backend-core/src/events/publishers/group.ts +++ b/packages/backend-core/src/events/publishers/group.ts @@ -40,9 +40,9 @@ export async function usersAdded(count: number, group: UserGroup) { await publishEvent(Event.USER_GROUP_USERS_ADDED, properties) } -export async function usersDeleted(emails: string[], group: UserGroup) { +export async function usersDeleted(count: number, group: UserGroup) { const properties: GroupUsersDeletedEvent = { - count: emails.length, + count, groupId: group._id as string, } await publishEvent(Event.USER_GROUP_USERS_REMOVED, properties) diff --git a/packages/backend-core/src/users.ts b/packages/backend-core/src/users.ts index cf055df477..44f04749c9 100644 --- a/packages/backend-core/src/users.ts +++ b/packages/backend-core/src/users.ts @@ -6,7 +6,7 @@ import { } from "./db/utils" import { queryGlobalView } from "./db/views" import { UNICODE_MAX } from "./db/constants" -import { User } from "@budibase/types" +import { BulkDocsResponse, User } from "@budibase/types" import { getGlobalDB } from "./context" import PouchDB from "pouchdb" @@ -20,6 +20,11 @@ export const bulkGetGlobalUsersById = async (userIds: string[]) => { ).rows.map(row => row.doc) as User[] } +export const bulkUpdateGlobalUsers = async (users: User[]) => { + const db = getGlobalDB() as PouchDB.Database + return (await db.bulkDocs(users)) as BulkDocsResponse +} + /** * Given an email address this will use a view to search through * all the users to find one with this email address. diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index 9f110a492c..222dccea01 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -21,7 +21,6 @@ import { AllDocsResponse, BulkCreateUsersResponse, BulkDeleteUsersResponse, - BulkDocsResponse, CloudAccount, CreateUserResponse, InviteUsersRequest, @@ -391,7 +390,7 @@ export const bulkCreate = async ( }) const usersToBulkSave = await Promise.all(usersToSave) - await db.bulkDocs(usersToBulkSave) + await usersCore.bulkUpdateGlobalUsers(usersToBulkSave) // Post-processing of bulk added users, e.g. events and cache operations for (const user of usersToBulkSave) { @@ -469,13 +468,11 @@ export const bulkDelete = async ( ) // Delete from DB - const dbResponse: BulkDocsResponse = await db.bulkDocs( - usersToDelete.map(user => ({ - ...user, - _deleted: true, - })) - ) - + const toDelete = usersToDelete.map(user => ({ + ...user, + _deleted: true, + })) + const dbResponse = await usersCore.bulkUpdateGlobalUsers(toDelete) for (let user of usersToDelete) { await bulkDeleteProcessing(user) }