feat: Admin team sees everything

This commit is contained in:
Andras Bacsai 2022-04-06 15:55:17 +02:00
parent 352bb65125
commit 8405ebd28d
13 changed files with 210 additions and 150 deletions

View File

@ -5,7 +5,13 @@ import { getDomain, removeDestinationDocker } from '$lib/common';
import { prisma } from './common'; import { prisma } from './common';
export async function listApplications(teamId) { 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 }) { export async function newApplication({ name, teamId }) {
@ -130,7 +136,20 @@ export async function getApplicationById({ id }) {
return { ...body }; return { ...body };
} }
export async function getApplication({ id, teamId }) { export async function getApplication({ id, teamId }) {
let body = await prisma.application.findFirst({ 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 } } }, where: { id, teams: { some: { id: teamId } } },
include: { include: {
destinationDocker: true, destinationDocker: true,
@ -140,6 +159,7 @@ export async function getApplication({ id, teamId }) {
persistentStorage: true persistentStorage: true
} }
}); });
}
if (body?.gitSource?.githubApp?.clientSecret) { if (body?.gitSource?.githubApp?.clientSecret) {
body.gitSource.githubApp.clientSecret = decrypt(body.gitSource.githubApp.clientSecret); body.gitSource.githubApp.clientSecret = decrypt(body.gitSource.githubApp.clientSecret);

View File

@ -7,7 +7,14 @@ import getPort, { portNumbers } from 'get-port';
import { asyncExecShell, getEngine, removeContainer } from '$lib/common'; import { asyncExecShell, getEngine, removeContainer } from '$lib/common';
export async function listDatabases(teamId) { 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 }) { export async function newDatabase({ name, teamId }) {
const dbUser = cuid(); const dbUser = cuid();
@ -31,10 +38,18 @@ export async function newDatabase({ name, teamId }) {
} }
export async function getDatabase({ id, teamId }) { export async function getDatabase({ id, teamId }) {
const body = await prisma.database.findFirst({ 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 } } }, where: { id, teams: { some: { id: teamId } } },
include: { destinationDocker: true, settings: true } include: { destinationDocker: true, settings: true }
}); });
}
if (body.dbUserPassword) body.dbUserPassword = decrypt(body.dbUserPassword); if (body.dbUserPassword) body.dbUserPassword = decrypt(body.dbUserPassword);
if (body.rootUserPassword) body.rootUserPassword = decrypt(body.rootUserPassword); if (body.rootUserPassword) body.rootUserPassword = decrypt(body.rootUserPassword);

View File

@ -6,7 +6,13 @@ import { getDatabaseImage } from '.';
import { prisma } from './common'; import { prisma } from './common';
export async function listDestinations(teamId) { 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 }) { export async function configureDestinationForService({ id, destinationId }) {
@ -124,12 +130,17 @@ export async function removeDestination({ id }) {
} }
export async function getDestination({ id, teamId }) { export async function getDestination({ id, teamId }) {
let destination = await prisma.destinationDocker.findFirst({ let destination = {};
if (teamId === '0') {
destination = await prisma.destinationDocker.findFirst({
where: { id }
});
} else {
destination = await prisma.destinationDocker.findFirst({
where: { id, teams: { some: { id: teamId } } } where: { id, teams: { some: { id: teamId } } }
}); });
if (destination.remoteEngine) {
destination.sshPrivateKey = decrypt(destination.sshPrivateKey);
} }
return destination; return destination;
} }
export async function getDestinationByApplicationId({ id, teamId }) { export async function getDestinationByApplicationId({ id, teamId }) {

View File

@ -2,9 +2,14 @@ import { decrypt, encrypt } from '$lib/crypto';
import { prisma } from './common'; import { prisma } from './common';
export async function listSources(teamId) { 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({ return await prisma.gitSource.findMany({
where: { teams: { some: { id: teamId } } }, 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 }) { export async function getSource({ id, teamId }) {
let body = await prisma.gitSource.findFirst({ 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 } } }, where: { id, teams: { some: { id: teamId } } },
include: { githubApp: true, gitlabApp: true } include: { githubApp: true, gitlabApp: true }
}); });
}
if (body?.githubApp?.clientSecret) if (body?.githubApp?.clientSecret)
body.githubApp.clientSecret = decrypt(body.githubApp.clientSecret); body.githubApp.clientSecret = decrypt(body.githubApp.clientSecret);
if (body?.githubApp?.webhookSecret) if (body?.githubApp?.webhookSecret)

View File

@ -5,7 +5,14 @@ import { generatePassword } from '.';
import { prisma } from './common'; import { prisma } from './common';
export async function listServices(teamId) { 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 }) { export async function newService({ name, teamId }) {
@ -13,9 +20,8 @@ export async function newService({ name, teamId }) {
} }
export async function getService({ id, teamId }) { export async function getService({ id, teamId }) {
const body = await prisma.service.findFirst({ let body = {};
where: { id, teams: { some: { id: teamId } } }, const include = {
include: {
destinationDocker: true, destinationDocker: true,
plausibleAnalytics: true, plausibleAnalytics: true,
minio: true, minio: true,
@ -24,8 +30,18 @@ export async function getService({ id, teamId }) {
ghost: true, ghost: true,
serviceSecret: true, serviceSecret: true,
meiliSearch: 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) if (body.plausibleAnalytics?.postgresqlPassword)
body.plausibleAnalytics.postgresqlPassword = decrypt( body.plausibleAnalytics.postgresqlPassword = decrypt(

View File

@ -54,6 +54,7 @@
{/if} {/if}
<div class="truncate text-center text-xl font-bold">{application.name}</div> <div class="truncate text-center text-xl font-bold">{application.name}</div>
<div class="truncate text-center">Team {application.teams[0].name}</div>
{#if application.fqdn} {#if application.fqdn}
<div class="truncate text-center">{application.fqdn}</div> <div class="truncate text-center">{application.fqdn}</div>
{/if} {/if}

View File

@ -59,6 +59,7 @@
<div class="font-bold text-xl text-center truncate"> <div class="font-bold text-xl text-center truncate">
{database.name} {database.name}
</div> </div>
<div class="text-center truncate">Team {database.teams[0].name}</div>
{#if !database.type} {#if !database.type}
<div class="font-bold text-center truncate text-red-500 group-hover:text-white"> <div class="font-bold text-center truncate text-red-500 group-hover:text-white">
Configuration missing Configuration missing

View File

@ -184,6 +184,7 @@
value={destination.network} value={destination.network}
/> />
</div> </div>
{#if $session.teamId === '0'}
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<Setting <Setting
disabled={cannotDisable} disabled={cannotDisable}
@ -197,28 +198,5 @@
}`} }`}
/> />
</div> </div>
{/if}
</form> </form>
<!-- <div class="flex justify-center">
{#if payload.isCoolifyProxyUsed}
{#if state}
<button on:click={stopProxy}>Stop proxy</button>
{:else}
<button on:click={startProxy}>Start proxy</button>
{/if}
{/if}
</div> -->
<!-- {#if scannedApps.length > 0}
<div class="flex justify-center px-6 pb-10">
<div class="flex space-x-2 h-8 items-center">
<div class="font-bold text-xl text-white">Found applications</div>
</div>
</div>
<div class="max-w-4xl mx-auto px-6">
<div class="flex space-x-2 justify-center">
{#each scannedApps as app}
<FoundApp {app} />
{/each}
</div>
</div>
{/if} -->

View File

@ -8,7 +8,7 @@ import type { RequestHandler } from '@sveltejs/kit';
export const get: RequestHandler = async (event) => { export const get: RequestHandler = async (event) => {
const { teamId, status, body } = await getUserDetails(event); const { teamId, status, body } = await getUserDetails(event);
if (status === 401) return { status, body }; if (status === 401) return { status, body };
console.log(teamId);
const { id } = event.params; const { id } = event.params;
try { try {
const destination = await db.getDestination({ id, teamId }); const destination = await db.getDestination({ id, teamId });

View File

@ -57,6 +57,7 @@
<a href="/destinations/{destination.id}" class="no-underline p-2 w-96"> <a href="/destinations/{destination.id}" class="no-underline p-2 w-96">
<div class="box-selection hover:bg-sky-600"> <div class="box-selection hover:bg-sky-600">
<div class="font-bold text-xl text-center truncate">{destination.name}</div> <div class="font-bold text-xl text-center truncate">{destination.name}</div>
<div class="text-center truncate">Team {destination.teams[0].name}</div>
<div class="text-center truncate">{destination.network}</div> <div class="text-center truncate">{destination.network}</div>
</div> </div>
</a> </a>

View File

@ -74,6 +74,7 @@
<div class="font-bold text-xl text-center truncate"> <div class="font-bold text-xl text-center truncate">
{service.name} {service.name}
</div> </div>
<div class="text-center truncate">Team {service.teams[0].name}</div>
{#if !service.type || !service.fqdn} {#if !service.type || !service.fqdn}
<div class="font-bold text-center truncate text-red-500 group-hover:text-white"> <div class="font-bold text-center truncate text-red-500 group-hover:text-white">
Configuration missing Configuration missing

View File

@ -91,6 +91,7 @@
</script> </script>
{#if !source.gitlabApp?.appId} {#if !source.gitlabApp?.appId}
<div>
<form class="grid grid-flow-row gap-2 py-4" on:submit|preventDefault={newApp}> <form class="grid grid-flow-row gap-2 py-4" on:submit|preventDefault={newApp}>
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="type">GitLab Application Type</label> <label for="type">GitLab Application Type</label>
@ -178,6 +179,7 @@
/> />
</div> </div>
</form> </form>
</div>
{:else} {:else}
<div class="mx-auto max-w-4xl px-6"> <div class="mx-auto max-w-4xl px-6">
<form on:submit|preventDefault={handleSubmitSave} class="py-4"> <form on:submit|preventDefault={handleSubmitSave} class="py-4">

View File

@ -60,6 +60,7 @@
class:border-l-4={source.gitlabApp && !source.gitlabAppId} class:border-l-4={source.gitlabApp && !source.gitlabAppId}
> >
<div class="font-bold text-xl text-center truncate">{source.name}</div> <div class="font-bold text-xl text-center truncate">{source.name}</div>
<div class="text-center truncate">Team {source.teams[0].name}</div>
{#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)} {#if (source.type === 'gitlab' && !source.gitlabAppId) || (source.type === 'github' && !source.githubAppId && !source.githubApp?.installationId)}
<div class="font-bold text-center truncate text-red-500 group-hover:text-white"> <div class="font-bold text-center truncate text-red-500 group-hover:text-white">
Configuration missing Configuration missing