Clearing out per-app builders when app is deleted.

This commit is contained in:
mike12345567 2023-11-23 17:35:55 +00:00
parent 7984ecde05
commit b6c6e6ec6e
2 changed files with 17 additions and 5 deletions

View File

@ -146,12 +146,12 @@ export class UserDB {
static async allUsers() {
const db = getGlobalDB()
const response = await db.allDocs(
const response = await db.allDocs<User>(
dbUtils.getGlobalUserParams(null, {
include_docs: true,
})
)
return response.rows.map((row: any) => row.doc)
return response.rows.map(row => row.doc!)
}
static async countUsersByApp(appId: string) {

View File

@ -51,10 +51,22 @@ export async function removeAppRole(ctx: Ctx) {
const users = await sdk.users.db.allUsers()
const bulk = []
const cacheInvalidations = []
const prodAppId = dbCore.getProdAppID(appId)
for (let user of users) {
if (user.roles[appId]) {
cacheInvalidations.push(cache.user.invalidateUser(user._id))
delete user.roles[appId]
let updated = false
if (user.roles[prodAppId]) {
cacheInvalidations.push(cache.user.invalidateUser(user._id!))
delete user.roles[prodAppId]
updated = true
}
if (user.builder && Array.isArray(user.builder?.apps)) {
const idx = user.builder.apps.indexOf(prodAppId)
if (idx !== -1) {
user.builder.apps.splice(idx, 1)
updated = true
}
}
if (updated) {
bulk.push(user)
}
}