From e5b505b0039129e9f27c30cd55283c950cebecf3 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 26 Jul 2022 12:26:45 +0000 Subject: [PATCH] ui: settings --- .github/ISSUE_TEMPLATE/config.yml | 2 +- .gitpod.yml | 2 + .../20220726121333_fix_ssh_key/migration.sql | 16 + apps/api/prisma/schema.prisma | 3 + apps/api/src/lib/common.ts | 2 +- .../src/routes/api/v1/settings/handlers.ts | 6 +- apps/ui/src/lib/store.ts | 1 - apps/ui/src/routes/__layout.svelte | 54 +- apps/ui/src/routes/destinations/index.svelte | 3 + apps/ui/src/routes/settings/_Menu.svelte | 21 + apps/ui/src/routes/settings/__layout.svelte | 23 + apps/ui/src/routes/settings/global.svelte | 302 +++++++++++ apps/ui/src/routes/settings/index.svelte | 478 +----------------- apps/ui/src/routes/settings/ssh-keys.svelte | 150 ++++++ 14 files changed, 556 insertions(+), 507 deletions(-) create mode 100644 apps/api/prisma/migrations/20220726121333_fix_ssh_key/migration.sql create mode 100644 apps/ui/src/routes/settings/_Menu.svelte create mode 100644 apps/ui/src/routes/settings/__layout.svelte create mode 100644 apps/ui/src/routes/settings/global.svelte create mode 100644 apps/ui/src/routes/settings/ssh-keys.svelte diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml index 326d434b3..3338ead6a 100644 --- a/.github/ISSUE_TEMPLATE/config.yml +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -3,6 +3,6 @@ contact_links: - name: 🤔 Questions and Help url: https://discord.com/invite/6rDM4fkymF about: Reach out to us on discord or our github discussions page. - - name: 🙋‍♂️ service request + - name: 🙋‍♂️ Service request url: https://feedback.coolify.io/ about: want to request a new service? for e.g wordpress, hasura, appwrite etc... diff --git a/.gitpod.yml b/.gitpod.yml index 3af3611be..d46244e67 100644 --- a/.gitpod.yml +++ b/.gitpod.yml @@ -9,3 +9,5 @@ tasks: ports: - port: 3001 visibility: public + - port: 3000 + visibility: public diff --git a/apps/api/prisma/migrations/20220726121333_fix_ssh_key/migration.sql b/apps/api/prisma/migrations/20220726121333_fix_ssh_key/migration.sql new file mode 100644 index 000000000..e6e47b197 --- /dev/null +++ b/apps/api/prisma/migrations/20220726121333_fix_ssh_key/migration.sql @@ -0,0 +1,16 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_SshKey" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "privateKey" TEXT NOT NULL, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "teamId" TEXT, + CONSTRAINT "SshKey_teamId_fkey" FOREIGN KEY ("teamId") REFERENCES "Team" ("id") ON DELETE SET NULL ON UPDATE CASCADE +); +INSERT INTO "new_SshKey" ("createdAt", "id", "name", "privateKey", "updatedAt") SELECT "createdAt", "id", "name", "privateKey", "updatedAt" FROM "SshKey"; +DROP TABLE "SshKey"; +ALTER TABLE "new_SshKey" RENAME TO "SshKey"; +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/apps/api/prisma/schema.prisma b/apps/api/prisma/schema.prisma index a3b6effc4..5ec5dc683 100644 --- a/apps/api/prisma/schema.prisma +++ b/apps/api/prisma/schema.prisma @@ -66,6 +66,7 @@ model Team { databaseId String? service Service[] @relation(references: [id]) serviceId String? + SshKey SshKey[] } model TeamInvitation { @@ -227,6 +228,8 @@ model SshKey { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt destinationDocker DestinationDocker[] + team Team? @relation(fields: [teamId], references: [id]) + teamId String? } model GitSource { diff --git a/apps/api/src/lib/common.ts b/apps/api/src/lib/common.ts index 59f121a54..10a0fa162 100644 --- a/apps/api/src/lib/common.ts +++ b/apps/api/src/lib/common.ts @@ -323,7 +323,7 @@ export async function isDomainConfigured({ id: string; fqdn: string; checkOwn?: boolean; - dockerId: string; + dockerId?: string; }): Promise { console.log({ checkOwn, dockerId }) diff --git a/apps/api/src/routes/api/v1/settings/handlers.ts b/apps/api/src/routes/api/v1/settings/handlers.ts index 2a2fabeaa..073dbd7e3 100644 --- a/apps/api/src/routes/api/v1/settings/handlers.ts +++ b/apps/api/src/routes/api/v1/settings/handlers.ts @@ -7,8 +7,9 @@ import { CheckDNS, CheckDomain, DeleteDomain, DeleteSSHKey, SaveSettings, SaveSS export async function listAllSettings(request: FastifyRequest) { try { + const teamId = request.user.teamId; const settings = await listSettings(); - const sshKeys = await prisma.sshKey.findMany() + const sshKeys = await prisma.sshKey.findMany({ where: { team: { id: teamId } } }) const unencryptedKeys = [] if (sshKeys.length > 0) { for (const key of sshKeys) { @@ -96,6 +97,7 @@ export async function checkDNS(request: FastifyRequest) { export async function saveSSHKey(request: FastifyRequest, reply: FastifyReply) { try { + const teamId = request.user.teamId; const { privateKey, name } = request.body; const found = await prisma.sshKey.findMany({ where: { name } }) if (found.length > 0) { @@ -104,7 +106,7 @@ export async function saveSSHKey(request: FastifyRequest, reply: Fas } } const encryptedSSHKey = encrypt(privateKey) - await prisma.sshKey.create({ data: { name, privateKey: encryptedSSHKey } }) + await prisma.sshKey.create({ data: { name, privateKey: encryptedSSHKey, team: { connect: { id: teamId } } } }) return reply.code(201).send() } catch ({ status, message }) { return errorHandler({ status, message }) diff --git a/apps/ui/src/lib/store.ts b/apps/ui/src/lib/store.ts index 8b7a8d830..627885385 100644 --- a/apps/ui/src/lib/store.ts +++ b/apps/ui/src/lib/store.ts @@ -35,7 +35,6 @@ export const appSession: Writable = writable({ gitlab: null } }); -export const isTraefikUsed: Writable = writable(false); export const disabledButton: Writable = writable(false); export const status: Writable = writable({ application: { diff --git a/apps/ui/src/routes/__layout.svelte b/apps/ui/src/routes/__layout.svelte index d25437d2c..0dc363d94 100644 --- a/apps/ui/src/routes/__layout.svelte +++ b/apps/ui/src/routes/__layout.svelte @@ -86,15 +86,13 @@ import UpdateAvailable from '$lib/components/UpdateAvailable.svelte'; import PageLoader from '$lib/components/PageLoader.svelte'; import { errorNotification } from '$lib/common'; - import { appSession, isTraefikUsed } from '$lib/store'; + import { appSession } from '$lib/store'; if (userId) $appSession.userId = userId; if (teamId) $appSession.teamId = teamId; if (permission) $appSession.permission = permission; if (isAdmin) $appSession.isAdmin = isAdmin; - $isTraefikUsed = settings?.isTraefikUsed || false; - async function logout() { try { Cookies.remove('token'); @@ -324,33 +322,31 @@ - {#if $appSession.teamId === '0'} - + - - - - - - - {/if} + + + + +
Not verified yet
{/if} + {#if destination.remoteEngine && !destination.sshKeyId} +
SSH Key missing!
+ {/if} {/each} diff --git a/apps/ui/src/routes/settings/_Menu.svelte b/apps/ui/src/routes/settings/_Menu.svelte new file mode 100644 index 000000000..ad03a81af --- /dev/null +++ b/apps/ui/src/routes/settings/_Menu.svelte @@ -0,0 +1,21 @@ + + +
+ {#if $appSession.teamId === '0'} + + Global Settings + + {/if} + SSH Keys +
diff --git a/apps/ui/src/routes/settings/__layout.svelte b/apps/ui/src/routes/settings/__layout.svelte new file mode 100644 index 000000000..0fc272517 --- /dev/null +++ b/apps/ui/src/routes/settings/__layout.svelte @@ -0,0 +1,23 @@ + + + + diff --git a/apps/ui/src/routes/settings/global.svelte b/apps/ui/src/routes/settings/global.svelte new file mode 100644 index 000000000..20fdee5bd --- /dev/null +++ b/apps/ui/src/routes/settings/global.svelte @@ -0,0 +1,302 @@ + + + + +
+
{$t('index.settings')}
+
+
+
+ +
+
+
+
{$t('index.global_settings')}
+ + + {#if isFqdnSet} + + {/if} +
+
+ +
+
+
+ {$t('application.url_fqdn')} +
+ +
+
+ + + {#if forceSave} +
+ {#if isNonWWWDomainOK} + + {:else} + + {/if} + {#if dualCerts} + {#if isWWWDomainOK} + + {:else} + + {/if} + {/if} +
+ {/if} +
+
+
+
+
+ {$t('forms.public_port_range')} +
+ +
+
+ + - + +
+
+
+ changeSettings('isDNSCheckEnabled')} + /> +
+
+ !isFqdnSet && changeSettings('dualCerts')} + /> +
+
+ changeSettings('isRegistrationEnabled')} + /> +
+ {#if browser && $features.beta} +
+ changeSettings('isAutoUpdateEnabled')} + /> +
+ {/if} +
+
+
+
+
diff --git a/apps/ui/src/routes/settings/index.svelte b/apps/ui/src/routes/settings/index.svelte index d4fdf42ef..e63251299 100644 --- a/apps/ui/src/routes/settings/index.svelte +++ b/apps/ui/src/routes/settings/index.svelte @@ -1,476 +1,8 @@ - - - -
-
{$t('index.settings')}
-
-
-
-
- - -
-
- {#if $appSession.teamId === '0'} - {#if subMenuActive === 'globalsettings'} -
-
-
{$t('index.global_settings')}
- - - {#if isFqdnSet} - - {/if} -
-
- -
-
-
- {$t('application.url_fqdn')} -
- -
-
- - - {#if forceSave} -
- {#if isNonWWWDomainOK} - - {:else} - - {/if} - {#if dualCerts} - {#if isWWWDomainOK} - - {:else} - - {/if} - {/if} -
- {/if} -
-
-
-
-
- {$t('forms.public_port_range')} -
- -
-
- - - - -
-
-
- changeSettings('isDNSCheckEnabled')} - /> -
-
- !isFqdnSet && changeSettings('dualCerts')} - /> -
-
- changeSettings('isRegistrationEnabled')} - /> -
- {#if browser && $features.beta} -
- changeSettings('isAutoUpdateEnabled')} - /> -
- {/if} -
-
- {#if !settings.isTraefikUsed} -
-
{$t('setting.coolify_proxy_settings')}
-
- -
-
- - -
-
- - -
-
- {/if} - {/if} - {#if subMenuActive === 'sshkey'} -
-
-
SSH Keys
- -
-
- {#if sshKeys.length === 0} -
No SSH keys found
- {:else} - {#each sshKeys as key} -
-
{key.name}
-
Added on {key.createdAt}
- -
- {/each} - {/if} -
-
- {/if} - {/if} -
-
-
- -{#if isModalActive} -