Adding group cleanup, removing group IDs from users when group is deleted.

This commit is contained in:
mike12345567 2022-09-21 12:43:09 +01:00
parent e22f4ab7d7
commit 9466592663
4 changed files with 21 additions and 16 deletions

View File

@ -7,6 +7,18 @@ import {
import { queryGlobalView } from "./db/views" import { queryGlobalView } from "./db/views"
import { UNICODE_MAX } from "./db/constants" import { UNICODE_MAX } from "./db/constants"
import { User } from "@budibase/types" 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 * Given an email address this will use a view to search through

View File

@ -44,6 +44,7 @@
importUsersModal importUsersModal
let searchEmail = undefined let searchEmail = undefined
let selectedRows = [] let selectedRows = []
let bulkSaveResponse
let customRenderers = [ let customRenderers = [
{ column: "userGroups", component: GroupsTableRenderer }, { column: "userGroups", component: GroupsTableRenderer },
{ column: "apps", component: AppsTableRenderer }, { column: "apps", component: AppsTableRenderer },
@ -166,10 +167,11 @@
async function createUsers() { async function createUsers() {
try { try {
await users.create(await removingDuplicities(userData)) bulkSaveResponse = await users.create(await removingDuplicities(userData))
notifications.success("Successfully created user") notifications.success("Successfully created user")
await groups.actions.init() await groups.actions.init()
passwordModal.show() passwordModal.show()
await fetch.refresh()
} catch (error) { } catch (error) {
notifications.error("Error creating user") notifications.error("Error creating user")
} }
@ -177,7 +179,7 @@
async function chooseCreationType(onboardingType) { async function chooseCreationType(onboardingType) {
if (onboardingType === "emailOnboarding") { if (onboardingType === "emailOnboarding") {
createUserFlow() await createUserFlow()
} else { } else {
await createUsers() await createUsers()
} }
@ -292,7 +294,10 @@
</Modal> </Modal>
<Modal bind:this={passwordModal}> <Modal bind:this={passwordModal}>
<PasswordModal userData={userData.users} /> <PasswordModal
createUsersResponse={bulkSaveResponse}
userData={userData.users}
/>
</Modal> </Modal>
<Modal bind:this={importUsersModal}> <Modal bind:this={importUsersModal}>

View File

@ -55,12 +55,6 @@ export function createGroupsStore() {
return return
} }
// Update group
await actions.save({
...group,
users: [...group.users, { _id: userId, email: user.email }],
})
// Update user // Update user
let userGroups = user.userGroups || [] let userGroups = user.userGroups || []
userGroups.push(groupId) userGroups.push(groupId)
@ -78,12 +72,6 @@ export function createGroupsStore() {
return return
} }
// Update group
await actions.save({
...group,
users: group.users.filter(x => x._id !== userId),
})
// Update user // Update user
await users.save({ await users.save({
...user, ...user,

View File

@ -393,7 +393,7 @@ export const bulkCreate = async (
const usersToBulkSave = await Promise.all(usersToSave) const usersToBulkSave = await Promise.all(usersToSave)
await db.bulkDocs(usersToBulkSave) 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) { for (const user of usersToBulkSave) {
// TODO: Refactor to bulk insert users into the info db // TODO: Refactor to bulk insert users into the info db
// instead of relying on looping tenant creation // instead of relying on looping tenant creation