From a18ccb635d467e8f4d19975ec51b6955cb1c8551 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 25 Apr 2025 10:19:30 -0700 Subject: [PATCH 1/6] remove unused settings, remove comment --- client/src/Features/Settings/settingsSlice.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/client/src/Features/Settings/settingsSlice.js b/client/src/Features/Settings/settingsSlice.js index d158a4ae4..614ab7159 100644 --- a/client/src/Features/Settings/settingsSlice.js +++ b/client/src/Features/Settings/settingsSlice.js @@ -30,26 +30,9 @@ export const getAppSettings = createAsyncThunk( export const updateAppSettings = createAsyncThunk( "settings/updateSettings", async ({ settings }, thunkApi) => { - // The reason for commenting is that, previously, we had the flexibility to set the API base. - // However, now this could lead to an issue where it gets set to undefined. - // networkService.setBaseUrl(settings.apiBaseUrl); try { const parsedSettings = { - apiBaseUrl: settings.apiBaseUrl, - logLevel: settings.logLevel, language: settings.language, - clientHost: settings.clientHost, - jwtSecret: settings.jwtSecret, - dbType: settings.dbType, - dbConnectionString: settings.dbConnectionString, - redisHost: settings.redisHost, - redisPort: settings.redisPort, - jwtTTL: settings.jwtTTL, - pagespeedApiKey: settings.pagespeedApiKey, - systemEmailHost: settings.systemEmailHost, - systemEmailPort: settings.systemEmailPort, - systemEmailAddress: settings.systemEmailAddress, - systemEmailPassword: settings.systemEmailPassword, }; const res = await networkService.updateAppSettings({ settings: parsedSettings }); return res.data; From 23a9c9b97ad4edfae576023cda637a56ca25dfdb Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 25 Apr 2025 10:19:54 -0700 Subject: [PATCH 2/6] fix error handling --- client/src/Pages/Settings/index.jsx | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/client/src/Pages/Settings/index.jsx b/client/src/Pages/Settings/index.jsx index 2155485cd..1bad8414d 100644 --- a/client/src/Pages/Settings/index.jsx +++ b/client/src/Pages/Settings/index.jsx @@ -123,31 +123,17 @@ const Settings = () => { ttl: form.ttl, }); const updatedUser = { ...user, checkTTL: form.ttl }; - const action = await dispatch(update({ localData: updatedUser })); - const settingsAction = await dispatch( - updateAppSettings({ settings: { language: language } }) - ); + const [userAction, settingsAction] = await Promise.all([ + dispatch(update({ localData: updatedUser })), + dispatch(updateAppSettings({ settings: { language: language } })), + ]); - if (action.payload.success && settingsAction.payload.success) { - createToast({ - body: t("settingsSuccessSaved"), - }); + if (userAction.payload.success && settingsAction.payload.success) { + createToast({ body: t("settingsSuccessSaved") }); } else { - if (action.payload) { - console.log(action.payload); - // dispatch errors - createToast({ - body: action.payload.msg, - }); - } else { - // unknown errors - createToast({ - body: "Unknown error.", - }); - } + throw new Error("Failed to save settings"); } } catch (error) { - console.log(error); createToast({ body: t("settingsFailedToSave") }); } finally { setChecksIsLoading(false); From 5c66ad1990f73d8ec4941e0a22bd7469fd438294 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 25 Apr 2025 10:20:24 -0700 Subject: [PATCH 3/6] 401 -> 403 for insufficient permissoins --- server/middleware/isAllowed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/middleware/isAllowed.js b/server/middleware/isAllowed.js index 39289dfe8..4c6f89aa3 100755 --- a/server/middleware/isAllowed.js +++ b/server/middleware/isAllowed.js @@ -41,7 +41,7 @@ const isAllowed = (allowedRoles) => { return; } else { const error = new Error(stringService.insufficientPermissions); - error.status = 401; + error.status = 403; error.service = SERVICE_NAME; next(error); return; From 4954468a9ab1625bb9a1baba87f6f96c66695cf3 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 25 Apr 2025 10:20:42 -0700 Subject: [PATCH 4/6] allow admin for settings --- server/routes/settingsRoute.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/routes/settingsRoute.js b/server/routes/settingsRoute.js index 8da262427..a5501aaf3 100755 --- a/server/routes/settingsRoute.js +++ b/server/routes/settingsRoute.js @@ -12,7 +12,7 @@ class SettingsRoutes { this.router.get("/", this.settingsController.getAppSettings); this.router.put( "/", - isAllowed(["superadmin"]), + isAllowed(["admin", "superadmin"]), this.settingsController.updateAppSettings ); } From dc36873cb1ad5e705115824e002d303fd5750205 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 25 Apr 2025 10:21:19 -0700 Subject: [PATCH 5/6] remove baseapiurl --- server/service/settingsService.js | 1 - 1 file changed, 1 deletion(-) diff --git a/server/service/settingsService.js b/server/service/settingsService.js index 6d3b8c66d..840f15e84 100755 --- a/server/service/settingsService.js +++ b/server/service/settingsService.js @@ -3,7 +3,6 @@ import dotenv from "dotenv"; dotenv.config(); const envConfig = { logLevel: process.env.LOG_LEVEL, - apiBaseUrl: undefined, language: process.env.LANGUAGE, clientHost: process.env.CLIENT_HOST, jwtSecret: process.env.JWT_SECRET, From 5e11ba05ba62d2d91d5654991489b66561687f92 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Fri, 25 Apr 2025 10:21:40 -0700 Subject: [PATCH 6/6] add missing getter --- server/service/stringService.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server/service/stringService.js b/server/service/stringService.js index de900b23a..0c283c98b 100755 --- a/server/service/stringService.js +++ b/server/service/stringService.js @@ -189,26 +189,26 @@ class StringService { get telegramRequiresBotTokenAndChatId() { return this.translationService.getTranslation("telegramRequiresBotTokenAndChatId"); } - + get webhookUrlRequired() { return this.translationService.getTranslation("webhookUrlRequired"); } - + get platformRequired() { return this.translationService.getTranslation("platformRequired"); } - + get testNotificationFailed() { return this.translationService.getTranslation("testNotificationFailed"); } get monitorUpAlert() { return this.translationService.getTranslation("monitorUpAlert"); - } - - get monitorDownAlert() { + } + + get monitorDownAlert() { return this.translationService.getTranslation("monitorDownAlert"); - } + } getWebhookUnsupportedPlatform(platform) { return this.translationService @@ -415,6 +415,10 @@ class StringService { return this.translationService.getTranslation("updateAppSettings"); } + get insufficientPermissions() { + return this.translationService.getTranslation("insufficientPermissions"); + } + getDbFindMonitorById(monitorId) { return this.translationService .getTranslation("dbFindMonitorById")