diff --git a/apps/api/src/routes/api/v1/services/handlers.ts b/apps/api/src/routes/api/v1/services/handlers.ts index 8691f2b41..53d446a48 100644 --- a/apps/api/src/routes/api/v1/services/handlers.ts +++ b/apps/api/src/routes/api/v1/services/handlers.ts @@ -2,13 +2,13 @@ import type { FastifyReply, FastifyRequest } from 'fastify'; import fs from 'fs/promises'; import yaml from 'js-yaml'; import bcrypt from 'bcryptjs'; -import { prisma, uniqueName, asyncExecShell, getServiceImage, getServiceFromDB, getContainerUsage,isDomainConfigured, saveUpdateableFields, fixType, decrypt, encrypt, getServiceMainPort, createDirectories, ComposeFile, makeLabelForServices, getFreePublicPort, getDomain, errorHandler, generatePassword, isDev, stopTcpHttpProxy, executeDockerCmd, checkDomainsIsValidInDNS, persistentVolumes, asyncSleep, isARM, defaultComposeConfiguration, checkExposedPort } from '../../../../lib/common'; +import { prisma, uniqueName, asyncExecShell, getServiceImage, getServiceFromDB, getContainerUsage, isDomainConfigured, saveUpdateableFields, fixType, decrypt, encrypt, getServiceMainPort, createDirectories, ComposeFile, makeLabelForServices, getFreePublicPort, getDomain, errorHandler, generatePassword, isDev, stopTcpHttpProxy, executeDockerCmd, checkDomainsIsValidInDNS, persistentVolumes, asyncSleep, isARM, defaultComposeConfiguration, checkExposedPort } from '../../../../lib/common'; import { day } from '../../../../lib/dayjs'; import { checkContainer, isContainerExited, removeContainer } from '../../../../lib/docker'; import cuid from 'cuid'; import type { OnlyId } from '../../../../types'; -import type { ActivateWordpressFtp, CheckService, CheckServiceDomain, DeleteServiceSecret, DeleteServiceStorage, GetServiceLogs, SaveService, SaveServiceDestination, SaveServiceSecret, SaveServiceSettings, SaveServiceStorage, SaveServiceType, SaveServiceVersion, ServiceStartStop, SetWordpressSettings } from './types'; +import type { ActivateWordpressFtp, CheckService, CheckServiceDomain, DeleteServiceSecret, DeleteServiceStorage, GetServiceLogs, SaveService, SaveServiceDestination, SaveServiceSecret, SaveServiceSettings, SaveServiceStorage, SaveServiceType, SaveServiceVersion, ServiceStartStop, SetGlitchTipSettings, SetWordpressSettings } from './types'; import { defaultServiceConfigurations } from '../../../../lib/services'; import { supportedServiceTypesAndVersions } from '../../../../lib/services/supportedVersions'; import { configureServiceType, removeService } from '../../../../lib/services/common'; @@ -269,7 +269,6 @@ export async function saveService(request: FastifyRequest, reply: F if (exposePort) exposePort = Number(exposePort); type = fixType(type) - const update = saveUpdateableFields(type, request.body[type]) const data = { fqdn, @@ -400,17 +399,33 @@ export async function deleteServiceStorage(request: FastifyRequest, reply: FastifyReply) { +export async function setSettingsService(request: FastifyRequest, reply: FastifyReply) { try { const { type } = request.params if (type === 'wordpress') { return await setWordpressSettings(request, reply) } + if (type === 'glitchtip') { + return await setGlitchTipSettings(request, reply) + } throw `Service type ${type} not supported.` } catch ({ status, message }) { return errorHandler({ status, message }) } } +async function setGlitchTipSettings(request: FastifyRequest, reply: FastifyReply) { + try { + const { id } = request.params + const { enableOpenUserRegistration, emailSmtpUseSsl, emailSmtpUseTls } = request.body + await prisma.glitchTip.update({ + where: { serviceId: id }, + data: { enableOpenUserRegistration, emailSmtpUseSsl, emailSmtpUseTls } + }); + return reply.code(201).send() + } catch ({ status, message }) { + return errorHandler({ status, message }) + } +} async function setWordpressSettings(request: FastifyRequest, reply: FastifyReply) { try { const { id } = request.params diff --git a/apps/api/src/routes/api/v1/services/index.ts b/apps/api/src/routes/api/v1/services/index.ts index fd1ab061b..454f4c06e 100644 --- a/apps/api/src/routes/api/v1/services/index.ts +++ b/apps/api/src/routes/api/v1/services/index.ts @@ -29,7 +29,7 @@ import { } from './handlers'; import type { OnlyId } from '../../../../types'; -import type { ActivateWordpressFtp, CheckService, CheckServiceDomain, DeleteServiceSecret, DeleteServiceStorage, GetServiceLogs, SaveService, SaveServiceDestination, SaveServiceSecret, SaveServiceSettings, SaveServiceStorage, SaveServiceType, SaveServiceVersion, ServiceStartStop, SetWordpressSettings } from './types'; +import type { ActivateWordpressFtp, CheckService, CheckServiceDomain, DeleteServiceSecret, DeleteServiceStorage, GetServiceLogs, SaveService, SaveServiceDestination, SaveServiceSecret, SaveServiceSettings, SaveServiceStorage, SaveServiceType, SaveServiceVersion, ServiceStartStop, SetGlitchTipSettings, SetWordpressSettings } from './types'; import { startService, stopService } from '../../../../lib/services/handlers'; const root: FastifyPluginAsync = async (fastify): Promise => { @@ -71,7 +71,7 @@ const root: FastifyPluginAsync = async (fastify): Promise => { fastify.post('/:id/:type/start', async (request) => await startService(request)); fastify.post('/:id/:type/stop', async (request) => await stopService(request)); - fastify.post('/:id/:type/settings', async (request, reply) => await setSettingsService(request, reply)); + fastify.post('/:id/:type/settings', async (request, reply) => await setSettingsService(request, reply)); fastify.post('/:id/plausibleanalytics/activate', async (request, reply) => await activatePlausibleUsers(request, reply)); fastify.post('/:id/plausibleanalytics/cleanup', async (request, reply) => await cleanupPlausibleLogs(request, reply)); diff --git a/apps/api/src/routes/api/v1/services/types.ts b/apps/api/src/routes/api/v1/services/types.ts index f09b4423f..098e7880f 100644 --- a/apps/api/src/routes/api/v1/services/types.ts +++ b/apps/api/src/routes/api/v1/services/types.ts @@ -89,6 +89,12 @@ export interface ActivateWordpressFtp extends OnlyId { } } - +export interface SetGlitchTipSettings extends OnlyId { + Body: { + enableOpenUserRegistration: boolean, + emailSmtpUseSsl: boolean, + emailSmtpUseTls: boolean + } +} diff --git a/apps/ui/src/lib/components/svg/services/MeiliSearch.svelte b/apps/ui/src/lib/components/svg/services/MeiliSearch.svelte index c3cd9b1f1..033fba82f 100644 --- a/apps/ui/src/lib/components/svg/services/MeiliSearch.svelte +++ b/apps/ui/src/lib/components/svg/services/MeiliSearch.svelte @@ -4,7 +4,7 @@ import CopyPasswordField from '$lib/components/CopyPasswordField.svelte'; - import Explainer from '$lib/components/Explainer.svelte'; + import { addToast, status } from '$lib/store'; import Setting from '$lib/components/Setting.svelte'; import { t } from '$lib/translations'; + import { post } from '$lib/api'; + import { page } from '$app/stores'; + import { errorNotification } from '$lib/common'; export let service: any; - function toggleEmailSmtpUseTls() { - service.glitchTip.emailSmtpUseTls = !service.glitchTip.emailSmtpUseTls; - } - function toggleEmailSmtpUseSsl() { - service.glitchTip.emailSmtpUseSsl = !service.glitchTip.emailSmtpUseSsl; - } - function toggleEnableOpenUserRegistration() { - service.glitchTip.enableOpenUserRegistration = !service.glitchTip.enableOpenUserRegistration; + + const { id } = $page.params; + let loading = false; + + async function changeSettings(name: any) { + if (loading || $status.service.isRunning) return; + + let enableOpenUserRegistration = service.glitchTip.enableOpenUserRegistration; + let emailSmtpUseSsl = service.glitchTip.emailSmtpUseSsl; + let emailSmtpUseTls = service.glitchTip.emailSmtpUseTls; + + loading = true; + if (name === 'enableOpenUserRegistration') { + enableOpenUserRegistration = !enableOpenUserRegistration; + } + if (name === 'emailSmtpUseSsl') { + emailSmtpUseSsl = !emailSmtpUseSsl; + } + if (name === 'emailSmtpUseTls') { + emailSmtpUseTls = !emailSmtpUseTls; + } + try { + await post(`/services/${id}/glitchtip/settings`, { + enableOpenUserRegistration, + emailSmtpUseSsl, + emailSmtpUseTls + }); + service.glitchTip.emailSmtpUseTls = emailSmtpUseTls; + service.glitchTip.emailSmtpUseSsl = emailSmtpUseSsl; + service.glitchTip.enableOpenUserRegistration = enableOpenUserRegistration; + return addToast({ + message: 'Settings updated.', + type: 'success', + }); + } catch (error) { + return errorNotification(error); + } finally { + loading = false; + } } @@ -19,76 +53,33 @@
GlitchTip
-
-
Settings
-
-
changeSettings('enableOpenUserRegistration')} + title="Enable Open User Registration" + description={''} + /> +
Email settings
- -
- - -
- -
- - -
- -
- - -
- -
- - -
- -
- - -
-
changeSettings('emailSmtpUseTls')} + title="Use TLS for SMTP" description={''} />
@@ -96,32 +87,84 @@
changeSettings('emailSmtpUseSsl')} + title="Use SSL for SMTP" description={''} />
-
- - -
- -
- +
- + + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
@@ -130,35 +173,31 @@
- +
- +
- +
- +
- +
- +