diff --git a/src/lib/database/applications.ts b/src/lib/database/applications.ts index 1d8140144..1c6e172c2 100644 --- a/src/lib/database/applications.ts +++ b/src/lib/database/applications.ts @@ -5,7 +5,13 @@ import { getDomain, removeDestinationDocker } from '$lib/common'; import { prisma } from './common'; export async function listApplications(teamId) { - return await prisma.application.findMany({ where: { teams: { some: { id: teamId } } } }); + if (teamId === '0') { + return await prisma.application.findMany({ include: { teams: true } }); + } + return await prisma.application.findMany({ + where: { teams: { some: { id: teamId } } }, + include: { teams: true } + }); } export async function newApplication({ name, teamId }) { @@ -130,16 +136,30 @@ export async function getApplicationById({ id }) { return { ...body }; } export async function getApplication({ id, teamId }) { - let body = await prisma.application.findFirst({ - where: { id, teams: { some: { id: teamId } } }, - include: { - destinationDocker: true, - settings: true, - gitSource: { include: { githubApp: true, gitlabApp: true } }, - secrets: true, - persistentStorage: true - } - }); + let body = {}; + if (teamId === '0') { + body = await prisma.application.findFirst({ + where: { id }, + include: { + destinationDocker: true, + settings: true, + gitSource: { include: { githubApp: true, gitlabApp: true } }, + secrets: true, + persistentStorage: true + } + }); + } else { + body = await prisma.application.findFirst({ + where: { id, teams: { some: { id: teamId } } }, + include: { + destinationDocker: true, + settings: true, + gitSource: { include: { githubApp: true, gitlabApp: true } }, + secrets: true, + persistentStorage: true + } + }); + } if (body?.gitSource?.githubApp?.clientSecret) { body.gitSource.githubApp.clientSecret = decrypt(body.gitSource.githubApp.clientSecret); diff --git a/src/lib/database/databases.ts b/src/lib/database/databases.ts index be5ddacd3..7fc237944 100644 --- a/src/lib/database/databases.ts +++ b/src/lib/database/databases.ts @@ -7,7 +7,14 @@ import getPort, { portNumbers } from 'get-port'; import { asyncExecShell, getEngine, removeContainer } from '$lib/common'; export async function listDatabases(teamId) { - return await prisma.database.findMany({ where: { teams: { some: { id: teamId } } } }); + if (teamId === '0') { + return await prisma.database.findMany({ include: { teams: true } }); + } else { + return await prisma.database.findMany({ + where: { teams: { some: { id: teamId } } }, + include: { teams: true } + }); + } } export async function newDatabase({ name, teamId }) { const dbUser = cuid(); @@ -31,10 +38,18 @@ export async function newDatabase({ name, teamId }) { } export async function getDatabase({ id, teamId }) { - const body = await prisma.database.findFirst({ - where: { id, teams: { some: { id: teamId } } }, - include: { destinationDocker: true, settings: true } - }); + let body = {}; + if (teamId === '0') { + body = await prisma.database.findFirst({ + where: { id }, + include: { destinationDocker: true, settings: true } + }); + } else { + body = await prisma.database.findFirst({ + where: { id, teams: { some: { id: teamId } } }, + include: { destinationDocker: true, settings: true } + }); + } if (body.dbUserPassword) body.dbUserPassword = decrypt(body.dbUserPassword); if (body.rootUserPassword) body.rootUserPassword = decrypt(body.rootUserPassword); diff --git a/src/lib/database/destinations.ts b/src/lib/database/destinations.ts index 3f3aadec5..5bd63c81b 100644 --- a/src/lib/database/destinations.ts +++ b/src/lib/database/destinations.ts @@ -6,7 +6,13 @@ import { getDatabaseImage } from '.'; import { prisma } from './common'; export async function listDestinations(teamId) { - return await prisma.destinationDocker.findMany({ where: { teams: { some: { id: teamId } } } }); + if (teamId === '0') { + return await prisma.destinationDocker.findMany({ include: { teams: true } }); + } + return await prisma.destinationDocker.findMany({ + where: { teams: { some: { id: teamId } } }, + include: { teams: true } + }); } export async function configureDestinationForService({ id, destinationId }) { @@ -124,12 +130,17 @@ export async function removeDestination({ id }) { } export async function getDestination({ id, teamId }) { - let destination = await prisma.destinationDocker.findFirst({ - where: { id, teams: { some: { id: teamId } } } - }); - if (destination.remoteEngine) { - destination.sshPrivateKey = decrypt(destination.sshPrivateKey); + let destination = {}; + if (teamId === '0') { + destination = await prisma.destinationDocker.findFirst({ + where: { id } + }); + } else { + destination = await prisma.destinationDocker.findFirst({ + where: { id, teams: { some: { id: teamId } } } + }); } + return destination; } export async function getDestinationByApplicationId({ id, teamId }) { diff --git a/src/lib/database/gitSources.ts b/src/lib/database/gitSources.ts index 927907964..7e4e90633 100644 --- a/src/lib/database/gitSources.ts +++ b/src/lib/database/gitSources.ts @@ -2,9 +2,14 @@ import { decrypt, encrypt } from '$lib/crypto'; import { prisma } from './common'; export async function listSources(teamId) { + if (teamId === '0') { + return await prisma.gitSource.findMany({ + include: { githubApp: true, gitlabApp: true, teams: true } + }); + } return await prisma.gitSource.findMany({ where: { teams: { some: { id: teamId } } }, - include: { githubApp: true, gitlabApp: true } + include: { githubApp: true, gitlabApp: true, teams: true } }); } @@ -31,10 +36,18 @@ export async function removeSource({ id }) { } export async function getSource({ id, teamId }) { - let body = await prisma.gitSource.findFirst({ - where: { id, teams: { some: { id: teamId } } }, - include: { githubApp: true, gitlabApp: true } - }); + let body = {}; + if (teamId === '0') { + body = await prisma.gitSource.findFirst({ + where: { id }, + include: { githubApp: true, gitlabApp: true } + }); + } else { + body = await prisma.gitSource.findFirst({ + where: { id, teams: { some: { id: teamId } } }, + include: { githubApp: true, gitlabApp: true } + }); + } if (body?.githubApp?.clientSecret) body.githubApp.clientSecret = decrypt(body.githubApp.clientSecret); if (body?.githubApp?.webhookSecret) diff --git a/src/lib/database/services.ts b/src/lib/database/services.ts index bc25b9327..d578a500c 100644 --- a/src/lib/database/services.ts +++ b/src/lib/database/services.ts @@ -5,7 +5,14 @@ import { generatePassword } from '.'; import { prisma } from './common'; export async function listServices(teamId) { - return await prisma.service.findMany({ where: { teams: { some: { id: teamId } } } }); + if (teamId === '0') { + return await prisma.service.findMany({ include: { teams: true } }); + } else { + return await prisma.service.findMany({ + where: { teams: { some: { id: teamId } } }, + include: { teams: true } + }); + } } export async function newService({ name, teamId }) { @@ -13,19 +20,28 @@ export async function newService({ name, teamId }) { } export async function getService({ id, teamId }) { - const body = await prisma.service.findFirst({ - where: { id, teams: { some: { id: teamId } } }, - include: { - destinationDocker: true, - plausibleAnalytics: true, - minio: true, - vscodeserver: true, - wordpress: true, - ghost: true, - serviceSecret: true, - meiliSearch: true - } - }); + let body = {}; + const include = { + destinationDocker: true, + plausibleAnalytics: true, + minio: true, + vscodeserver: true, + wordpress: true, + ghost: true, + serviceSecret: true, + meiliSearch: true + }; + if (teamId === '0') { + body = await prisma.service.findFirst({ + where: { id }, + include + }); + } else { + body = await prisma.service.findFirst({ + where: { id, teams: { some: { id: teamId } } }, + include + }); + } if (body.plausibleAnalytics?.postgresqlPassword) body.plausibleAnalytics.postgresqlPassword = decrypt( diff --git a/src/routes/applications/_Application.svelte b/src/routes/applications/_Application.svelte index 16d19a42f..fb6a157c7 100644 --- a/src/routes/applications/_Application.svelte +++ b/src/routes/applications/_Application.svelte @@ -54,6 +54,7 @@ {/if}