From 8405ebd28d27b8497320c29ddec229520e618b73 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Wed, 6 Apr 2022 15:55:17 +0200 Subject: [PATCH] feat: Admin team sees everything --- src/lib/database/applications.ts | 42 +++-- src/lib/database/databases.ts | 25 ++- src/lib/database/destinations.ts | 23 ++- src/lib/database/gitSources.ts | 23 ++- src/lib/database/services.ts | 44 ++++-- src/routes/applications/_Application.svelte | 1 + src/routes/databases/index.svelte | 1 + .../destinations/[id]/_LocalDocker.svelte | 52 ++----- src/routes/destinations/[id]/index.json.ts | 2 +- src/routes/destinations/index.svelte | 1 + src/routes/services/index.svelte | 1 + src/routes/sources/[id]/_Gitlab.svelte | 144 +++++++++--------- src/routes/sources/index.svelte | 1 + 13 files changed, 210 insertions(+), 150 deletions(-) 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}
{application.name}
+
Team {application.teams[0].name}
{#if application.fqdn}
{application.fqdn}
{/if} diff --git a/src/routes/databases/index.svelte b/src/routes/databases/index.svelte index f6834cd0b..6caa4d90e 100644 --- a/src/routes/databases/index.svelte +++ b/src/routes/databases/index.svelte @@ -59,6 +59,7 @@
{database.name}
+
Team {database.teams[0].name}
{#if !database.type}
Configuration missing diff --git a/src/routes/destinations/[id]/_LocalDocker.svelte b/src/routes/destinations/[id]/_LocalDocker.svelte index 329d23c2f..1ed6d3b99 100644 --- a/src/routes/destinations/[id]/_LocalDocker.svelte +++ b/src/routes/destinations/[id]/_LocalDocker.svelte @@ -184,41 +184,19 @@ value={destination.network} />
-
-
${ - cannotDisable - ? 'You cannot disable this proxy as FQDN is configured for Coolify.' - : '' - }`} - /> -
- - - - + diff --git a/src/routes/destinations/[id]/index.json.ts b/src/routes/destinations/[id]/index.json.ts index e88c29825..d64df8c08 100644 --- a/src/routes/destinations/[id]/index.json.ts +++ b/src/routes/destinations/[id]/index.json.ts @@ -8,7 +8,7 @@ import type { RequestHandler } from '@sveltejs/kit'; export const get: RequestHandler = async (event) => { const { teamId, status, body } = await getUserDetails(event); if (status === 401) return { status, body }; - + console.log(teamId); const { id } = event.params; try { const destination = await db.getDestination({ id, teamId }); diff --git a/src/routes/destinations/index.svelte b/src/routes/destinations/index.svelte index 01f860b21..a7b6b9a7e 100644 --- a/src/routes/destinations/index.svelte +++ b/src/routes/destinations/index.svelte @@ -57,6 +57,7 @@
{destination.name}
+
Team {destination.teams[0].name}
{destination.network}
diff --git a/src/routes/services/index.svelte b/src/routes/services/index.svelte index 4cba9a702..f2a6e5fb0 100644 --- a/src/routes/services/index.svelte +++ b/src/routes/services/index.svelte @@ -74,6 +74,7 @@
{service.name}
+
Team {service.teams[0].name}
{#if !service.type || !service.fqdn}
Configuration missing diff --git a/src/routes/sources/[id]/_Gitlab.svelte b/src/routes/sources/[id]/_Gitlab.svelte index 56bb0288d..7823aebe9 100644 --- a/src/routes/sources/[id]/_Gitlab.svelte +++ b/src/routes/sources/[id]/_Gitlab.svelte @@ -91,93 +91,95 @@ {#if !source.gitlabApp?.appId} -
-
- - -
- {#if payload.applicationType === 'group'} +
+
- - + +
- {/if} + {#if payload.applicationType === 'group'} +
+ + +
+ {/if} -
- -
+
+ +
- - -
-
-
Configuration
- -
+ /> +
+
+
+
Configuration
+ +
-
-
- - +
+ + +
+
- -
- {#if payload.applicationType === 'group'} + {#if payload.applicationType === 'group'} +
+ + +
+ {/if}
- - + +
- {/if} -
- - -
-
- - -
-
+
+ + +
+ +
{:else}
diff --git a/src/routes/sources/index.svelte b/src/routes/sources/index.svelte index bd9039514..d80579272 100644 --- a/src/routes/sources/index.svelte +++ b/src/routes/sources/index.svelte @@ -60,6 +60,7 @@ class:border-l-4={source.gitlabApp && !source.gitlabAppId} >
{source.name}
+
Team {source.teams[0].name}
{#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)}
Configuration missing