From 0616a68bd2e0c9cb559ebdf294e353dd3f69c9a5 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Thu, 15 Dec 2022 21:44:04 +0100 Subject: [PATCH] feat: custom email message --- backend/prisma/seed/config.seed.ts | 6 ++++++ backend/src/config/config.service.ts | 10 ++++++++-- backend/src/email/email.service.ts | 6 +++++- .../src/components/admin/AdminConfigTable.tsx | 15 ++++++++++++--- .../admin/showUpdateConfigVariableModal.tsx | 14 +++++++++++--- frontend/src/services/config.service.ts | 2 +- 6 files changed, 43 insertions(+), 10 deletions(-) diff --git a/backend/prisma/seed/config.seed.ts b/backend/prisma/seed/config.seed.ts index 52509ce..4220bda 100644 --- a/backend/prisma/seed/config.seed.ts +++ b/backend/prisma/seed/config.seed.ts @@ -60,6 +60,12 @@ const configVariables: Prisma.ConfigCreateInput[] = [ value: "false", secret: false, }, + { + key: "EMAIL_MESSAGE", + description: "Message which gets sent to the recipients. {creator} and {shareUrl} will be replaced with the creator's name and the share URL.", + type: "text", + value: "Hey!\n{creator} shared some files with you. View or download the files with this link: {shareUrl}\nShared securely with Pingvin Share 🐧", + }, { key: "SMTP_HOST", description: "Host of the SMTP server", diff --git a/backend/src/config/config.service.ts b/backend/src/config/config.service.ts index 1291fee..8ee78f5 100644 --- a/backend/src/config/config.service.ts +++ b/backend/src/config/config.service.ts @@ -23,7 +23,8 @@ export class ConfigService { if (configVariable.type == "number") return parseInt(configVariable.value); if (configVariable.type == "boolean") return configVariable.value == "true"; - if (configVariable.type == "string") return configVariable.value; + if (configVariable.type == "string" || configVariable.type == "text") + return configVariable.value; } async listForAdmin() { @@ -46,10 +47,15 @@ export class ConfigService { if (!configVariable || configVariable.locked) throw new NotFoundException("Config variable not found"); - if (typeof value != configVariable.type) + if ( + typeof value != configVariable.type && + typeof value == "string" && + configVariable.type != "text" + ) { throw new BadRequestException( `Config variable must be of type ${configVariable.type}` ); + } const updatedVariable = await this.prisma.config.update({ where: { key }, diff --git a/backend/src/email/email.service.ts b/backend/src/email/email.service.ts index 5078da2..2f36d94 100644 --- a/backend/src/email/email.service.ts +++ b/backend/src/email/email.service.ts @@ -28,7 +28,11 @@ export class EmailService { from: `"Pingvin Share" <${this.config.get("SMTP_EMAIL")}>`, to: recipientEmail, subject: "Files shared with you", - text: `Hey!\n${creator.username} shared some files with you. View or dowload the files with this link: ${shareUrl}\nShared securely with Pingvin Share 🐧`, + text: this.config + .get("EMAIL_MESSAGE") + .replaceAll("\\n", "\n") + .replaceAll("{creator}", creator.username) + .replaceAll("{shareUrl}", shareUrl), }); } } diff --git a/frontend/src/components/admin/AdminConfigTable.tsx b/frontend/src/components/admin/AdminConfigTable.tsx index 70a5b1b..e7141fa 100644 --- a/frontend/src/components/admin/AdminConfigTable.tsx +++ b/frontend/src/components/admin/AdminConfigTable.tsx @@ -73,9 +73,18 @@ const AdminConfigTable = () => { - {configVariable.obscured - ? "•".repeat(configVariable.value.length) - : configVariable.value} + + {configVariable.obscured + ? "•".repeat(configVariable.value.length) + : configVariable.value} + diff --git a/frontend/src/components/admin/showUpdateConfigVariableModal.tsx b/frontend/src/components/admin/showUpdateConfigVariableModal.tsx index c1ef6cb..fe4440f 100644 --- a/frontend/src/components/admin/showUpdateConfigVariableModal.tsx +++ b/frontend/src/components/admin/showUpdateConfigVariableModal.tsx @@ -7,6 +7,7 @@ import { Space, Stack, Text, + Textarea, TextInput, Title, } from "@mantine/core"; @@ -45,6 +46,7 @@ const Body = ({ const form = useForm({ initialValues: { stringValue: configVariable.value, + textValue: configVariable.value, numberValue: parseInt(configVariable.value), booleanValue: configVariable.value, }, @@ -56,12 +58,16 @@ const Body = ({ {configVariable.type == "string" && (configVariable.obscured ? ( - + ) : ( - + ))} + + {configVariable.type == "text" && ( +