From f6be4317cd4fb3ed669afadc27f47a6733dd9543 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:36:20 +0800 Subject: [PATCH 1/6] remove user and teamid from validation --- server/validation/joi.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/server/validation/joi.js b/server/validation/joi.js index 5eb24e758..725fcf218 100755 --- a/server/validation/joi.js +++ b/server/validation/joi.js @@ -558,14 +558,6 @@ const triggerNotificationBodyValidation = joi.object({ }); const createNotificationBodyValidation = joi.object({ - userId: joi.string().required().messages({ - "number.empty": "User ID is required", - "any.required": "User ID is required", - }), - teamId: joi.string().required().messages({ - "string.empty": "Team ID is required", - "any.required": "Team ID is required", - }), notificationName: joi.string().required().messages({ "string.empty": "Notification name is required", "any.required": "Notification name is required", From 22f8a37f1f93927a2d60c10e5808fedf2297d45f Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:36:34 +0800 Subject: [PATCH 2/6] add discord type --- server/db/models/Notification.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/db/models/Notification.js b/server/db/models/Notification.js index 34afa1f31..751324131 100755 --- a/server/db/models/Notification.js +++ b/server/db/models/Notification.js @@ -7,7 +7,7 @@ const configSchema = mongoose.Schema( chatId: { type: String }, platform: { type: String, - enum: ["slack", "pager_duty", "webhook"], + enum: ["slack", "pager_duty", "webhook", "discord"], }, routingKey: { type: String }, }, From bfae00b69b56e369c250d35c75158174a69ecbf8 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:36:45 +0800 Subject: [PATCH 3/6] add strings --- client/src/locales/en.json | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/client/src/locales/en.json b/client/src/locales/en.json index 2791dd3e7..31db9325b 100644 --- a/client/src/locales/en.json +++ b/client/src/locales/en.json @@ -298,6 +298,12 @@ "description": "Configure your webhook here", "webhookLabel": "Webhook URL", "webhookPlaceholder": "https://your-server.com/webhook" + }, + "discordSettings": { + "title": "Discord", + "description": "Configure your Discord webhook here", + "webhookLabel": "Discord Webhook URL", + "webhookPlaceholder": "https://your-server.com/webhook" } }, From 5aae16486560bdccba425adc77f8eb8bf551bb90 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:37:04 +0800 Subject: [PATCH 4/6] extrat userId and teamId from req.uesr --- server/controllers/notificationController.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/server/controllers/notificationController.js b/server/controllers/notificationController.js index a9c399901..82e2a23ab 100755 --- a/server/controllers/notificationController.js +++ b/server/controllers/notificationController.js @@ -102,6 +102,7 @@ class NotificationController { success = await this.notificationService.sendTestPagerDutyNotification(notification); } + if (!success) { return res.error({ msg: "Sending notification failed", @@ -128,7 +129,11 @@ class NotificationController { } try { - const notification = await this.db.createNotification(req.body); + const body = req.body; + const { _id, teamId } = req.user; + body.userId = _id; + body.teamId = teamId; + const notification = await this.db.createNotification(body); return res.success({ msg: "Notification created successfully", data: notification, From bea23a94bb6a042faaea8ee3b6ce1b883f5a17ce Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 16 Jun 2025 10:38:05 +0800 Subject: [PATCH 5/6] handle discord webhooks --- .../src/Pages/Notifications/create/index.jsx | 72 ++++++++++++++----- client/src/Pages/Notifications/utils.js | 3 +- 2 files changed, 58 insertions(+), 17 deletions(-) diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx index 3c17c113c..8b5512ca8 100644 --- a/client/src/Pages/Notifications/create/index.jsx +++ b/client/src/Pages/Notifications/create/index.jsx @@ -10,7 +10,6 @@ import TextInput from "../../../Components/Inputs/TextInput"; // Utils import { useState } from "react"; -import { useSelector } from "react-redux"; import { useTheme } from "@emotion/react"; import { useCreateNotification, @@ -44,7 +43,6 @@ const CreateNotifications = () => { ]; // Redux state - const { user } = useSelector((state) => state.auth); // local state const [notification, setNotification] = useState({ @@ -73,7 +71,7 @@ const CreateNotifications = () => { type: NOTIFICATION_TYPES.find((type) => type._id === notification.type).value, }; - if (notification.type === 2) { + if (form.type === "slack" || form.type === "discord") { form.type = "webhook"; } @@ -128,27 +126,33 @@ const CreateNotifications = () => { // Handle config/platform initialization if type is webhook - if (newNotification.type === 1) { + const type = NOTIFICATION_TYPES.find( + (type) => type._id === newNotification.type + ).value; + + if (newNotification.type === "email") { newNotification.config = null; - } else if (newNotification.type === 2) { + } else if (type === "slack" || type === "webhook" || type === "discord") { newNotification.address = ""; newNotification.config = newNotification.config || {}; if (name === "config") { newNotification.config = value; } - newNotification.config.platform = "slack"; - } else if (newNotification.type === 3) { + if (type === "webhook") { + newNotification.config.platform = "webhook"; + } + if (type === "slack") { + newNotification.config.platform = "slack"; + } + if (type === "discord") { + newNotification.config.platform = "discord"; + } + } else if (type === "pager_duty") { newNotification.config = newNotification.config || {}; if (name === "config") { newNotification.config = value; } newNotification.config.platform = "pager_duty"; - } else if (newNotification.type === 4) { - newNotification.config = newNotification.config || {}; - if (name === "config") { - newNotification.config = value; - } - newNotification.config.platform = "webhook"; } // Field-level validation @@ -159,12 +163,15 @@ const CreateNotifications = () => { fieldError = error?.message; } - if (newNotification.type === 1 && name === "address") { + if (type === "email" && name === "address") { const { error } = notificationEmailValidation.extract(name).validate(value); fieldError = error?.message; } - if (newNotification.type === 2 && name === "config") { + if ( + (type === "slack" || type === "webhook" || type === "discord") && + name === "config" + ) { // Validate only webhookUrl inside config const { error } = notificationWebhookValidation.extract("config").validate(value); fieldError = error?.message; @@ -185,7 +192,7 @@ const CreateNotifications = () => { type: NOTIFICATION_TYPES.find((type) => type._id === notification.type).value, }; - if (notification.type === 2) { + if (form.type === "slack" || form.type === "discord") { form.type = "webhook"; } @@ -405,6 +412,39 @@ const CreateNotifications = () => { )} + {notification.type === 5 && ( + + + + {t("createNotifications.discordSettings.title")} + + + {t("createNotifications.discordSettings.description")} + + + + { + const updatedConfig = { + ...notification.config, + webhookUrl: e.target.value, + }; + + onChange({ + target: { + name: "config", + value: updatedConfig, + }, + }); + }} + /> + + + )} Date: Mon, 16 Jun 2025 13:30:27 +0800 Subject: [PATCH 6/6] fix email type --- client/src/Pages/Notifications/create/index.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/src/Pages/Notifications/create/index.jsx b/client/src/Pages/Notifications/create/index.jsx index 8b5512ca8..2fd83e4e1 100644 --- a/client/src/Pages/Notifications/create/index.jsx +++ b/client/src/Pages/Notifications/create/index.jsx @@ -130,7 +130,7 @@ const CreateNotifications = () => { (type) => type._id === newNotification.type ).value; - if (newNotification.type === "email") { + if (type === "email") { newNotification.config = null; } else if (type === "slack" || type === "webhook" || type === "discord") { newNotification.address = "";