From 2f8d0ee60cd482caac44f53ae556f9fa8f392710 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Thu, 7 Apr 2022 15:23:32 +0200 Subject: [PATCH] ui: Better layout for root team --- src/lib/common.ts | 1 + src/routes/__layout.svelte | 2 +- src/routes/applications/index.svelte | 31 +++++- src/routes/dashboard.json.ts | 15 ++- src/routes/databases/index.svelte | 114 +++++++++++++++------ src/routes/destinations/index.svelte | 56 ++++++++--- src/routes/services/index.svelte | 144 +++++++++++++++++++-------- src/routes/settings/index.json.ts | 4 +- src/routes/settings/index.svelte | 7 +- src/routes/sources/index.svelte | 87 ++++++++++++---- src/routes/teams/index.json.ts | 2 +- src/routes/teams/index.svelte | 65 +++++++++--- 12 files changed, 396 insertions(+), 132 deletions(-) diff --git a/src/lib/common.ts b/src/lib/common.ts index 680e35208..4eec73539 100644 --- a/src/lib/common.ts +++ b/src/lib/common.ts @@ -100,6 +100,7 @@ export const getUserDetails = async (event, isAdminRequired = true) => { message: 'OK' } }; + if (isAdminRequired && permission !== 'admin' && permission !== 'owner') { payload.status = 401; payload.body.message = diff --git a/src/routes/__layout.svelte b/src/routes/__layout.svelte index 8d5922450..b6cb57435 100644 --- a/src/routes/__layout.svelte +++ b/src/routes/__layout.svelte @@ -12,7 +12,7 @@ if (!session.userId) { return {}; } - const endpoint = `/teams.json`; + const endpoint = `/dashboard.json`; const res = await fetch(endpoint); if (res.ok) { diff --git a/src/routes/applications/index.svelte b/src/routes/applications/index.svelte index 5f6056ac5..049bded43 100644 --- a/src/routes/applications/index.svelte +++ b/src/routes/applications/index.svelte @@ -8,6 +8,16 @@ const { id } = await post('/applications/new', {}); return await goto(`/applications/${id}`, { replaceState: true }); } + const ownApplications = applications.filter((application) => { + if (application.teams[0].id === $session.teamId) { + return application; + } + }); + const otherApplications = applications.filter((application) => { + if (application.teams[0].id !== $session.teamId) { + return application; + } + });
@@ -36,8 +46,23 @@
No applications found
{:else} - {#each applications as application} - - {/each} +
+ {#if $session.teamId === '0'} +
Your Team's Applications
+ {/if} +
+ {#each ownApplications as application} + + {/each} +
+ {#if otherApplications.length > 0 && $session.teamId === '0'} +
Other Team's Applications
+
+ {#each otherApplications as application} + + {/each} +
+ {/if} +
{/if} diff --git a/src/routes/dashboard.json.ts b/src/routes/dashboard.json.ts index 4c3ed3097..11ff9bab3 100644 --- a/src/routes/dashboard.json.ts +++ b/src/routes/dashboard.json.ts @@ -9,23 +9,28 @@ export const get: RequestHandler = async (event) => { try { const applicationsCount = await db.prisma.application.count({ - where: { teams: { some: { id: teamId } } } + where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } }); const sourcesCount = await db.prisma.gitSource.count({ - where: { teams: { some: { id: teamId } } } + where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } }); const destinationsCount = await db.prisma.destinationDocker.count({ - where: { teams: { some: { id: teamId } } } + where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } }); const teamsCount = await db.prisma.permission.count({ where: { userId } }); const databasesCount = await db.prisma.database.count({ - where: { teams: { some: { id: teamId } } } + where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } }); const servicesCount = await db.prisma.service.count({ - where: { teams: { some: { id: teamId } } } + where: { teams: { some: { id: teamId === '0' ? undefined : teamId } } } + }); + const teams = await db.prisma.permission.findMany({ + where: { userId }, + include: { team: { include: { _count: { select: { users: true } } } } } }); return { body: { + teams, applicationsCount, sourcesCount, destinationsCount, diff --git a/src/routes/databases/index.svelte b/src/routes/databases/index.svelte index 32156ef4b..26fc89d9c 100644 --- a/src/routes/databases/index.svelte +++ b/src/routes/databases/index.svelte @@ -14,6 +14,16 @@ const { id } = await post('/databases/new', {}); return await goto(`/databases/${id}`, { replaceState: true }); } + const ownDatabases = databases.filter((database) => { + if (database.teams[0].id === $session.teamId) { + return database; + } + }); + const otherDatabases = databases.filter((database) => { + if (database.teams[0].id !== $session.teamId) { + return database; + } + });
@@ -41,37 +51,81 @@
No databases found
{:else} - {#each databases as database} - -
- {#if database.type === 'clickhouse'} - - {:else if database.type === 'couchdb'} - - {:else if database.type === 'mongodb'} - - {:else if database.type === 'mysql'} - - {:else if database.type === 'postgresql'} - - {:else if database.type === 'redis'} - - {/if} -
- {database.name} -
- {#if $session.teamId === '0'} -
Team {database.teams[0].name}
- {/if} - {#if !database.type} -
diff --git a/src/routes/destinations/index.svelte b/src/routes/destinations/index.svelte index df186e35f..f78f8dc7a 100644 --- a/src/routes/destinations/index.svelte +++ b/src/routes/destinations/index.svelte @@ -24,6 +24,16 @@ import { session } from '$app/stores'; export let destinations: Prisma.DestinationDocker[]; + const ownDestinations = destinations.filter((destination) => { + if (destination.teams[0].id === $session.teamId) { + return destination; + } + }); + const otherDestinations = destinations.filter((destination) => { + if (destination.teams[0].id !== $session.teamId) { + return destination; + } + });
@@ -52,18 +62,40 @@
No destination found
{:else} -
- {#each destinations as destination} - -
-
{destination.name}
- {#if $session.teamId === '0'} -
Team {destination.teams[0].name}
- {/if} -
{destination.network}
-
-
- {/each} +
+ {#if $session.teamId === '0'} +
Your Team's Destinations
+ {/if} + + + {#if otherDestinations.length > 0 && $session.teamId === '0'} +
Other Team's Destinations
+ + {/if}
{/if}
diff --git a/src/routes/services/index.svelte b/src/routes/services/index.svelte index d590761a2..19f651d7e 100644 --- a/src/routes/services/index.svelte +++ b/src/routes/services/index.svelte @@ -19,6 +19,16 @@ const { id } = await post('/services/new', {}); return await goto(`/services/${id}`, { replaceState: true }); } + const ownServices = services.filter((service) => { + if (service.teams[0].id === $session.teamId) { + return service; + } + }); + const otherServices = services.filter((service) => { + if (service.teams[0].id !== $session.teamId) { + return service; + } + });
@@ -46,47 +56,101 @@
No services found
{:else} - {#each services as service} - -
- {#if service.type === 'plausibleanalytics'} - - {:else if service.type === 'nocodb'} - - {:else if service.type === 'minio'} - - {:else if service.type === 'vscodeserver'} - - {:else if service.type === 'wordpress'} - - {:else if service.type === 'vaultwarden'} - - {:else if service.type === 'languagetool'} - - {:else if service.type === 'n8n'} - - {:else if service.type === 'uptimekuma'} - - {:else if service.type === 'ghost'} - - {:else if service.type === 'meilisearch'} - - {/if} -
- {service.name} -
- {#if $session.teamId === '0'} -
Team {service.teams[0].name}
- {/if} - {#if !service.type || !service.fqdn} -
- Configuration missing +
+ {#if $session.teamId === '0'} +
Your Team's Applications
+ {/if} +
+ {#if otherServices.length > 0 && $session.teamId === '0'} +
Other Team's Applications
+ - - {/each} + {/if} +
{/if}
diff --git a/src/routes/settings/index.json.ts b/src/routes/settings/index.json.ts index db3dc0710..d126b2313 100644 --- a/src/routes/settings/index.json.ts +++ b/src/routes/settings/index.json.ts @@ -5,9 +5,9 @@ import type { RequestHandler } from '@sveltejs/kit'; import { promises as dns } from 'dns'; export const get: RequestHandler = async (event) => { - const { status, body } = await getUserDetails(event); + const { teamId, status, body } = await getUserDetails(event); if (status === 401) return { status, body }; - + if (teamId !== '0') return { status: 401, body: { message: 'You are not an admin.' } }; try { const settings = await listSettings(); return { diff --git a/src/routes/settings/index.svelte b/src/routes/settings/index.svelte index e6148a26f..0af8d534c 100644 --- a/src/routes/settings/index.svelte +++ b/src/routes/settings/index.svelte @@ -11,7 +11,12 @@ } }; } - + if (res.status === 401) { + return { + status: 302, + redirect: '/databases' + }; + } return { status: res.status, error: new Error(`Could not load ${url}`) diff --git a/src/routes/sources/index.svelte b/src/routes/sources/index.svelte index c57efdaa6..8fe0617dc 100644 --- a/src/routes/sources/index.svelte +++ b/src/routes/sources/index.svelte @@ -22,6 +22,16 @@
@@ -50,29 +60,62 @@
No git sources found
{:else} -
- {#each sources as source} - - diff --git a/src/routes/teams/index.json.ts b/src/routes/teams/index.json.ts index 702e20887..f382800ea 100644 --- a/src/routes/teams/index.json.ts +++ b/src/routes/teams/index.json.ts @@ -9,7 +9,7 @@ export const get: RequestHandler = async (event) => { try { const teams = await db.prisma.permission.findMany({ - where: { userId: teamId === '0' ? undefined : teamId }, + where: { userId: teamId === '0' ? undefined : userId }, include: { team: { include: { _count: { select: { users: true } } } } } }); diff --git a/src/routes/teams/index.svelte b/src/routes/teams/index.svelte index 05c020cdf..ee8269234 100644 --- a/src/routes/teams/index.svelte +++ b/src/routes/teams/index.svelte @@ -43,6 +43,16 @@ return errorNotification(error); } } + const ownTeams = teams.filter((team) => { + if (team.team.id === $session.teamId) { + return team; + } + }); + const otherTeams = teams.filter((team) => { + if (team.team.id !== $session.teamId) { + return team; + } + });
@@ -92,20 +102,45 @@
{/if}