From d8dff468ab9bb8b5b987fde0a80d834245a91c6d Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Tue, 18 Jun 2024 13:33:09 +0100 Subject: [PATCH] refactor: Update Cookie.ts to accept string as key parameter This commit modifies the Cookie.ts file to update the setItem method signature. The key parameter now accepts both CookieName and string types, allowing for more flexibility when setting cookies. This change improves the usability and versatility of the Cookie utility class. --- Accounts/src/Pages/LoginWithSSO.tsx | 2 +- .../Templates/MonitorOwnerStatusChanged.hbs | 2 + .../Templates/Partials/DetailBoxField.hbs | 10 +- .../SendCreatedResourceNotification.ts | 134 ++++++++++-------- .../SendStatusChangeNotification.ts | 3 +- CommonUI/src/Utils/Cookie.ts | 2 +- 6 files changed, 85 insertions(+), 68 deletions(-) diff --git a/Accounts/src/Pages/LoginWithSSO.tsx b/Accounts/src/Pages/LoginWithSSO.tsx index 94141a3823..9b7e10d828 100644 --- a/Accounts/src/Pages/LoginWithSSO.tsx +++ b/Accounts/src/Pages/LoginWithSSO.tsx @@ -10,7 +10,7 @@ import Navigation from "CommonUI/src/Utils/Navigation"; import UserUtil from "CommonUI/src/Utils/User"; import User from "Model/Models/User"; import React, { ReactElement, useState } from "react"; -import ProjectSSO from "Model/Models/ProjectSSO"; +import ProjectSSO from "Model/Models/ProjectSso"; import PageLoader from "CommonUI/src/Components/Loader/PageLoader"; import API from "CommonUI/src/Utils/API/API"; import BasicForm from "CommonUI/src/Components/Forms/BasicForm"; diff --git a/App/FeatureSet/Notification/Templates/MonitorOwnerStatusChanged.hbs b/App/FeatureSet/Notification/Templates/MonitorOwnerStatusChanged.hbs index cbe08ae493..ba4c89e826 100644 --- a/App/FeatureSet/Notification/Templates/MonitorOwnerStatusChanged.hbs +++ b/App/FeatureSet/Notification/Templates/MonitorOwnerStatusChanged.hbs @@ -11,8 +11,10 @@ {{> DetailBoxStart this }} {{> DetailBoxField title="Monitor Name:" text=monitorName }} {{> DetailBoxField title="New Status: " text=currentStatus }} +{{#ifNotCond rootCause ""}} {{> DetailBoxField title="Root Cause: " text="" }} {{> DetailBoxField title="" text=rootCause }} +{{/ifNotCond}} {{> DetailBoxField title="Status changed at: " text="" }} {{> DetailBoxField title="" text=statusChangedAt }} {{> DetailBoxField title="Description: " text="" }} diff --git a/App/FeatureSet/Notification/Templates/Partials/DetailBoxField.hbs b/App/FeatureSet/Notification/Templates/Partials/DetailBoxField.hbs index 609449ef4f..d3d4604e5e 100644 --- a/App/FeatureSet/Notification/Templates/Partials/DetailBoxField.hbs +++ b/App/FeatureSet/Notification/Templates/Partials/DetailBoxField.hbs @@ -1,7 +1,7 @@ - {{#if title}} -

- {{{title}}} {{{text}}}

+

+{{#if title}} +{{{title}}} {{{text}}} {{else}} {{{text}}} -{{/if}} \ No newline at end of file +{{/if}} +

\ No newline at end of file diff --git a/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts b/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts index f07c7f810b..0abb07b35f 100644 --- a/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts +++ b/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts @@ -12,6 +12,7 @@ import IncidentService from "CommonServer/Services/IncidentService"; import ProjectService from "CommonServer/Services/ProjectService"; import UserNotificationSettingService from "CommonServer/Services/UserNotificationSettingService"; import Markdown, { MarkdownContentType } from "CommonServer/Types/Markdown"; +import logger from "CommonServer/Utils/Logger"; import Incident from "Model/Models/Incident"; import Monitor from "Model/Models/Monitor"; import User from "Model/Models/User"; @@ -38,6 +39,7 @@ RunCron( project: { name: true, }, + remediationNotes: true, currentIncidentState: { name: true, }, @@ -83,67 +85,81 @@ RunCron( } for (const user of owners) { - const vars: Dictionary = { - incidentTitle: incident.title!, - projectName: incident.project!.name!, - currentState: incident.currentIncidentState!.name!, - incidentDescription: await Markdown.convertToHTML( - incident.description! || "", - MarkdownContentType.Email, - ), - resourcesAffected: - incident - .monitors!.map((monitor: Monitor) => { - return monitor.name!; - }) - .join(", ") || "None", - incidentSeverity: incident.incidentSeverity!.name!, - declaredAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({ - date: incidentIdentifiedDate, - timezones: user.timezone ? [user.timezone] : [], - }), - remediationNotes: incident.remediationNotes || "", - rootCause: - incident.rootCause || "No root cause identified for this incident", - incidentViewLink: ( - await IncidentService.getIncidentLinkInDashboard( - incident.projectId!, - incident.id!, - ) - ).toString(), - }; + try { + const vars: Dictionary = { + incidentTitle: incident.title!, + projectName: incident.project!.name!, + currentState: incident.currentIncidentState!.name!, + incidentDescription: await Markdown.convertToHTML( + incident.description! || "", + MarkdownContentType.Email, + ), + resourcesAffected: + incident + .monitors!.map((monitor: Monitor) => { + return monitor.name!; + }) + .join(", ") || "None", + incidentSeverity: incident.incidentSeverity!.name!, + declaredAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones( + { + date: incidentIdentifiedDate, + timezones: user.timezone ? [user.timezone] : [], + }, + ), + remediationNotes: + (await Markdown.convertToHTML( + incident.remediationNotes! || "", + MarkdownContentType.Email, + )) || "", + rootCause: + incident.rootCause || + "No root cause identified for this incident", + incidentViewLink: ( + await IncidentService.getIncidentLinkInDashboard( + incident.projectId!, + incident.id!, + ) + ).toString(), + }; - if (doesResourceHasOwners === true) { - vars["isOwner"] = "true"; + if (doesResourceHasOwners === true) { + vars["isOwner"] = "true"; + } + + const emailMessage: EmailEnvelope = { + templateType: EmailTemplateType.IncidentOwnerResourceCreated, + vars: vars, + subject: "[New Incident] " + incident.title!, + }; + + const sms: SMSMessage = { + message: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`, + }; + + const callMessage: CallRequestMessage = { + data: [ + { + sayMessage: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good bye.`, + }, + ], + }; + + await UserNotificationSettingService.sendUserNotification({ + userId: user.id!, + projectId: incident.projectId!, + emailEnvelope: emailMessage, + smsMessage: sms, + callRequestMessage: callMessage, + eventType: + NotificationSettingEventType.SEND_INCIDENT_CREATED_OWNER_NOTIFICATION, + }); + } catch (e) { + logger.error( + "Error in sending incident created resource notification", + ); + logger.error(e); } - - const emailMessage: EmailEnvelope = { - templateType: EmailTemplateType.IncidentOwnerResourceCreated, - vars: vars, - subject: "[Incident] " + incident.title!, - }; - - const sms: SMSMessage = { - message: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`, - }; - - const callMessage: CallRequestMessage = { - data: [ - { - sayMessage: `This is a message from OneUptime. New incident created: ${incident.title}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good bye.`, - }, - ], - }; - - await UserNotificationSettingService.sendUserNotification({ - userId: user.id!, - projectId: incident.projectId!, - emailEnvelope: emailMessage, - smsMessage: sms, - callRequestMessage: callMessage, - eventType: - NotificationSettingEventType.SEND_INCIDENT_CREATED_OWNER_NOTIFICATION, - }); } } }, diff --git a/App/FeatureSet/Workers/Jobs/MonitorOwners/SendStatusChangeNotification.ts b/App/FeatureSet/Workers/Jobs/MonitorOwners/SendStatusChangeNotification.ts index 4c985d369e..c37bee60e2 100644 --- a/App/FeatureSet/Workers/Jobs/MonitorOwners/SendStatusChangeNotification.ts +++ b/App/FeatureSet/Workers/Jobs/MonitorOwners/SendStatusChangeNotification.ts @@ -106,8 +106,7 @@ RunCron( monitor.id!, ) ).toString(), - rootCause: - monitorStatusTimeline.rootCause || "No root cause identified.", + rootCause: monitorStatusTimeline.rootCause || "", }; if (doesResourceHasOwners === true) { diff --git a/CommonUI/src/Utils/Cookie.ts b/CommonUI/src/Utils/Cookie.ts index 50214ccdd1..2a17186620 100644 --- a/CommonUI/src/Utils/Cookie.ts +++ b/CommonUI/src/Utils/Cookie.ts @@ -10,7 +10,7 @@ import CookieName from "Common/Types/CookieName"; export default class Cookie { public static setItem( - key: CookieName, + key: CookieName | string, value: JSONValue | Email | URL, options?: | {