Browse Source
Merge pull request #2816 from Budibase/remove-global-info-users-on-deletion
Remove global info users on user deletion
gh-pages
Rory Powell
5 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with
18 additions and
0 deletions
-
packages/auth/src/tenancy/deprovision.js
-
packages/worker/src/api/controllers/global/users.js
|
|
|
@ -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 => { |
|
|
|
try { |
|
|
|
const globalDb = getGlobalDB(tenantId) |
|
|
|
|
|
|
|
@ -19,6 +19,7 @@ const { |
|
|
|
tryAddTenant, |
|
|
|
updateTenantId, |
|
|
|
} = require("@budibase/auth/tenancy") |
|
|
|
const { removeUserFromInfoDB } = require("@budibase/auth/deprovision") |
|
|
|
const env = require("../../../environment") |
|
|
|
|
|
|
|
const PLATFORM_INFO_DB = StaticDatabases.PLATFORM_INFO.name |
|
|
|
@ -193,6 +194,7 @@ exports.adminUser = async ctx => { |
|
|
|
exports.destroy = async ctx => { |
|
|
|
const db = getGlobalDB() |
|
|
|
const dbUser = await db.get(ctx.params.id) |
|
|
|
await removeUserFromInfoDB(dbUser) |
|
|
|
await db.remove(dbUser._id, dbUser._rev) |
|
|
|
await userCache.invalidateUser(dbUser._id) |
|
|
|
await invalidateSessions(dbUser._id) |
|
|
|
|