Merge pull request #2816 from Budibase/remove-global-info-users-on-deletion

Remove global info users on user deletion
This commit is contained in:
Rory Powell 2021-09-30 14:41:27 +01:00 committed by GitHub
commit 56fff164e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -19,6 +19,22 @@ const removeTenantFromInfoDB = async tenantId => {
} }
} }
exports.removeUserFromInfoDB = async dbUser => {
const infoDb = getDB(PLATFORM_INFO_DB)
const keys = [dbUser._id, dbUser.email]
const userDocs = await infoDb.allDocs({
keys,
include_docs: true,
})
const toDelete = userDocs.rows.map(row => {
return {
...row.doc,
_deleted: true,
}
})
await infoDb.bulkDocs(toDelete)
}
const removeUsersFromInfoDB = async tenantId => { const removeUsersFromInfoDB = async tenantId => {
try { try {
const globalDb = getGlobalDB(tenantId) const globalDb = getGlobalDB(tenantId)

View File

@ -19,6 +19,7 @@ const {
tryAddTenant, tryAddTenant,
updateTenantId, updateTenantId,
} = require("@budibase/auth/tenancy") } = require("@budibase/auth/tenancy")
const { removeUserFromInfoDB } = require("@budibase/auth/deprovision")
const env = require("../../../environment") const env = require("../../../environment")
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name
@ -193,6 +194,7 @@ exports.adminUser = async ctx => {
exports.destroy = async ctx => { exports.destroy = async ctx => {
const db = getGlobalDB() const db = getGlobalDB()
const dbUser = await db.get(ctx.params.id) const dbUser = await db.get(ctx.params.id)
await removeUserFromInfoDB(dbUser)
await db.remove(dbUser._id, dbUser._rev) await db.remove(dbUser._id, dbUser._rev)
await userCache.invalidateUser(dbUser._id) await userCache.invalidateUser(dbUser._id)
await invalidateSessions(dbUser._id) await invalidateSessions(dbUser._id)