@oneuptime/common 7.0.3717 → 7.0.3786

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/Models/DatabaseModels/Alert.ts +3 -2
  2. package/Models/DatabaseModels/Incident.ts +3 -2
  3. package/Models/DatabaseModels/Index.ts +3 -0
  4. package/Models/DatabaseModels/ProjectUser.ts +335 -0
  5. package/Models/DatabaseModels/ScheduledMaintenance.ts +3 -2
  6. package/Server/API/SlackAPI.ts +65 -97
  7. package/Server/API/UserOnCallLogTimelineAPI.ts +2 -9
  8. package/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.ts +17 -0
  9. package/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.ts +17 -0
  10. package/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.ts +17 -0
  11. package/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.ts +101 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  13. package/Server/Middleware/SlackAuthorization.ts +11 -2
  14. package/Server/Services/AlertFeedService.ts +2 -2
  15. package/Server/Services/AlertInternalNoteService.ts +2 -2
  16. package/Server/Services/AlertOwnerTeamService.ts +4 -4
  17. package/Server/Services/AlertOwnerUserService.ts +3 -3
  18. package/Server/Services/AlertService.ts +62 -20
  19. package/Server/Services/AlertStateTimelineService.ts +8 -18
  20. package/Server/Services/IncidentFeedService.ts +101 -2
  21. package/Server/Services/IncidentInternalNoteService.ts +47 -4
  22. package/Server/Services/IncidentOwnerTeamService.ts +57 -4
  23. package/Server/Services/IncidentOwnerUserService.ts +59 -15
  24. package/Server/Services/IncidentPublicNoteService.ts +41 -4
  25. package/Server/Services/IncidentService.ts +279 -193
  26. package/Server/Services/IncidentStateService.ts +25 -0
  27. package/Server/Services/IncidentStateTimelineService.ts +37 -19
  28. package/Server/Services/MonitorStatusTimelineService.ts +7 -17
  29. package/Server/Services/OnCallDutyPolicyEscalationRuleService.ts +2 -0
  30. package/Server/Services/OnCallDutyPolicyExecutionLogService.ts +74 -7
  31. package/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.ts +63 -4
  32. package/Server/Services/OnCallDutyPolicyService.ts +13 -0
  33. package/Server/Services/ProjectUserService.ts +130 -0
  34. package/Server/Services/ScheduledMaintenanceFeedService.ts +2 -2
  35. package/Server/Services/ScheduledMaintenanceInternalNoteService.ts +12 -10
  36. package/Server/Services/ScheduledMaintenanceOwnerTeamService.ts +22 -18
  37. package/Server/Services/ScheduledMaintenanceOwnerUserService.ts +28 -30
  38. package/Server/Services/ScheduledMaintenancePublicNoteService.ts +12 -10
  39. package/Server/Services/ScheduledMaintenanceService.ts +16 -10
  40. package/Server/Services/ScheduledMaintenanceStateTimelineService.ts +1 -1
  41. package/Server/Services/StatusPageSubscriberService.ts +3 -0
  42. package/Server/Services/TeamMemberService.ts +20 -0
  43. package/Server/Services/UserNotificationRuleService.ts +74 -0
  44. package/Server/Services/UserOnCallLogService.ts +1 -1
  45. package/Server/Services/UserService.ts +35 -0
  46. package/Server/Services/WorkspaceNotificationRuleService.ts +508 -149
  47. package/Server/Services/WorkspaceUserAuthTokenService.ts +23 -0
  48. package/Server/Utils/Express.ts +1 -1
  49. package/Server/Utils/StartServer.ts +6 -1
  50. package/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.ts +195 -0
  51. package/Server/Utils/Workspace/Slack/Actions/ActionTypes.ts +20 -0
  52. package/Server/Utils/Workspace/Slack/Actions/Auth.ts +266 -0
  53. package/Server/Utils/Workspace/Slack/Actions/Incident.ts +1117 -0
  54. package/Server/Utils/Workspace/Slack/Messages/Incident.ts +116 -0
  55. package/Server/Utils/Workspace/Slack/Slack.ts +555 -18
  56. package/Server/Utils/Workspace/Slack/app-manifest.json +18 -10
  57. package/Server/Utils/Workspace/Workspace.ts +194 -1
  58. package/Server/Utils/Workspace/WorkspaceBase.ts +145 -19
  59. package/Server/Utils/Workspace/WorkspaceMessages/Incident.ts +68 -0
  60. package/Types/Icon/IconProp.ts +1 -0
  61. package/Types/Workspace/NotificationRules/NotificationRuleCondition.ts +2 -1
  62. package/Types/Workspace/NotificationRules/NotificationRuleUtil.ts +251 -121
  63. package/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.ts +6 -0
  64. package/Types/Workspace/WorkspaceMessagePayload.ts +71 -2
  65. package/UI/Components/ComingSoon/ComingSoon.tsx +13 -3
  66. package/UI/Components/Forms/Fields/FormField.tsx +2 -2
  67. package/UI/Components/Icon/Icon.tsx +39 -2
  68. package/UI/Components/ModelTable/BaseModelTable.tsx +16 -0
  69. package/UI/Components/Radio/Radio.tsx +11 -2
  70. package/UI/Components/Table/TableCard.tsx +2 -2
  71. package/build/dist/Models/DatabaseModels/Alert.js.map +1 -1
  72. package/build/dist/Models/DatabaseModels/Incident.js.map +1 -1
  73. package/build/dist/Models/DatabaseModels/Index.js +2 -0
  74. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  75. package/build/dist/Models/DatabaseModels/ProjectUser.js +340 -0
  76. package/build/dist/Models/DatabaseModels/ProjectUser.js.map +1 -0
  77. package/build/dist/Models/DatabaseModels/ScheduledMaintenance.js.map +1 -1
  78. package/build/dist/Server/API/SlackAPI.js +39 -79
  79. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  80. package/build/dist/Server/API/UserOnCallLogTimelineAPI.js.map +1 -1
  81. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.js +12 -0
  82. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740597525803-MigrationName.js.map +1 -0
  83. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.js +12 -0
  84. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1740598793630-MigrationName.js.map +1 -0
  85. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.js +12 -0
  86. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741031019972-MigrationName.js.map +1 -0
  87. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.js +42 -0
  88. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1741209339971-MigrationName.js.map +1 -0
  89. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  90. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  91. package/build/dist/Server/Middleware/SlackAuthorization.js +8 -2
  92. package/build/dist/Server/Middleware/SlackAuthorization.js.map +1 -1
  93. package/build/dist/Server/Services/AlertFeedService.js +2 -2
  94. package/build/dist/Server/Services/AlertFeedService.js.map +1 -1
  95. package/build/dist/Server/Services/AlertInternalNoteService.js +2 -2
  96. package/build/dist/Server/Services/AlertInternalNoteService.js.map +1 -1
  97. package/build/dist/Server/Services/AlertOwnerTeamService.js +4 -4
  98. package/build/dist/Server/Services/AlertOwnerTeamService.js.map +1 -1
  99. package/build/dist/Server/Services/AlertOwnerUserService.js +3 -3
  100. package/build/dist/Server/Services/AlertOwnerUserService.js.map +1 -1
  101. package/build/dist/Server/Services/AlertService.js +44 -19
  102. package/build/dist/Server/Services/AlertService.js.map +1 -1
  103. package/build/dist/Server/Services/AlertStateTimelineService.js +6 -16
  104. package/build/dist/Server/Services/AlertStateTimelineService.js.map +1 -1
  105. package/build/dist/Server/Services/IncidentFeedService.js +62 -2
  106. package/build/dist/Server/Services/IncidentFeedService.js.map +1 -1
  107. package/build/dist/Server/Services/IncidentInternalNoteService.js +35 -4
  108. package/build/dist/Server/Services/IncidentInternalNoteService.js.map +1 -1
  109. package/build/dist/Server/Services/IncidentOwnerTeamService.js +42 -4
  110. package/build/dist/Server/Services/IncidentOwnerTeamService.js.map +1 -1
  111. package/build/dist/Server/Services/IncidentOwnerUserService.js +43 -15
  112. package/build/dist/Server/Services/IncidentOwnerUserService.js.map +1 -1
  113. package/build/dist/Server/Services/IncidentPublicNoteService.js +32 -4
  114. package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
  115. package/build/dist/Server/Services/IncidentService.js +221 -170
  116. package/build/dist/Server/Services/IncidentService.js.map +1 -1
  117. package/build/dist/Server/Services/IncidentStateService.js +14 -0
  118. package/build/dist/Server/Services/IncidentStateService.js.map +1 -1
  119. package/build/dist/Server/Services/IncidentStateTimelineService.js +31 -17
  120. package/build/dist/Server/Services/IncidentStateTimelineService.js.map +1 -1
  121. package/build/dist/Server/Services/MonitorStatusTimelineService.js +5 -15
  122. package/build/dist/Server/Services/MonitorStatusTimelineService.js.map +1 -1
  123. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js +1 -0
  124. package/build/dist/Server/Services/OnCallDutyPolicyEscalationRuleService.js.map +1 -1
  125. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js +62 -7
  126. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogService.js.map +1 -1
  127. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js +51 -5
  128. package/build/dist/Server/Services/OnCallDutyPolicyExecutionLogTimelineService.js.map +1 -1
  129. package/build/dist/Server/Services/OnCallDutyPolicyService.js +6 -0
  130. package/build/dist/Server/Services/OnCallDutyPolicyService.js.map +1 -1
  131. package/build/dist/Server/Services/ProjectUserService.js +106 -0
  132. package/build/dist/Server/Services/ProjectUserService.js.map +1 -0
  133. package/build/dist/Server/Services/ScheduledMaintenanceFeedService.js +2 -2
  134. package/build/dist/Server/Services/ScheduledMaintenanceFeedService.js.map +1 -1
  135. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js +2 -2
  136. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js.map +1 -1
  137. package/build/dist/Server/Services/ScheduledMaintenanceOwnerTeamService.js +4 -4
  138. package/build/dist/Server/Services/ScheduledMaintenanceOwnerTeamService.js.map +1 -1
  139. package/build/dist/Server/Services/ScheduledMaintenanceOwnerUserService.js +8 -16
  140. package/build/dist/Server/Services/ScheduledMaintenanceOwnerUserService.js.map +1 -1
  141. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +2 -2
  142. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
  143. package/build/dist/Server/Services/ScheduledMaintenanceService.js +5 -2
  144. package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
  145. package/build/dist/Server/Services/ScheduledMaintenanceStateTimelineService.js +1 -1
  146. package/build/dist/Server/Services/ScheduledMaintenanceStateTimelineService.js.map +1 -1
  147. package/build/dist/Server/Services/StatusPageSubscriberService.js +3 -0
  148. package/build/dist/Server/Services/StatusPageSubscriberService.js.map +1 -1
  149. package/build/dist/Server/Services/TeamMemberService.js +17 -0
  150. package/build/dist/Server/Services/TeamMemberService.js.map +1 -1
  151. package/build/dist/Server/Services/UserNotificationRuleService.js +52 -0
  152. package/build/dist/Server/Services/UserNotificationRuleService.js.map +1 -1
  153. package/build/dist/Server/Services/UserOnCallLogService.js +1 -1
  154. package/build/dist/Server/Services/UserOnCallLogService.js.map +1 -1
  155. package/build/dist/Server/Services/UserService.js +23 -0
  156. package/build/dist/Server/Services/UserService.js.map +1 -1
  157. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +306 -84
  158. package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
  159. package/build/dist/Server/Services/WorkspaceUserAuthTokenService.js +18 -0
  160. package/build/dist/Server/Services/WorkspaceUserAuthTokenService.js.map +1 -1
  161. package/build/dist/Server/Utils/StartServer.js +4 -0
  162. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  163. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.js +148 -0
  164. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/Messages/Incident.js.map +1 -0
  165. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js +19 -0
  166. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js.map +1 -0
  167. package/build/dist/Server/Utils/Workspace/Slack/Actions/Auth.js +167 -0
  168. package/build/dist/Server/Utils/Workspace/Slack/Actions/Auth.js.map +1 -0
  169. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +727 -0
  170. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js.map +1 -0
  171. package/build/dist/Server/Utils/Workspace/Slack/Messages/Incident.js +82 -0
  172. package/build/dist/Server/Utils/Workspace/Slack/Messages/Incident.js.map +1 -0
  173. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +397 -14
  174. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  175. package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +18 -10
  176. package/build/dist/Server/Utils/Workspace/Workspace.js +126 -0
  177. package/build/dist/Server/Utils/Workspace/Workspace.js.map +1 -1
  178. package/build/dist/Server/Utils/Workspace/WorkspaceBase.js +69 -11
  179. package/build/dist/Server/Utils/Workspace/WorkspaceBase.js.map +1 -1
  180. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Incident.js +47 -0
  181. package/build/dist/Server/Utils/Workspace/WorkspaceMessages/Incident.js.map +1 -0
  182. package/build/dist/Types/Icon/IconProp.js +1 -0
  183. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  184. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js +2 -1
  185. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleCondition.js.map +1 -1
  186. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleUtil.js +214 -120
  187. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleUtil.js.map +1 -1
  188. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.js +2 -0
  189. package/build/dist/Types/Workspace/NotificationRules/NotificationRuleWorkspaceChannel.js.map +1 -0
  190. package/build/dist/UI/Components/ComingSoon/ComingSoon.js +3 -2
  191. package/build/dist/UI/Components/ComingSoon/ComingSoon.js.map +1 -1
  192. package/build/dist/UI/Components/Forms/Fields/FormField.js +2 -2
  193. package/build/dist/UI/Components/Forms/Fields/FormField.js.map +1 -1
  194. package/build/dist/UI/Components/Icon/Icon.js +19 -2
  195. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  196. package/build/dist/UI/Components/ModelTable/BaseModelTable.js +11 -0
  197. package/build/dist/UI/Components/ModelTable/BaseModelTable.js.map +1 -1
  198. package/build/dist/UI/Components/Radio/Radio.js +5 -2
  199. package/build/dist/UI/Components/Radio/Radio.js.map +1 -1
  200. package/build/dist/UI/Components/Table/TableCard.js +2 -2
  201. package/build/dist/UI/Components/Table/TableCard.js.map +1 -1
  202. package/package.json +3 -2
  203. package/Server/Utils/Workspace/Slack/app-manifest.example.json +0 -198
@@ -6,12 +6,34 @@ import IncidentFeedService from "./IncidentFeedService";
6
6
  import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed";
7
7
  import { Blue500 } from "../../Types/BrandColors";
8
8
  import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
9
+ import IncidentService from "./IncidentService";
10
+ import Incident from "../../Models/DatabaseModels/Incident";
9
11
 
10
12
  export class Service extends DatabaseService<Model> {
11
13
  public constructor() {
12
14
  super(Model);
13
15
  }
14
16
 
17
+ public async addNote(data: {
18
+ userId: ObjectID;
19
+ incidentId: ObjectID;
20
+ projectId: ObjectID;
21
+ note: string;
22
+ }): Promise<Model> {
23
+ const publicNote: Model = new Model();
24
+ publicNote.createdByUserId = data.userId;
25
+ publicNote.incidentId = data.incidentId;
26
+ publicNote.projectId = data.projectId;
27
+ publicNote.note = data.note;
28
+
29
+ return this.create({
30
+ data: publicNote,
31
+ props: {
32
+ isRoot: true,
33
+ },
34
+ });
35
+ }
36
+
15
37
  public override async onCreateSuccess(
16
38
  _onCreate: OnCreate<Model>,
17
39
  createdItem: Model,
@@ -19,17 +41,28 @@ export class Service extends DatabaseService<Model> {
19
41
  const userId: ObjectID | null | undefined =
20
42
  createdItem.createdByUserId || createdItem.createdByUser?.id;
21
43
 
22
- await IncidentFeedService.createIncidentFeed({
44
+ const incidentId: ObjectID = createdItem.incidentId!;
45
+
46
+ const incidentNumber: number | null =
47
+ await IncidentService.getIncidentNumber({
48
+ incidentId: incidentId,
49
+ });
50
+
51
+ await IncidentFeedService.createIncidentFeedItem({
23
52
  incidentId: createdItem.incidentId!,
24
53
  projectId: createdItem.projectId!,
25
54
  incidentFeedEventType: IncidentFeedEventType.PrivateNote,
26
55
  displayColor: Blue500,
27
56
  userId: userId || undefined,
28
57
 
29
- feedInfoInMarkdown: `**Posted Internal / Private Note**
58
+ feedInfoInMarkdown: `📄 posted **private note** for this [Incident ${incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(createdItem.projectId!, incidentId)).toString()}):
30
59
 
31
60
  ${createdItem.note}
32
61
  `,
62
+ workspaceNotification: {
63
+ sendWorkspaceNotification: true,
64
+ notifyUserId: userId || undefined,
65
+ },
33
66
  });
34
67
 
35
68
  return createdItem;
@@ -49,6 +82,10 @@ ${createdItem.note}
49
82
  },
50
83
  select: {
51
84
  incidentId: true,
85
+ incident: {
86
+ projectId: true,
87
+ incidentNumber: true,
88
+ },
52
89
  projectId: true,
53
90
  note: true,
54
91
  createdByUserId: true,
@@ -62,17 +99,23 @@ ${createdItem.note}
62
99
  onUpdate.updateBy.props.userId;
63
100
 
64
101
  for (const updatedItem of updatedItems) {
65
- await IncidentFeedService.createIncidentFeed({
102
+ const incident: Incident = updatedItem.incident!;
103
+
104
+ await IncidentFeedService.createIncidentFeedItem({
66
105
  incidentId: updatedItem.incidentId!,
67
106
  projectId: updatedItem.projectId!,
68
107
  incidentFeedEventType: IncidentFeedEventType.PrivateNote,
69
108
  displayColor: Blue500,
70
109
  userId: userId || undefined,
71
110
 
72
- feedInfoInMarkdown: `**Updated Internal / Private Note**
111
+ feedInfoInMarkdown: `📄 updated **Private Note** for this [Incident ${incident.incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(incident.projectId!, incident.id!)).toString()})
73
112
 
74
113
  ${updatedItem.note}
75
114
  `,
115
+ workspaceNotification: {
116
+ sendWorkspaceNotification: true,
117
+ notifyUserId: userId || undefined,
118
+ },
76
119
  });
77
120
  }
78
121
  }
@@ -8,6 +8,11 @@ import { Gray500, Red500 } from "../../Types/BrandColors";
8
8
  import TeamService from "./TeamService";
9
9
  import Team from "../../Models/DatabaseModels/Team";
10
10
  import DeleteBy from "../Types/Database/DeleteBy";
11
+ import IncidentService from "./IncidentService";
12
+ import WorkspaceNotificationRuleService from "./WorkspaceNotificationRuleService";
13
+ import NotificationRuleEventType from "../../Types/Workspace/NotificationRules/EventType";
14
+ import WorkspaceNotificationRule from "../../Models/DatabaseModels/WorkspaceNotificationRule";
15
+ import logger from "../Utils/Logger";
11
16
 
12
17
  export class Service extends DatabaseService<Model> {
13
18
  public constructor() {
@@ -64,14 +69,23 @@ export class Service extends DatabaseService<Model> {
64
69
  },
65
70
  });
66
71
 
72
+ const incidentNumber: number | null =
73
+ await IncidentService.getIncidentNumber({
74
+ incidentId: incidentId,
75
+ });
76
+
67
77
  if (team && team.name) {
68
- await IncidentFeedService.createIncidentFeed({
78
+ await IncidentFeedService.createIncidentFeedItem({
69
79
  incidentId: incidentId,
70
80
  projectId: projectId,
71
81
  incidentFeedEventType: IncidentFeedEventType.OwnerTeamRemoved,
72
82
  displayColor: Red500,
73
- feedInfoInMarkdown: `**Team ${team.name}** was removed from the incident as the owner.`,
83
+ feedInfoInMarkdown: `👨🏻‍👩🏻‍👦🏻 Removed team **${team.name}** from the [Incident ${incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(projectId!, incidentId!)).toString()}) as the owner.`,
74
84
  userId: deleteByUserId || undefined,
85
+ workspaceNotification: {
86
+ sendWorkspaceNotification: true,
87
+ notifyUserId: deleteByUserId || undefined,
88
+ },
75
89
  });
76
90
  }
77
91
  }
@@ -104,17 +118,56 @@ export class Service extends DatabaseService<Model> {
104
118
  });
105
119
 
106
120
  if (team && team.name) {
107
- await IncidentFeedService.createIncidentFeed({
121
+ const incidentNumber: number | null =
122
+ await IncidentService.getIncidentNumber({
123
+ incidentId: incidentId,
124
+ });
125
+
126
+ await IncidentFeedService.createIncidentFeedItem({
108
127
  incidentId: incidentId,
109
128
  projectId: projectId,
110
129
  incidentFeedEventType: IncidentFeedEventType.OwnerTeamAdded,
111
130
  displayColor: Gray500,
112
- feedInfoInMarkdown: `**Team ${team.name}** was added to the incident as the owner.`,
131
+ feedInfoInMarkdown: `👨🏻‍👩🏻‍👦🏻 Added team **${team.name}** to the [Incident ${incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(projectId!, incidentId!)).toString()}) as the owner.`,
113
132
  userId: createdByUserId || undefined,
133
+ workspaceNotification: {
134
+ sendWorkspaceNotification: true,
135
+ notifyUserId: createdByUserId || undefined,
136
+ },
114
137
  });
115
138
  }
116
139
  }
117
140
 
141
+ // get notification rule where inviteOwners is true.
142
+ const notificationRules: Array<WorkspaceNotificationRule> =
143
+ await WorkspaceNotificationRuleService.getNotificationRulesWhereInviteOwnersIsTrue(
144
+ {
145
+ projectId: projectId!,
146
+ notificationFor: {
147
+ incidentId: incidentId,
148
+ },
149
+ notificationRuleEventType: NotificationRuleEventType.Incident,
150
+ },
151
+ );
152
+
153
+ logger.debug(`Notification Rules for Incident Owner Teams`);
154
+ logger.debug(notificationRules);
155
+
156
+ WorkspaceNotificationRuleService.inviteTeamsBasedOnRulesAndWorkspaceChannels(
157
+ {
158
+ notificationRules: notificationRules,
159
+ projectId: projectId!,
160
+ workspaceChannels: await IncidentService.getWorkspaceChannelForIncident(
161
+ {
162
+ incidentId: incidentId!,
163
+ },
164
+ ),
165
+ teamIds: [teamId!],
166
+ },
167
+ ).catch((error: Error) => {
168
+ logger.error(error);
169
+ });
170
+
118
171
  return createdItem;
119
172
  }
120
173
  }
@@ -8,6 +8,11 @@ import User from "../../Models/DatabaseModels/User";
8
8
  import UserService from "./UserService";
9
9
  import { OnCreate, OnDelete } from "../Types/Database/Hooks";
10
10
  import DeleteBy from "../Types/Database/DeleteBy";
11
+ import IncidentService from "./IncidentService";
12
+ import WorkspaceNotificationRuleService from "./WorkspaceNotificationRuleService";
13
+ import NotificationRuleEventType from "../../Types/Workspace/NotificationRules/EventType";
14
+ import WorkspaceNotificationRule from "../../Models/DatabaseModels/WorkspaceNotificationRule";
15
+ import logger from "../Utils/Logger";
11
16
 
12
17
  export class Service extends DatabaseService<Model> {
13
18
  public constructor() {
@@ -65,14 +70,23 @@ export class Service extends DatabaseService<Model> {
65
70
  },
66
71
  });
67
72
 
73
+ const incidentNumber: number | null =
74
+ await IncidentService.getIncidentNumber({
75
+ incidentId: incidentId,
76
+ });
77
+
68
78
  if (user && user.name) {
69
- await IncidentFeedService.createIncidentFeed({
79
+ await IncidentFeedService.createIncidentFeedItem({
70
80
  incidentId: incidentId,
71
81
  projectId: projectId,
72
82
  incidentFeedEventType: IncidentFeedEventType.OwnerUserRemoved,
73
83
  displayColor: Red500,
74
- feedInfoInMarkdown: `**${user.name.toString()}** (${user.email?.toString()}) was removed from the incident as the owner.`,
84
+ feedInfoInMarkdown: `👨🏻‍💻 Removed **${user.name.toString()}** (${user.email?.toString()}) from the [Incident ${incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(projectId!, incidentId!)).toString()}) as the owner.`,
75
85
  userId: deleteByUserId || undefined,
86
+ workspaceNotification: {
87
+ sendWorkspaceNotification: true,
88
+ notifyUserId: userId || undefined,
89
+ },
76
90
  });
77
91
  }
78
92
  }
@@ -94,29 +108,59 @@ export class Service extends DatabaseService<Model> {
94
108
  createdItem.createdByUserId || onCreate.createBy.props.userId;
95
109
 
96
110
  if (incidentId && userId && projectId) {
97
- const user: User | null = await UserService.findOneById({
98
- id: userId,
99
- select: {
100
- name: true,
101
- email: true,
102
- },
103
- props: {
104
- isRoot: true,
105
- },
106
- });
111
+ const incidentNumber: number | null =
112
+ await IncidentService.getIncidentNumber({
113
+ incidentId: incidentId,
114
+ });
107
115
 
108
- if (user && user.name) {
109
- await IncidentFeedService.createIncidentFeed({
116
+ if (userId) {
117
+ await IncidentFeedService.createIncidentFeedItem({
110
118
  incidentId: incidentId,
111
119
  projectId: projectId,
112
120
  incidentFeedEventType: IncidentFeedEventType.OwnerUserAdded,
113
121
  displayColor: Gray500,
114
- feedInfoInMarkdown: `**${user.name.toString()}** (${user.email?.toString()}) was added to the incident as the owner.`,
122
+ feedInfoInMarkdown: `👨🏻‍💻 Added **${await UserService.getUserMarkdownString(
123
+ {
124
+ userId: userId,
125
+ projectId: projectId,
126
+ },
127
+ )}** to the [Incident ${incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(projectId!, incidentId!)).toString()}) as the owner.`,
115
128
  userId: createdByUserId || undefined,
129
+ workspaceNotification: {
130
+ sendWorkspaceNotification: true,
131
+ notifyUserId: userId || undefined,
132
+ },
116
133
  });
117
134
  }
118
135
  }
119
136
 
137
+ // get notification rule where inviteOwners is true.
138
+ const notificationRules: Array<WorkspaceNotificationRule> =
139
+ await WorkspaceNotificationRuleService.getNotificationRulesWhereInviteOwnersIsTrue(
140
+ {
141
+ projectId: projectId!,
142
+ notificationFor: {
143
+ incidentId: incidentId,
144
+ },
145
+ notificationRuleEventType: NotificationRuleEventType.Incident,
146
+ },
147
+ );
148
+
149
+ WorkspaceNotificationRuleService.inviteUsersBasedOnRulesAndWorkspaceChannels(
150
+ {
151
+ notificationRules: notificationRules,
152
+ projectId: projectId!,
153
+ workspaceChannels: await IncidentService.getWorkspaceChannelForIncident(
154
+ {
155
+ incidentId: incidentId!,
156
+ },
157
+ ),
158
+ userIds: [userId!],
159
+ },
160
+ ).catch((error: Error) => {
161
+ logger.error(error);
162
+ });
163
+
120
164
  return createdItem;
121
165
  }
122
166
  }
@@ -8,12 +8,34 @@ import { IncidentFeedEventType } from "../../Models/DatabaseModels/IncidentFeed"
8
8
  import { Blue500, Indigo500 } from "../../Types/BrandColors";
9
9
  import ObjectID from "../../Types/ObjectID";
10
10
  import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
11
+ import IncidentService from "./IncidentService";
11
12
 
12
13
  export class Service extends DatabaseService<Model> {
13
14
  public constructor() {
14
15
  super(Model);
15
16
  }
16
17
 
18
+ public async addNote(data: {
19
+ userId: ObjectID;
20
+ incidentId: ObjectID;
21
+ projectId: ObjectID;
22
+ note: string;
23
+ }): Promise<Model> {
24
+ const publicNote: Model = new Model();
25
+ publicNote.createdByUserId = data.userId;
26
+ publicNote.incidentId = data.incidentId;
27
+ publicNote.projectId = data.projectId;
28
+ publicNote.note = data.note;
29
+ publicNote.postedAt = OneUptimeDate.getCurrentDate();
30
+
31
+ return this.create({
32
+ data: publicNote,
33
+ props: {
34
+ isRoot: true,
35
+ },
36
+ });
37
+ }
38
+
17
39
  protected override async onBeforeCreate(
18
40
  createBy: CreateBy<Model>,
19
41
  ): Promise<OnCreate<Model>> {
@@ -34,16 +56,27 @@ export class Service extends DatabaseService<Model> {
34
56
  const userId: ObjectID | null | undefined =
35
57
  createdItem.createdByUserId || createdItem.createdByUser?.id;
36
58
 
37
- await IncidentFeedService.createIncidentFeed({
59
+ const incidentId: ObjectID = createdItem.incidentId!;
60
+ const projectId: ObjectID = createdItem.projectId!;
61
+ const incidentNumber: number | null =
62
+ await IncidentService.getIncidentNumber({
63
+ incidentId: incidentId,
64
+ });
65
+
66
+ await IncidentFeedService.createIncidentFeedItem({
38
67
  incidentId: createdItem.incidentId!,
39
68
  projectId: createdItem.projectId!,
40
69
  incidentFeedEventType: IncidentFeedEventType.PublicNote,
41
70
  displayColor: Indigo500,
42
71
  userId: userId || undefined,
43
- feedInfoInMarkdown: `**Posted public note for this incident on status page**
72
+ feedInfoInMarkdown: `📄 posted **public note** for this [Incident ${incidentNumber}](${(await IncidentService.getIncidentLinkInDashboard(projectId!, incidentId!)).toString()}) on status page:
44
73
 
45
74
  ${createdItem.note}
46
75
  `,
76
+ workspaceNotification: {
77
+ sendWorkspaceNotification: true,
78
+ notifyUserId: userId || undefined,
79
+ },
47
80
  });
48
81
 
49
82
  return createdItem;
@@ -76,17 +109,21 @@ ${createdItem.note}
76
109
  onUpdate.updateBy.props.userId;
77
110
 
78
111
  for (const updatedItem of updatedItems) {
79
- await IncidentFeedService.createIncidentFeed({
112
+ await IncidentFeedService.createIncidentFeedItem({
80
113
  incidentId: updatedItem.incidentId!,
81
114
  projectId: updatedItem.projectId!,
82
115
  incidentFeedEventType: IncidentFeedEventType.PublicNote,
83
116
  displayColor: Blue500,
84
117
  userId: userId || undefined,
85
118
 
86
- feedInfoInMarkdown: `**Updated Public Note**
119
+ feedInfoInMarkdown: `📄 **Updated Public Note**
87
120
 
88
121
  ${updatedItem.note}
89
122
  `,
123
+ workspaceNotification: {
124
+ sendWorkspaceNotification: true,
125
+ notifyUserId: userId || undefined,
126
+ },
90
127
  });
91
128
  }
92
129
  }