PR comments.

This commit is contained in:
mike12345567 2025-03-04 17:56:46 +00:00
parent 45843e328d
commit a7c7a94760
3 changed files with 15 additions and 16 deletions

View File

@ -222,9 +222,12 @@ export class DatabaseImpl implements Database {
} }
async getMultiple<T extends Document>( async getMultiple<T extends Document>(
ids: string[], ids?: string[],
opts?: { allowMissing?: boolean; excludeDocs?: boolean } opts?: { allowMissing?: boolean; excludeDocs?: boolean }
): Promise<T[]> { ): Promise<T[]> {
if (!ids || ids.length === 0) {
return []
}
// get unique // get unique
ids = [...new Set(ids)] ids = [...new Set(ids)]
const includeDocs = !opts?.excludeDocs const includeDocs = !opts?.excludeDocs

View File

@ -16,30 +16,26 @@ export const hasAdminPermissions = sdk.users.hasAdminPermissions
export const hasBuilderPermissions = sdk.users.hasBuilderPermissions export const hasBuilderPermissions = sdk.users.hasBuilderPermissions
export const hasAppBuilderPermissions = sdk.users.hasAppBuilderPermissions export const hasAppBuilderPermissions = sdk.users.hasAppBuilderPermissions
async function getGroups(groupIds?: string[]) {
if (groupIds?.length) {
const db = context.getGlobalDB()
return await db.getMultiple<UserGroup>(groupIds, { allowMissing: true })
}
return []
}
export async function creatorsInList( export async function creatorsInList(
users: (User | ContextUser)[], users: (User | ContextUser)[],
groups?: UserGroup[] groups?: UserGroup[]
) { ) {
if (!groups) { const groupIds = [
const groupIds = users.flatMap(user => user.userGroups || []) ...new Set(
users.filter(user => user.userGroups).flatMap(user => user.userGroups!)
),
]
if (groupIds.length) { if (groupIds.length) {
groups = await getGroups(groupIds) const db = context.getGlobalDB()
} groups = await db.getMultiple<UserGroup>(groupIds)
} }
return users.map(user => isCreatorSync(user, groups)) return users.map(user => isCreatorSync(user, groups))
} }
// fetches groups if no provided, but is async and shouldn't be looped with // fetches groups if no provided, but is async and shouldn't be looped with
export async function isCreatorAsync(user: User | ContextUser) { export async function isCreatorAsync(user: User | ContextUser) {
const groups = await getGroups(user.userGroups) const db = context.getGlobalDB()
const groups = await db.getMultiple<UserGroup>(user.userGroups)
return isCreatorSync(user, groups) return isCreatorSync(user, groups)
} }

View File

@ -136,7 +136,7 @@ export interface Database {
get<T extends Document>(id?: string): Promise<T> get<T extends Document>(id?: string): Promise<T>
tryGet<T extends Document>(id?: string): Promise<T | undefined> tryGet<T extends Document>(id?: string): Promise<T | undefined>
getMultiple<T extends Document>( getMultiple<T extends Document>(
ids: string[], ids?: string[],
opts?: { allowMissing?: boolean; excludeDocs?: boolean } opts?: { allowMissing?: boolean; excludeDocs?: boolean }
): Promise<T[]> ): Promise<T[]>
remove(idOrDoc: Document): Promise<Nano.DocumentDestroyResponse> remove(idOrDoc: Document): Promise<Nano.DocumentDestroyResponse>