1
0
Fork 0
mirror of synced 2024-06-23 08:30:31 +12:00

Removing un-necessary code now that groups automatically enrich from users.

This commit is contained in:
mike12345567 2022-09-20 19:33:54 +01:00
parent 49fc65b584
commit e22f4ab7d7
2 changed files with 1 additions and 57 deletions

View file

@ -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) {

View file

@ -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<User> = await db.allDocs({
include_docs: true,
@ -466,19 +464,6 @@ export const bulkDelete = async (
})
const usersToDelete: User[] = allDocsResponse.rows.map(
(user: RowResponse<User>) => {
// 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" })