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,16 +136,30 @@ 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 = {};
where: { id, teams: { some: { id: teamId } } }, if (teamId === '0') {
include: { body = await prisma.application.findFirst({
destinationDocker: true, where: { id },
settings: true, include: {
gitSource: { include: { githubApp: true, gitlabApp: true } }, destinationDocker: true,
secrets: true, settings: true,
persistentStorage: 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) { 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 = {};
where: { id, teams: { some: { id: teamId } } }, if (teamId === '0') {
include: { destinationDocker: true, settings: true } 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.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 = {};
where: { id, teams: { some: { id: teamId } } } if (teamId === '0') {
}); destination = await prisma.destinationDocker.findFirst({
if (destination.remoteEngine) { where: { id }
destination.sshPrivateKey = decrypt(destination.sshPrivateKey); });
} else {
destination = await prisma.destinationDocker.findFirst({
where: { id, teams: { some: { id: teamId } } }
});
} }
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 = {};
where: { id, teams: { some: { id: teamId } } }, if (teamId === '0') {
include: { githubApp: true, gitlabApp: true } 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) 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,19 +20,28 @@ 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, vscodeserver: true,
vscodeserver: true, wordpress: true,
wordpress: true, 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,41 +184,19 @@
value={destination.network} value={destination.network}
/> />
</div> </div>
<div class="grid grid-cols-2 items-center"> {#if $session.teamId === '0'}
<Setting <div class="grid grid-cols-2 items-center">
disabled={cannotDisable} <Setting
bind:setting={destination.isCoolifyProxyUsed} disabled={cannotDisable}
on:click={changeProxySetting} bind:setting={destination.isCoolifyProxyUsed}
title="Use Coolify Proxy?" on:click={changeProxySetting}
description={`This will install a proxy on the destination to allow you to access your applications and services without any manual configuration. Databases will have their own proxy. <br><br>${ title="Use Coolify Proxy?"
cannotDisable description={`This will install a proxy on the destination to allow you to access your applications and services without any manual configuration. Databases will have their own proxy. <br><br>${
? '<span class="font-bold text-white">You cannot disable this proxy as FQDN is configured for Coolify.</span>' cannotDisable
: '' ? '<span class="font-bold text-white">You cannot disable this proxy as FQDN is configured for Coolify.</span>'
}`} : ''
/> }`}
</div> />
</form> </div>
<!-- <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} {/if}
</div> --> </form>
<!-- {#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,93 +91,95 @@
</script> </script>
{#if !source.gitlabApp?.appId} {#if !source.gitlabApp?.appId}
<form class="grid grid-flow-row gap-2 py-4" on:submit|preventDefault={newApp}> <div>
<div class="grid grid-cols-2 items-center"> <form class="grid grid-flow-row gap-2 py-4" on:submit|preventDefault={newApp}>
<label for="type">GitLab Application Type</label>
<select name="type" id="type" class="w-96" bind:value={payload.applicationType}>
<option value="user">User owned application</option>
<option value="group">Group owned application</option>
{#if source.htmlUrl !== 'https://gitlab.com'}
<option value="instance">Instance-wide application (self-hosted)</option>
{/if}
</select>
</div>
{#if payload.applicationType === 'group'}
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="groupName">Group Name</label> <label for="type">GitLab Application Type</label>
<input name="groupName" id="groupName" required bind:value={payload.groupName} /> <select name="type" id="type" class="w-96" bind:value={payload.applicationType}>
<option value="user">User owned application</option>
<option value="group">Group owned application</option>
{#if source.htmlUrl !== 'https://gitlab.com'}
<option value="instance">Instance-wide application (self-hosted)</option>
{/if}
</select>
</div> </div>
{/if} {#if payload.applicationType === 'group'}
<div class="grid grid-cols-2 items-center">
<label for="groupName">Group Name</label>
<input name="groupName" id="groupName" required bind:value={payload.groupName} />
</div>
{/if}
<div class="w-full pt-10 text-center"> <div class="w-full pt-10 text-center">
<button class="w-96 bg-orange-600 hover:bg-orange-500" type="submit" <button class="w-96 bg-orange-600 hover:bg-orange-500" type="submit"
>Register new OAuth application on GitLab</button >Register new OAuth application on GitLab</button
> >
</div> </div>
<Explainer <Explainer
customClass="w-full" customClass="w-full"
text="<span class='font-bold text-base text-white'>Scopes required:</span> text="<span class='font-bold text-base text-white'>Scopes required:</span>
<br>- <span class='text-orange-500 font-bold'>api</span> (Access the authenticated user's API) <br>- <span class='text-orange-500 font-bold'>api</span> (Access the authenticated user's API)
<br>- <span class='text-orange-500 font-bold'>read_repository</span> (Allows read-only access to the repository) <br>- <span class='text-orange-500 font-bold'>read_repository</span> (Allows read-only access to the repository)
<br>- <span class='text-orange-500 font-bold'>email</span> (Allows read-only access to the user's primary email address using OpenID Connect) <br>- <span class='text-orange-500 font-bold'>email</span> (Allows read-only access to the user's primary email address using OpenID Connect)
<br> <br>
<br>For extra security, you can set Expire access tokens! <br>For extra security, you can set Expire access tokens!
<br><br>Webhook URL: <span class='text-orange-500 font-bold'>{browser <br><br>Webhook URL: <span class='text-orange-500 font-bold'>{browser
? window.location.origin ? window.location.origin
: ''}/webhooks/gitlab</span> : ''}/webhooks/gitlab</span>
<br>But if you will set a custom domain name for Coolify, use that instead." <br>But if you will set a custom domain name for Coolify, use that instead."
/> />
</form> </form>
<form on:submit|preventDefault={handleSubmit} class="grid grid-flow-row gap-2 py-4 pt-10"> <form on:submit|preventDefault={handleSubmit} class="grid grid-flow-row gap-2 py-4 pt-10">
<div class="flex h-8 items-center space-x-2"> <div class="flex h-8 items-center space-x-2">
<div class="text-xl font-bold text-white">Configuration</div> <div class="text-xl font-bold text-white">Configuration</div>
<button <button
type="submit" type="submit"
class:bg-orange-600={!loading} class:bg-orange-600={!loading}
class:hover:bg-orange-500={!loading} class:hover:bg-orange-500={!loading}
disabled={loading}>{loading ? 'Saving...' : 'Save'}</button disabled={loading}>{loading ? 'Saving...' : 'Save'}</button
> >
</div> </div>
<div class="grid grid-cols-2 items-start"> <div class="grid grid-cols-2 items-start">
<div class="flex-col"> <div class="flex-col">
<label for="oauthId" class="pt-2">OAuth ID</label> <label for="oauthId" class="pt-2">OAuth ID</label>
<Explainer <Explainer
text="The OAuth ID is the unique identifier of the GitLab application. <br>You can find it <span class='font-bold text-orange-600' >in the URL</span> of your GitLab OAuth Application." text="The OAuth ID is the unique identifier of the GitLab application. <br>You can find it <span class='font-bold text-orange-600' >in the URL</span> of your GitLab OAuth Application."
/>
</div>
<input
on:change={checkOauthId}
bind:this={oauthIdEl}
name="oauthId"
id="oauthId"
type="number"
required
bind:value={payload.oauthId}
/> />
</div> </div>
<input {#if payload.applicationType === 'group'}
on:change={checkOauthId} <div class="grid grid-cols-2 items-center">
bind:this={oauthIdEl} <label for="groupName">Group Name</label>
name="oauthId" <input name="groupName" id="groupName" required bind:value={payload.groupName} />
id="oauthId" </div>
type="number" {/if}
required
bind:value={payload.oauthId}
/>
</div>
{#if payload.applicationType === 'group'}
<div class="grid grid-cols-2 items-center"> <div class="grid grid-cols-2 items-center">
<label for="groupName">Group Name</label> <label for="appId">Application ID</label>
<input name="groupName" id="groupName" required bind:value={payload.groupName} /> <input name="appId" id="appId" required bind:value={payload.appId} />
</div> </div>
{/if} <div class="grid grid-cols-2 items-center">
<div class="grid grid-cols-2 items-center"> <label for="appSecret">Secret</label>
<label for="appId">Application ID</label> <input
<input name="appId" id="appId" required bind:value={payload.appId} /> name="appSecret"
</div> id="appSecret"
<div class="grid grid-cols-2 items-center"> type="password"
<label for="appSecret">Secret</label> required
<input bind:value={payload.appSecret}
name="appSecret" />
id="appSecret" </div>
type="password" </form>
required </div>
bind:value={payload.appSecret}
/>
</div>
</form>
{: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