-
Notifications
You must be signed in to change notification settings - Fork 232
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:OneUptime/oneuptime
- Loading branch information
Showing
48 changed files
with
22,104 additions
and
1,426 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
App/FeatureSet/Notification/Templates/ProbeConnectionStatusChange.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{{> Start this}} | ||
|
||
|
||
{{> Logo this}} | ||
{{> EmailTitle title=title}} | ||
|
||
{{> InfoBlock info="Here are the details: "}} | ||
|
||
{{> DetailBoxStart this }} | ||
{{> DetailBoxField title="Probe Name:" text=probeName }} | ||
{{> DetailBoxField title="Probe Description:" text=probeDescription }} | ||
{{> DetailBoxField title="Probe Status:" text=probeStatus }} | ||
{{> DetailBoxField title="Status Since:" text="" }} | ||
{{> DetailBoxField title="" text=lastAlive }} | ||
{{> DetailBoxField title="Project Name: " text=projectName }} | ||
{{> DetailBoxEnd this }} | ||
|
||
|
||
{{> InfoBlock info="You can view this probe by going to Project Settings > Probes "}} | ||
|
||
{{> ButtonBlock buttonUrl=viewProbesLink buttonText="View Probes"}} | ||
|
||
{{> InfoBlock info="You can also copy and paste this link:"}} | ||
{{> InfoBlock info=viewProbesLink}} | ||
|
||
{{> InfoBlock info="You will be notified when the status of this probe changes."}} | ||
|
||
{{> OwnerInfo this }} | ||
{{> UnsubscribeOwnerEmail this }} | ||
|
||
{{> Footer this }} | ||
|
||
{{> End this}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
{{> Start this}} | ||
|
||
|
||
{{> Logo this}} | ||
{{> EmailTitle title=(concat "Probe: " probeName) }} | ||
|
||
{{> InfoBlock info="You have been added as the owner of this probe."}} | ||
|
||
{{> InfoBlock info="Here are the details: "}} | ||
|
||
{{> DetailBoxStart this }} | ||
{{> DetailBoxField title="Probe Name:" text=probeName }} | ||
{{> DetailBoxField title="Probe Description: " text=probeDescription }} | ||
{{> DetailBoxEnd this }} | ||
|
||
|
||
{{> InfoBlock info="You can view this probe by clicking on the button below - "}} | ||
|
||
{{> ButtonBlock buttonUrl=viewProbeLink buttonText="View on Dashboard"}} | ||
|
||
{{> InfoBlock info="You can also copy and paste this link:"}} | ||
{{> InfoBlock info=viewProbeLink}} | ||
|
||
{{> InfoBlock info="You will be notified when the status of this probe changes."}} | ||
|
||
{{> Footer this }} | ||
|
||
{{> End this}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
190 changes: 190 additions & 0 deletions
190
App/FeatureSet/Workers/Jobs/Probe/SendOwnerAddedNotification.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import RunCron from "../../Utils/Cron"; | ||
import { CallRequestMessage } from "Common/Types/Call/CallRequest"; | ||
import LIMIT_MAX from "Common/Types/Database/LimitMax"; | ||
import Dictionary from "Common/Types/Dictionary"; | ||
import { EmailEnvelope } from "Common/Types/Email/EmailMessage"; | ||
import EmailTemplateType from "Common/Types/Email/EmailTemplateType"; | ||
import NotificationSettingEventType from "Common/Types/NotificationSetting/NotificationSettingEventType"; | ||
import ObjectID from "Common/Types/ObjectID"; | ||
import { SMSMessage } from "Common/Types/SMS/SMS"; | ||
import { EVERY_MINUTE } from "Common/Utils/CronTime"; | ||
import ProbeOwnerTeamService from "CommonServer/Services/ProbeOwnerTeamService"; | ||
import ProbeOwnerUserService from "CommonServer/Services/ProbeOwnerUserService"; | ||
import TeamMemberService from "CommonServer/Services/TeamMemberService"; | ||
import UserNotificationSettingService from "CommonServer/Services/UserNotificationSettingService"; | ||
import ProbeOwnerTeam from "Model/Models/ProbeOwnerTeam"; | ||
import ProbeOwnerUser from "Model/Models/ProbeOwnerUser"; | ||
import User from "Model/Models/User"; | ||
import Probe from "Model/Models/Probe"; | ||
import ProbeService from "CommonServer/Services/ProbeService"; | ||
|
||
RunCron( | ||
"ProbeOwner:SendOwnerAddedEmail", | ||
{ schedule: EVERY_MINUTE, runOnStartup: false }, | ||
async () => { | ||
const probeOwnerTeams: Array<ProbeOwnerTeam> = | ||
await ProbeOwnerTeamService.findBy({ | ||
query: { | ||
isOwnerNotified: false, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
limit: LIMIT_MAX, | ||
skip: 0, | ||
select: { | ||
_id: true, | ||
probeId: true, | ||
teamId: true, | ||
}, | ||
}); | ||
|
||
const probeOwnersMap: Dictionary<Array<User>> = {}; | ||
|
||
for (const probeOwnerTeam of probeOwnerTeams) { | ||
const probeId: ObjectID = probeOwnerTeam.probeId!; | ||
const teamId: ObjectID = probeOwnerTeam.teamId!; | ||
|
||
const users: Array<User> = await TeamMemberService.getUsersInTeams([ | ||
teamId, | ||
]); | ||
|
||
if (probeOwnersMap[probeId.toString()] === undefined) { | ||
probeOwnersMap[probeId.toString()] = []; | ||
} | ||
|
||
for (const user of users) { | ||
(probeOwnersMap[probeId.toString()] as Array<User>).push(user); | ||
} | ||
|
||
// mark this as notified. | ||
await ProbeOwnerTeamService.updateOneById({ | ||
id: probeOwnerTeam.id!, | ||
data: { | ||
isOwnerNotified: true, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
}); | ||
} | ||
|
||
const probeOwnerUsers: Array<ProbeOwnerUser> = | ||
await ProbeOwnerUserService.findBy({ | ||
query: { | ||
isOwnerNotified: false, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
limit: LIMIT_MAX, | ||
skip: 0, | ||
select: { | ||
_id: true, | ||
probeId: true, | ||
userId: true, | ||
user: { | ||
email: true, | ||
name: true, | ||
}, | ||
}, | ||
}); | ||
|
||
for (const probeOwnerUser of probeOwnerUsers) { | ||
const probeId: ObjectID = probeOwnerUser.probeId!; | ||
const user: User = probeOwnerUser.user!; | ||
|
||
if (probeOwnersMap[probeId.toString()] === undefined) { | ||
probeOwnersMap[probeId.toString()] = []; | ||
} | ||
|
||
(probeOwnersMap[probeId.toString()] as Array<User>).push(user); | ||
|
||
// mark this as notified. | ||
await ProbeOwnerUserService.updateOneById({ | ||
id: probeOwnerUser.id!, | ||
data: { | ||
isOwnerNotified: true, | ||
}, | ||
props: { | ||
isRoot: true, | ||
}, | ||
}); | ||
} | ||
|
||
// send email to all of these users. | ||
|
||
for (const probeId in probeOwnersMap) { | ||
if (!probeOwnersMap[probeId]) { | ||
continue; | ||
} | ||
|
||
if ((probeOwnersMap[probeId] as Array<User>).length === 0) { | ||
continue; | ||
} | ||
|
||
const users: Array<User> = probeOwnersMap[probeId] as Array<User>; | ||
|
||
// get all scheduled events of all the projects. | ||
const probe: Probe | null = await ProbeService.findOneById({ | ||
id: new ObjectID(probeId), | ||
props: { | ||
isRoot: true, | ||
}, | ||
|
||
select: { | ||
_id: true, | ||
name: true, | ||
description: true, | ||
projectId: true, | ||
project: { | ||
name: true, | ||
}, | ||
}, | ||
}); | ||
|
||
if (!probe) { | ||
continue; | ||
} | ||
|
||
const vars: Dictionary<string> = { | ||
probeName: probe.name!, | ||
probeDescription: probe.description || "No description provided", | ||
projectName: probe.project!.name!, | ||
viewProbeLink: ( | ||
await ProbeService.getLinkInDashboard(probe.projectId!, probe.id!) | ||
).toString(), | ||
}; | ||
|
||
for (const user of users) { | ||
const emailMessage: EmailEnvelope = { | ||
templateType: EmailTemplateType.ProbeOwnerAdded, | ||
vars: vars, | ||
subject: "[Probe] Owner of " + probe.name, | ||
}; | ||
|
||
const sms: SMSMessage = { | ||
message: `This is a message from OneUptime. You have been added as the owner of the probe: ${probe.name!}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard.`, | ||
}; | ||
|
||
const callMessage: CallRequestMessage = { | ||
data: [ | ||
{ | ||
sayMessage: `This is a message from OneUptime. You have been added as the owner of the probe: ${probe.name!}. To unsubscribe from this notification go to User Settings in OneUptime Dashboard. Good bye.`, | ||
}, | ||
], | ||
}; | ||
|
||
await UserNotificationSettingService.sendUserNotification({ | ||
userId: user.id!, | ||
projectId: probe.projectId!, | ||
emailEnvelope: emailMessage, | ||
smsMessage: sms, | ||
callRequestMessage: callMessage, | ||
eventType: | ||
NotificationSettingEventType.SEND_PROBE_OWNER_ADDED_NOTIFICATION, | ||
}); | ||
} | ||
} | ||
}, | ||
); |
Oops, something went wrong.