From e22f4ab7d71f232729dbfbec7f923ccb05177039 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Tue, 20 Sep 2022 19:33:54 +0100 Subject: [PATCH] Removing un-necessary code now that groups automatically enrich from users. --- .../src/api/controllers/global/users.ts | 36 +------------------ packages/worker/src/sdk/users/users.ts | 22 ------------ 2 files changed, 1 insertion(+), 57 deletions(-) diff --git a/packages/worker/src/api/controllers/global/users.ts b/packages/worker/src/api/controllers/global/users.ts index c065933d89..639aab5794 100644 --- a/packages/worker/src/api/controllers/global/users.ts +++ b/packages/worker/src/api/controllers/global/users.ts @@ -7,8 +7,6 @@ import { InviteUserRequest, InviteUsersRequest, User, - GroupUser, - UserGroup, } from "@budibase/types" import { accounts, @@ -18,7 +16,6 @@ import { tenancy, } from "@budibase/backend-core" import { checkAnyUserExists } from "../../../utilities/users" -import { groups as groupUtils } from "@budibase/pro" const MAX_USERS_UPLOAD_LIMIT = 1000 @@ -40,21 +37,8 @@ export const bulkCreate = async (ctx: any) => { ) } - const db = tenancy.getGlobalDB() - let groupsToSave: any[] = [] - - if (groups.length) { - for (const groupId of groups) { - let oldGroup = await db.get(groupId) - groupsToSave.push(oldGroup) - } - } - try { - const response = await users.bulkCreate(newUsersRequested, groups) - await groupUtils.bulkSaveGroupUsers(groupsToSave, response.successful) - - ctx.body = response + ctx.body = await users.bulkCreate(newUsersRequested, groups) } catch (err: any) { ctx.throw(err.status || 400, err) } @@ -233,24 +217,6 @@ export const inviteAccept = async (ctx: any) => { const db = tenancy.getGlobalDB() const user = await db.get(saved._id) await events.user.inviteAccepted(user) - - // add user to groups if required - if (info.groups?.length) { - let groups: UserGroup[] = [] - for (const groupId of info.groups) { - try { - let group: UserGroup = await db.get(groupId) - if (group) { - groups.push(group) - } - } catch (error) { - // group was probably deleted - } - } - const groupUser: GroupUser = { _id: saved._id, email: saved.email } - await groupUtils.bulkSaveGroupUsers(groups, [groupUser]) - } - return saved }) } catch (err: any) { diff --git a/packages/worker/src/sdk/users/users.ts b/packages/worker/src/sdk/users/users.ts index 4e030f5e61..d7556044c0 100644 --- a/packages/worker/src/sdk/users/users.ts +++ b/packages/worker/src/sdk/users/users.ts @@ -31,7 +31,6 @@ import { RowResponse, User, } from "@budibase/types" -import { groups as groupUtils } from "@budibase/pro" import { sendEmail } from "../../utilities/email" import { EmailTemplatePurpose } from "../../constants" @@ -458,7 +457,6 @@ export const bulkDelete = async ( }) } - let groupsToModify: any = {} // Get users and delete const allDocsResponse: AllDocsResponse = await db.allDocs({ include_docs: true, @@ -466,19 +464,6 @@ export const bulkDelete = async ( }) const usersToDelete: User[] = allDocsResponse.rows.map( (user: RowResponse) => { - // if we find a user that has an associated group, add it to - // an array so we can easily use allDocs on them later. - // This prevents us having to re-loop over all the users - if (user.doc.userGroups) { - for (let groupId of user.doc.userGroups) { - if (!Object.keys(groupsToModify).includes(groupId)) { - groupsToModify[groupId] = [user.id] - } else { - groupsToModify[groupId] = [...groupsToModify[groupId], user.id] - } - } - } - return user.doc } ) @@ -491,8 +476,6 @@ export const bulkDelete = async ( })) ) - // Deletion post processing - await groupUtils.bulkDeleteGroupUsers(groupsToModify) for (let user of usersToDelete) { await bulkDeleteProcessing(user) } @@ -526,7 +509,6 @@ export const destroy = async (id: string, currentUser: any) => { const db = tenancy.getGlobalDB() const dbUser = await db.get(id) const userId = dbUser._id as string - let groups = dbUser.userGroups if (!env.SELF_HOSTED && !env.DISABLE_ACCOUNT_PORTAL) { // root account holder can't be deleted from inside budibase @@ -545,10 +527,6 @@ export const destroy = async (id: string, currentUser: any) => { await db.remove(userId, dbUser._rev) - if (groups) { - await groupUtils.deleteGroupUsers(groups, dbUser) - } - await eventHelpers.handleDeleteEvents(dbUser) await cache.user.invalidateUser(userId) await sessions.invalidateSessions(userId, { reason: "deletion" })