Populate apps from groups while fetching apps

This commit is contained in:
Adria Navarro 2023-09-18 17:58:07 +02:00
parent 539fdd1d6d
commit 3f7b615d10
1 changed files with 10 additions and 4 deletions

View File

@ -1,13 +1,14 @@
import { AppStatus } from "../../../db/utils" import { AppStatus } from "../../../db/utils"
import { App, ContextUser } from "@budibase/types" import { App, ContextUser, User } from "@budibase/types"
import { getLocksById } from "../../../utilities/redis" import { getLocksById } from "../../../utilities/redis"
import { enrichApps } from "../../users/sessions" import { enrichApps } from "../../users/sessions"
import { checkAppMetadata } from "../../../automations/logging" import { checkAppMetadata } from "../../../automations/logging"
import { db as dbCore, users } from "@budibase/backend-core" import { db as dbCore, users } from "@budibase/backend-core"
import { groups } from "@budibase/pro"
export function filterAppList(user: ContextUser, apps: App[]) { export function filterAppList(user: User, apps: App[]) {
let appList: string[] = [] let appList: string[] = []
const roleApps = Object.keys(user.roles || {}) const roleApps = Object.keys(user.roles)
if (users.hasAppBuilderPermissions(user)) { if (users.hasAppBuilderPermissions(user)) {
appList = user.builder?.apps || [] appList = user.builder?.apps || []
appList = appList.concat(roleApps) appList = appList.concat(roleApps)
@ -23,7 +24,12 @@ export async function fetch(status: AppStatus, user: ContextUser) {
const dev = status === AppStatus.DEV const dev = status === AppStatus.DEV
const all = status === AppStatus.ALL const all = status === AppStatus.ALL
let apps = (await dbCore.getAllApps({ dev, all })) as App[] let apps = (await dbCore.getAllApps({ dev, all })) as App[]
apps = filterAppList(user, apps)
const enrichedUser = await groups.enrichUserRolesFromGroups({
...user,
roles: user.roles || {},
})
apps = filterAppList(enrichedUser, apps)
const appIds = apps const appIds = apps
.filter((app: any) => app.status === "development") .filter((app: any) => app.status === "development")