1
0
Fork 0
mirror of synced 2024-06-30 20:10:54 +12:00

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() { static async allUsers() {
const db = getGlobalDB() const db = getGlobalDB()
const response = await db.allDocs( const response = await db.allDocs<User>(
dbUtils.getGlobalUserParams(null, { dbUtils.getGlobalUserParams(null, {
include_docs: true, include_docs: true,
}) })
) )
return response.rows.map((row: any) => row.doc) return response.rows.map(row => row.doc!)
} }
static async countUsersByApp(appId: string) { 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 users = await sdk.users.db.allUsers()
const bulk = [] const bulk = []
const cacheInvalidations = [] const cacheInvalidations = []
const prodAppId = dbCore.getProdAppID(appId)
for (let user of users) { for (let user of users) {
if (user.roles[appId]) { let updated = false
cacheInvalidations.push(cache.user.invalidateUser(user._id)) if (user.roles[prodAppId]) {
delete user.roles[appId] 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) bulk.push(user)
} }
} }