Skip to content

Commit

Permalink
ui: settings
Browse files Browse the repository at this point in the history
  • Loading branch information
andrasbacsai committed Jul 26, 2022
1 parent 641dc98 commit e5b505b
Show file tree
Hide file tree
Showing 14 changed files with 556 additions and 507 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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...
2 changes: 2 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ tasks:
ports:
- port: 3001
visibility: public
- port: 3000
visibility: public
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions apps/api/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ model Team {
databaseId String?
service Service[] @relation(references: [id])
serviceId String?
SshKey SshKey[]
}

model TeamInvitation {
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/lib/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ export async function isDomainConfigured({
id: string;
fqdn: string;
checkOwn?: boolean;
dockerId: string;
dockerId?: string;
}): Promise<boolean> {

console.log({ checkOwn, dockerId })
Expand Down
6 changes: 4 additions & 2 deletions apps/api/src/routes/api/v1/settings/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -96,6 +97,7 @@ export async function checkDNS(request: FastifyRequest<CheckDNS>) {

export async function saveSSHKey(request: FastifyRequest<SaveSSHKey>, 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) {
Expand All @@ -104,7 +106,7 @@ export async function saveSSHKey(request: FastifyRequest<SaveSSHKey>, 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 })
Expand Down
1 change: 0 additions & 1 deletion apps/ui/src/lib/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export const appSession: Writable<AppSession> = writable({
gitlab: null
}
});
export const isTraefikUsed: Writable<boolean> = writable(false);
export const disabledButton: Writable<boolean> = writable(false);
export const status: Writable<any> = writable({
application: {
Expand Down
54 changes: 25 additions & 29 deletions apps/ui/src/routes/__layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -324,33 +322,31 @@
<path d="M21 21v-2a4 4 0 0 0 -3 -3.85" />
</svg>
</a>
{#if $appSession.teamId === '0'}
<a
sveltekit:prefetch
href="/settings"
class="icons tooltip-yellow-500 tooltip-right bg-coolgray-200 hover:text-yellow-500"
class:text-yellow-500={$page.url.pathname.startsWith('/settings')}
class:bg-coolgray-500={$page.url.pathname.startsWith('/settings')}
data-tooltip="Settings"
<a
sveltekit:prefetch
href={$appSession.teamId === '0' ? '/settings/global' : '/settings/ssh-keys'}
class="icons tooltip-yellow-500 tooltip-right bg-coolgray-200 hover:text-yellow-500"
class:text-yellow-500={$page.url.pathname.startsWith('/settings')}
class:bg-coolgray-500={$page.url.pathname.startsWith('/settings')}
data-tooltip="Settings"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-8 w-8"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-8 w-8"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
fill="none"
stroke-linecap="round"
stroke-linejoin="round"
>
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"
/>
<circle cx="12" cy="12" r="3" />
</svg>
</a>
{/if}
<path stroke="none" d="M0 0h24v24H0z" fill="none" />
<path
d="M10.325 4.317c.426 -1.756 2.924 -1.756 3.35 0a1.724 1.724 0 0 0 2.573 1.066c1.543 -.94 3.31 .826 2.37 2.37a1.724 1.724 0 0 0 1.065 2.572c1.756 .426 1.756 2.924 0 3.35a1.724 1.724 0 0 0 -1.066 2.573c.94 1.543 -.826 3.31 -2.37 2.37a1.724 1.724 0 0 0 -2.572 1.065c-.426 1.756 -2.924 1.756 -3.35 0a1.724 1.724 0 0 0 -2.573 -1.066c-1.543 .94 -3.31 -.826 -2.37 -2.37a1.724 1.724 0 0 0 -1.065 -2.572c-1.756 -.426 -1.756 -2.924 0 -3.35a1.724 1.724 0 0 0 1.066 -2.573c-.94 -1.543 .826 -3.31 2.37 -2.37c1 .608 2.296 .07 2.572 -1.065z"
/>
<circle cx="12" cy="12" r="3" />
</svg>
</a>

<div
class="icons tooltip-red-500 tooltip-right bg-coolgray-200 hover:text-red-500"
Expand Down
3 changes: 3 additions & 0 deletions apps/ui/src/routes/destinations/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@
{#if $appSession.teamId === '0' && destination.remoteVerified === false && destination.remoteEngine}
<div class="truncate text-center text-sm text-red-500">Not verified yet</div>
{/if}
{#if destination.remoteEngine && !destination.sshKeyId}
<div class="truncate text-center text-sm text-red-500">SSH Key missing!</div>
{/if}
</div>
</a>
{/each}
Expand Down
21 changes: 21 additions & 0 deletions apps/ui/src/routes/settings/_Menu.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script lang="ts">
import { page } from '$app/stores';
import { appSession } from '$lib/store';
</script>

<div class="flex flex-col pt-4 space-y-6 w-96 px-20">
{#if $appSession.teamId === '0'}
<a
href="/settings/global"
class="sub-menu no-underline"
class:sub-menu-active={$page.routeId === 'settings/global'}
>
Global Settings
</a>
{/if}
<a
href="/settings/ssh-keys"
class="sub-menu no-underline"
class:sub-menu-active={$page.routeId === 'settings/ssh-keys'}>SSH Keys</a
>
</div>
23 changes: 23 additions & 0 deletions apps/ui/src/routes/settings/__layout.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<script context="module" lang="ts">
import { get } from '$lib/api';
import type { Load } from '@sveltejs/kit';
export const load: Load = async () => {
try {
const response = await get(`/settings`);
return {
stuff: {
...response
}
};
} catch (error: any) {
return {
status: 500,
error: new Error(error)
};
}
};
</script>


<slot />
Loading

0 comments on commit e5b505b

Please sign in to comment.