Adding group cleanup, removing group IDs from users when group is deleted.
This commit is contained in:
parent
e22f4ab7d7
commit
9466592663
|
@ -7,6 +7,18 @@ import {
|
|||
import { queryGlobalView } from "./db/views"
|
||||
import { UNICODE_MAX } from "./db/constants"
|
||||
import { User } from "@budibase/types"
|
||||
import { getGlobalDB } from "./context"
|
||||
import PouchDB from "pouchdb"
|
||||
|
||||
export const bulkGetGlobalUsersById = async (userIds: string[]) => {
|
||||
const db = getGlobalDB() as PouchDB.Database
|
||||
return (
|
||||
await db.allDocs({
|
||||
keys: userIds,
|
||||
include_docs: true,
|
||||
})
|
||||
).rows.map(row => row.doc) as User[]
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an email address this will use a view to search through
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
importUsersModal
|
||||
let searchEmail = undefined
|
||||
let selectedRows = []
|
||||
let bulkSaveResponse
|
||||
let customRenderers = [
|
||||
{ column: "userGroups", component: GroupsTableRenderer },
|
||||
{ column: "apps", component: AppsTableRenderer },
|
||||
|
@ -166,10 +167,11 @@
|
|||
|
||||
async function createUsers() {
|
||||
try {
|
||||
await users.create(await removingDuplicities(userData))
|
||||
bulkSaveResponse = await users.create(await removingDuplicities(userData))
|
||||
notifications.success("Successfully created user")
|
||||
await groups.actions.init()
|
||||
passwordModal.show()
|
||||
await fetch.refresh()
|
||||
} catch (error) {
|
||||
notifications.error("Error creating user")
|
||||
}
|
||||
|
@ -177,7 +179,7 @@
|
|||
|
||||
async function chooseCreationType(onboardingType) {
|
||||
if (onboardingType === "emailOnboarding") {
|
||||
createUserFlow()
|
||||
await createUserFlow()
|
||||
} else {
|
||||
await createUsers()
|
||||
}
|
||||
|
@ -292,7 +294,10 @@
|
|||
</Modal>
|
||||
|
||||
<Modal bind:this={passwordModal}>
|
||||
<PasswordModal userData={userData.users} />
|
||||
<PasswordModal
|
||||
createUsersResponse={bulkSaveResponse}
|
||||
userData={userData.users}
|
||||
/>
|
||||
</Modal>
|
||||
|
||||
<Modal bind:this={importUsersModal}>
|
||||
|
|
|
@ -55,12 +55,6 @@ export function createGroupsStore() {
|
|||
return
|
||||
}
|
||||
|
||||
// Update group
|
||||
await actions.save({
|
||||
...group,
|
||||
users: [...group.users, { _id: userId, email: user.email }],
|
||||
})
|
||||
|
||||
// Update user
|
||||
let userGroups = user.userGroups || []
|
||||
userGroups.push(groupId)
|
||||
|
@ -78,12 +72,6 @@ export function createGroupsStore() {
|
|||
return
|
||||
}
|
||||
|
||||
// Update group
|
||||
await actions.save({
|
||||
...group,
|
||||
users: group.users.filter(x => x._id !== userId),
|
||||
})
|
||||
|
||||
// Update user
|
||||
await users.save({
|
||||
...user,
|
||||
|
|
|
@ -393,7 +393,7 @@ export const bulkCreate = async (
|
|||
const usersToBulkSave = await Promise.all(usersToSave)
|
||||
await db.bulkDocs(usersToBulkSave)
|
||||
|
||||
// Post processing of bulk added users, i.e events and cache operations
|
||||
// Post-processing of bulk added users, e.g. events and cache operations
|
||||
for (const user of usersToBulkSave) {
|
||||
// TODO: Refactor to bulk insert users into the info db
|
||||
// instead of relying on looping tenant creation
|
||||
|
|
Loading…
Reference in New Issue