Merge branch 'creator-changes' of github.com:Budibase/budibase into creator-changes

This commit is contained in:
Andrew Kingston 2023-11-23 17:49:18 +00:00
commit 5c39ac2d1d
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)
} }
} }