@oneuptime/common 7.0.5098 → 8.0.5124
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.
- package/Server/Services/AlertService.ts +124 -109
- package/Server/Services/IncidentService.ts +123 -89
- package/Server/Services/MonitorService.ts +114 -97
- package/Server/Services/ScheduledMaintenanceService.ts +82 -67
- package/Server/Services/WorkspaceNotificationRuleService.ts +112 -85
- package/Server/Utils/Workspace/Slack/Slack.ts +0 -11
- package/Server/Utils/Workspace/Workspace.ts +2 -2
- package/build/dist/Server/Services/AlertService.js +107 -81
- package/build/dist/Server/Services/AlertService.js.map +1 -1
- package/build/dist/Server/Services/IncidentService.js +98 -56
- package/build/dist/Server/Services/IncidentService.js.map +1 -1
- package/build/dist/Server/Services/MonitorService.js +77 -55
- package/build/dist/Server/Services/MonitorService.js.map +1 -1
- package/build/dist/Server/Services/ScheduledMaintenanceService.js +64 -43
- package/build/dist/Server/Services/ScheduledMaintenanceService.js.map +1 -1
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js +88 -70
- package/build/dist/Server/Services/WorkspaceNotificationRuleService.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js +0 -8
- package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
- package/build/dist/Server/Utils/Workspace/Workspace.js +2 -2
- package/build/dist/Server/Utils/Workspace/Workspace.js.map +1 -1
- package/package.json +1 -1
|
@@ -504,105 +504,122 @@ ${createdItem.description?.trim() || "No description provided."}
|
|
|
504
504
|
feedInfoInMarkdown += `\n\n`;
|
|
505
505
|
}
|
|
506
506
|
|
|
507
|
-
//
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
})
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
507
|
+
// Execute operations sequentially with error handling (workspace first)
|
|
508
|
+
Promise.resolve()
|
|
509
|
+
.then(async () => {
|
|
510
|
+
try {
|
|
511
|
+
return await this.handleWorkspaceOperationsAsync({
|
|
512
|
+
projectId: createdItem.projectId!,
|
|
513
|
+
monitorId: createdItem.id!,
|
|
514
|
+
monitorName: createdItem.name!,
|
|
515
|
+
feedInfoInMarkdown,
|
|
516
|
+
createdByUserId,
|
|
517
|
+
});
|
|
518
|
+
} catch (error) {
|
|
519
|
+
logger.error(
|
|
520
|
+
"Workspace operations failed in MonitorService.onCreateSuccess",
|
|
521
|
+
);
|
|
522
|
+
logger.error(error as Error);
|
|
523
|
+
return Promise.resolve();
|
|
524
|
+
}
|
|
525
|
+
})
|
|
526
|
+
.then(async () => {
|
|
527
|
+
try {
|
|
528
|
+
return await this.changeMonitorStatus(
|
|
529
|
+
createdItem.projectId!,
|
|
530
|
+
[createdItem.id!],
|
|
531
|
+
createdItem.currentMonitorStatusId!,
|
|
532
|
+
false, // notifyOwners = false
|
|
533
|
+
"This status was created when the monitor was created.",
|
|
534
|
+
undefined,
|
|
535
|
+
onCreate.createBy.props,
|
|
536
|
+
);
|
|
537
|
+
} catch (error) {
|
|
538
|
+
logger.error(
|
|
539
|
+
"Change monitor status failed in MonitorService.onCreateSuccess",
|
|
540
|
+
);
|
|
541
|
+
logger.error(error as Error);
|
|
542
|
+
return Promise.resolve();
|
|
543
|
+
}
|
|
544
|
+
})
|
|
545
|
+
.then(async () => {
|
|
546
|
+
try {
|
|
547
|
+
if (
|
|
548
|
+
createdItem.monitorType &&
|
|
549
|
+
MonitorTypeHelper.isProbableMonitor(createdItem.monitorType)
|
|
550
|
+
) {
|
|
551
|
+
return await this.addDefaultProbesToMonitor(
|
|
552
|
+
createdItem.projectId!,
|
|
553
|
+
createdItem.id!,
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
return Promise.resolve();
|
|
557
|
+
} catch (error) {
|
|
558
|
+
logger.error(
|
|
559
|
+
"Add default probes failed in MonitorService.onCreateSuccess",
|
|
560
|
+
);
|
|
561
|
+
logger.error(error as Error);
|
|
562
|
+
return Promise.resolve();
|
|
563
|
+
}
|
|
564
|
+
})
|
|
565
|
+
.then(async () => {
|
|
566
|
+
try {
|
|
567
|
+
if (IsBillingEnabled) {
|
|
568
|
+
return await ActiveMonitoringMeteredPlan.reportQuantityToBillingProvider(
|
|
569
|
+
createdItem.projectId!,
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
return Promise.resolve();
|
|
573
|
+
} catch (error) {
|
|
574
|
+
logger.error(
|
|
575
|
+
"Billing operations failed in MonitorService.onCreateSuccess",
|
|
576
|
+
);
|
|
577
|
+
logger.error(error as Error);
|
|
578
|
+
return Promise.resolve();
|
|
579
|
+
}
|
|
580
|
+
})
|
|
581
|
+
.then(async () => {
|
|
582
|
+
try {
|
|
583
|
+
if (
|
|
584
|
+
onCreate.createBy.miscDataProps &&
|
|
585
|
+
(onCreate.createBy.miscDataProps["ownerTeams"] ||
|
|
586
|
+
onCreate.createBy.miscDataProps["ownerUsers"])
|
|
587
|
+
) {
|
|
588
|
+
return await this.addOwners(
|
|
589
|
+
createdItem.projectId!,
|
|
590
|
+
createdItem.id!,
|
|
591
|
+
(onCreate.createBy.miscDataProps[
|
|
592
|
+
"ownerUsers"
|
|
593
|
+
] as Array<ObjectID>) || [],
|
|
594
|
+
(onCreate.createBy.miscDataProps[
|
|
595
|
+
"ownerTeams"
|
|
596
|
+
] as Array<ObjectID>) || [],
|
|
597
|
+
false,
|
|
598
|
+
onCreate.createBy.props,
|
|
599
|
+
);
|
|
600
|
+
}
|
|
601
|
+
return Promise.resolve();
|
|
602
|
+
} catch (error) {
|
|
603
|
+
logger.error("Add owners failed in MonitorService.onCreateSuccess");
|
|
604
|
+
logger.error(error as Error);
|
|
605
|
+
return Promise.resolve();
|
|
606
|
+
}
|
|
607
|
+
})
|
|
608
|
+
.then(async () => {
|
|
609
|
+
try {
|
|
610
|
+
return await this.refreshMonitorProbeStatus(createdItem.id!);
|
|
611
|
+
} catch (error) {
|
|
612
|
+
logger.error(
|
|
613
|
+
"Refresh probe status failed in MonitorService.onCreateSuccess",
|
|
614
|
+
);
|
|
615
|
+
logger.error(error as Error);
|
|
616
|
+
return Promise.resolve();
|
|
617
|
+
}
|
|
602
618
|
})
|
|
603
619
|
.catch((error: Error) => {
|
|
604
|
-
logger.error(
|
|
605
|
-
|
|
620
|
+
logger.error(
|
|
621
|
+
`Critical error in MonitorService sequential operations: ${error}`,
|
|
622
|
+
);
|
|
606
623
|
});
|
|
607
624
|
|
|
608
625
|
return createdItem;
|
|
@@ -610,6 +610,12 @@ ${resourcesAffected ? `**Resources Affected:** ${resourcesAffected}` : ""}
|
|
|
610
610
|
labels: {
|
|
611
611
|
name: true,
|
|
612
612
|
},
|
|
613
|
+
createdByUserId: true,
|
|
614
|
+
createdByUser: {
|
|
615
|
+
_id: true,
|
|
616
|
+
name: true,
|
|
617
|
+
email: true,
|
|
618
|
+
},
|
|
613
619
|
},
|
|
614
620
|
props: {
|
|
615
621
|
isRoot: true,
|
|
@@ -620,71 +626,80 @@ ${resourcesAffected ? `**Resources Affected:** ${resourcesAffected}` : ""}
|
|
|
620
626
|
throw new BadDataException("Scheduled Maintenance not found");
|
|
621
627
|
}
|
|
622
628
|
|
|
623
|
-
// Execute
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
createdItem,
|
|
631
|
-
),
|
|
632
|
-
);
|
|
633
|
-
|
|
634
|
-
// Create state timeline asynchronously
|
|
635
|
-
coreOperations.push(
|
|
636
|
-
this.createScheduledMaintenanceStateTimelineAsync(createdItem),
|
|
637
|
-
);
|
|
638
|
-
|
|
639
|
-
// Handle owner assignment asynchronously
|
|
640
|
-
if (
|
|
641
|
-
createdItem.projectId &&
|
|
642
|
-
createdItem.id &&
|
|
643
|
-
onCreate.createBy.miscDataProps &&
|
|
644
|
-
(onCreate.createBy.miscDataProps["ownerTeams"] ||
|
|
645
|
-
onCreate.createBy.miscDataProps["ownerUsers"])
|
|
646
|
-
) {
|
|
647
|
-
coreOperations.push(
|
|
648
|
-
this.addOwners(
|
|
649
|
-
createdItem.projectId!,
|
|
650
|
-
createdItem.id!,
|
|
651
|
-
(onCreate.createBy.miscDataProps["ownerUsers"] as Array<ObjectID>) ||
|
|
652
|
-
[],
|
|
653
|
-
(onCreate.createBy.miscDataProps["ownerTeams"] as Array<ObjectID>) ||
|
|
654
|
-
[],
|
|
655
|
-
false,
|
|
656
|
-
onCreate.createBy.props,
|
|
657
|
-
),
|
|
658
|
-
);
|
|
659
|
-
}
|
|
660
|
-
|
|
661
|
-
// Execute core operations in parallel with error handling
|
|
662
|
-
Promise.allSettled(coreOperations)
|
|
663
|
-
.then((coreResults: any[]) => {
|
|
664
|
-
// Log any errors from core operations
|
|
665
|
-
coreResults.forEach((result: any, index: number) => {
|
|
666
|
-
if (result.status === "rejected") {
|
|
667
|
-
logger.error(
|
|
668
|
-
`Core operation ${index} failed in ScheduledMaintenanceService.onCreateSuccess: ${result.reason}`,
|
|
629
|
+
// Execute operations sequentially with error handling
|
|
630
|
+
Promise.resolve()
|
|
631
|
+
.then(async () => {
|
|
632
|
+
try {
|
|
633
|
+
if (createdItem.projectId && createdItem.id) {
|
|
634
|
+
return await this.handleScheduledMaintenanceWorkspaceOperationsAsync(
|
|
635
|
+
createdItem,
|
|
669
636
|
);
|
|
670
637
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
638
|
+
return Promise.resolve();
|
|
639
|
+
} catch (error) {
|
|
640
|
+
logger.error(
|
|
641
|
+
`Workspace operations failed in ScheduledMaintenanceService.onCreateSuccess: ${error}`,
|
|
642
|
+
);
|
|
643
|
+
return Promise.resolve();
|
|
644
|
+
}
|
|
645
|
+
})
|
|
646
|
+
.then(async () => {
|
|
647
|
+
try {
|
|
648
|
+
return await this.createScheduledMaintenanceFeedAsync(
|
|
649
|
+
scheduledMaintenance,
|
|
650
|
+
);
|
|
651
|
+
} catch (error) {
|
|
652
|
+
logger.error(
|
|
653
|
+
`Create scheduled maintenance feed failed in ScheduledMaintenanceService.onCreateSuccess: ${error}`,
|
|
654
|
+
);
|
|
655
|
+
return Promise.resolve();
|
|
656
|
+
}
|
|
657
|
+
})
|
|
658
|
+
.then(async () => {
|
|
659
|
+
try {
|
|
660
|
+
return await this.createScheduledMaintenanceStateTimelineAsync(
|
|
677
661
|
createdItem,
|
|
678
|
-
)
|
|
679
|
-
|
|
680
|
-
|
|
662
|
+
);
|
|
663
|
+
} catch (error) {
|
|
664
|
+
logger.error(
|
|
665
|
+
`Create scheduled maintenance state timeline failed in ScheduledMaintenanceService.onCreateSuccess: ${error}`,
|
|
666
|
+
);
|
|
667
|
+
return Promise.resolve();
|
|
668
|
+
}
|
|
669
|
+
})
|
|
670
|
+
.then(async () => {
|
|
671
|
+
try {
|
|
672
|
+
if (
|
|
673
|
+
createdItem.projectId &&
|
|
674
|
+
createdItem.id &&
|
|
675
|
+
onCreate.createBy.miscDataProps &&
|
|
676
|
+
(onCreate.createBy.miscDataProps["ownerTeams"] ||
|
|
677
|
+
onCreate.createBy.miscDataProps["ownerUsers"])
|
|
678
|
+
) {
|
|
679
|
+
return await this.addOwners(
|
|
680
|
+
createdItem.projectId!,
|
|
681
|
+
createdItem.id!,
|
|
682
|
+
(onCreate.createBy.miscDataProps[
|
|
683
|
+
"ownerUsers"
|
|
684
|
+
] as Array<ObjectID>) || [],
|
|
685
|
+
(onCreate.createBy.miscDataProps[
|
|
686
|
+
"ownerTeams"
|
|
687
|
+
] as Array<ObjectID>) || [],
|
|
688
|
+
false,
|
|
689
|
+
onCreate.createBy.props,
|
|
681
690
|
);
|
|
682
|
-
}
|
|
691
|
+
}
|
|
692
|
+
return Promise.resolve();
|
|
693
|
+
} catch (error) {
|
|
694
|
+
logger.error(
|
|
695
|
+
`Add owners failed in ScheduledMaintenanceService.onCreateSuccess: ${error}`,
|
|
696
|
+
);
|
|
697
|
+
return Promise.resolve();
|
|
683
698
|
}
|
|
684
699
|
})
|
|
685
700
|
.catch((error: Error) => {
|
|
686
701
|
logger.error(
|
|
687
|
-
`Critical error in ScheduledMaintenanceService
|
|
702
|
+
`Critical error in ScheduledMaintenanceService sequential operations: ${error}`,
|
|
688
703
|
);
|
|
689
704
|
});
|
|
690
705
|
|
|
@@ -738,17 +753,17 @@ ${resourcesAffected ? `**Resources Affected:** ${resourcesAffected}` : ""}
|
|
|
738
753
|
@CaptureSpan()
|
|
739
754
|
private async createScheduledMaintenanceFeedAsync(
|
|
740
755
|
scheduledMaintenance: Model,
|
|
741
|
-
createdItem: Model,
|
|
742
756
|
): Promise<void> {
|
|
743
757
|
try {
|
|
744
758
|
const createdByUserId: ObjectID | undefined | null =
|
|
745
|
-
|
|
759
|
+
scheduledMaintenance.createdByUserId ||
|
|
760
|
+
scheduledMaintenance.createdByUser?.id;
|
|
746
761
|
|
|
747
|
-
let feedInfoInMarkdown: string = `#### 🕒 Scheduled Maintenance ${
|
|
762
|
+
let feedInfoInMarkdown: string = `#### 🕒 Scheduled Maintenance ${scheduledMaintenance.scheduledMaintenanceNumber?.toString()} Created:
|
|
748
763
|
|
|
749
|
-
**${
|
|
764
|
+
**${scheduledMaintenance.title || "No title provided."}**:
|
|
750
765
|
|
|
751
|
-
${
|
|
766
|
+
${scheduledMaintenance.description || "No description provided."}
|
|
752
767
|
|
|
753
768
|
`;
|
|
754
769
|
|
|
@@ -772,7 +787,7 @@ ${createdItem.description || "No description provided."}
|
|
|
772
787
|
feedInfoInMarkdown += `🌎 **Resources Affected**:\n`;
|
|
773
788
|
|
|
774
789
|
for (const monitor of scheduledMaintenance.monitors) {
|
|
775
|
-
feedInfoInMarkdown += `- [${monitor.name}](${(await MonitorService.getMonitorLinkInDashboard(
|
|
790
|
+
feedInfoInMarkdown += `- [${monitor.name}](${(await MonitorService.getMonitorLinkInDashboard(scheduledMaintenance.projectId!, monitor.id!)).toString()})\n`;
|
|
776
791
|
}
|
|
777
792
|
|
|
778
793
|
feedInfoInMarkdown += `\n\n`;
|
|
@@ -781,14 +796,14 @@ ${createdItem.description || "No description provided."}
|
|
|
781
796
|
const scheduledMaintenanceCreateMessageBlocks: Array<MessageBlocksByWorkspaceType> =
|
|
782
797
|
await ScheduledMaintenanceWorkspaceMessages.getScheduledMaintenanceCreateMessageBlocks(
|
|
783
798
|
{
|
|
784
|
-
scheduledMaintenanceId:
|
|
785
|
-
projectId:
|
|
799
|
+
scheduledMaintenanceId: scheduledMaintenance.id!,
|
|
800
|
+
projectId: scheduledMaintenance.projectId!,
|
|
786
801
|
},
|
|
787
802
|
);
|
|
788
803
|
|
|
789
804
|
await ScheduledMaintenanceFeedService.createScheduledMaintenanceFeedItem({
|
|
790
|
-
scheduledMaintenanceId:
|
|
791
|
-
projectId:
|
|
805
|
+
scheduledMaintenanceId: scheduledMaintenance.id!,
|
|
806
|
+
projectId: scheduledMaintenance.projectId!,
|
|
792
807
|
scheduledMaintenanceFeedEventType:
|
|
793
808
|
ScheduledMaintenanceFeedEventType.ScheduledMaintenanceCreated,
|
|
794
809
|
displayColor: Red500,
|
|
@@ -611,6 +611,9 @@ export class Service extends DatabaseService<WorkspaceNotificationRule> {
|
|
|
611
611
|
notificationFor: NotificationFor;
|
|
612
612
|
workspaceType: WorkspaceType;
|
|
613
613
|
}): Promise<Array<WorkspaceChannel>> {
|
|
614
|
+
logger.debug("getWorkspaceChannelsByNotificationFor called with data:");
|
|
615
|
+
logger.debug(JSON.stringify(data, null, 2));
|
|
616
|
+
|
|
614
617
|
let monitorChannels: Array<WorkspaceChannel> = [];
|
|
615
618
|
|
|
616
619
|
if (data.notificationFor.monitorId) {
|
|
@@ -654,6 +657,10 @@ export class Service extends DatabaseService<WorkspaceNotificationRule> {
|
|
|
654
657
|
},
|
|
655
658
|
);
|
|
656
659
|
}
|
|
660
|
+
|
|
661
|
+
logger.debug("Workspace channels found:");
|
|
662
|
+
logger.debug(monitorChannels);
|
|
663
|
+
|
|
657
664
|
return monitorChannels;
|
|
658
665
|
}
|
|
659
666
|
|
|
@@ -758,112 +765,132 @@ export class Service extends DatabaseService<WorkspaceNotificationRule> {
|
|
|
758
765
|
}): Promise<{
|
|
759
766
|
channelsCreated: Array<NotificationRuleWorkspaceChannel>;
|
|
760
767
|
} | null> {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
768
|
+
try {
|
|
769
|
+
logger.debug(
|
|
770
|
+
"WorkspaceNotificationRuleService.createInviteAndPostToChannelsBasedOnRules",
|
|
771
|
+
);
|
|
772
|
+
logger.debug(data);
|
|
765
773
|
|
|
766
|
-
|
|
774
|
+
const channelsCreated: Array<NotificationRuleWorkspaceChannel> = [];
|
|
767
775
|
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
logger.debug("projectAuths");
|
|
774
|
-
logger.debug(projectAuths);
|
|
776
|
+
const projectAuths: Array<WorkspaceProjectAuthToken> =
|
|
777
|
+
await WorkspaceProjectAuthTokenService.getProjectAuths({
|
|
778
|
+
projectId: data.projectId,
|
|
779
|
+
});
|
|
775
780
|
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
return null;
|
|
779
|
-
}
|
|
781
|
+
logger.debug("projectAuths");
|
|
782
|
+
logger.debug(projectAuths);
|
|
780
783
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
+
if (!projectAuths || projectAuths.length === 0) {
|
|
785
|
+
// do nothing.
|
|
786
|
+
return null;
|
|
784
787
|
}
|
|
785
788
|
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
+
for (const projectAuth of projectAuths) {
|
|
790
|
+
try {
|
|
791
|
+
if (!projectAuth.authToken) {
|
|
792
|
+
continue;
|
|
793
|
+
}
|
|
789
794
|
|
|
790
|
-
|
|
791
|
-
|
|
795
|
+
if (!projectAuth.workspaceType) {
|
|
796
|
+
continue;
|
|
797
|
+
}
|
|
792
798
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
projectId: data.projectId,
|
|
796
|
-
workspaceType: workspaceType,
|
|
797
|
-
notificationRuleEventType: data.notificationRuleEventType,
|
|
798
|
-
notificationFor: data.notificationFor,
|
|
799
|
-
});
|
|
799
|
+
const authToken: string = projectAuth.authToken;
|
|
800
|
+
const workspaceType: WorkspaceType = projectAuth.workspaceType;
|
|
800
801
|
|
|
801
|
-
|
|
802
|
-
|
|
802
|
+
const notificationRules: Array<WorkspaceNotificationRule> =
|
|
803
|
+
await this.getMatchingNotificationRules({
|
|
804
|
+
projectId: data.projectId,
|
|
805
|
+
workspaceType: workspaceType,
|
|
806
|
+
notificationRuleEventType: data.notificationRuleEventType,
|
|
807
|
+
notificationFor: data.notificationFor,
|
|
808
|
+
});
|
|
803
809
|
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
}
|
|
810
|
+
logger.debug("notificationRules");
|
|
811
|
+
logger.debug(notificationRules);
|
|
807
812
|
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
projectId: data.projectId,
|
|
812
|
-
projectOrUserAuthTokenForWorkspace: authToken,
|
|
813
|
-
workspaceType: workspaceType,
|
|
814
|
-
notificationRules: notificationRules,
|
|
815
|
-
channelNameSiffix: data.channelNameSiffix,
|
|
816
|
-
notificationEventType: data.notificationRuleEventType,
|
|
817
|
-
notificationFor: data.notificationFor,
|
|
818
|
-
});
|
|
813
|
+
if (!notificationRules || notificationRules.length === 0) {
|
|
814
|
+
return null;
|
|
815
|
+
}
|
|
819
816
|
|
|
820
|
-
|
|
821
|
-
|
|
817
|
+
logger.debug("Creating channels based on rules");
|
|
818
|
+
const createdWorkspaceChannels: Array<NotificationRuleWorkspaceChannel> =
|
|
819
|
+
await this.createChannelsBasedOnRules({
|
|
820
|
+
projectId: data.projectId,
|
|
821
|
+
projectOrUserAuthTokenForWorkspace: authToken,
|
|
822
|
+
workspaceType: workspaceType,
|
|
823
|
+
notificationRules: notificationRules,
|
|
824
|
+
channelNameSiffix: data.channelNameSiffix,
|
|
825
|
+
notificationEventType: data.notificationRuleEventType,
|
|
826
|
+
notificationFor: data.notificationFor,
|
|
827
|
+
});
|
|
822
828
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
projectId: data.projectId,
|
|
826
|
-
projectAuth: projectAuth,
|
|
827
|
-
workspaceType: workspaceType,
|
|
828
|
-
notificationRules: notificationRules,
|
|
829
|
-
notificationChannels: createdWorkspaceChannels,
|
|
830
|
-
});
|
|
829
|
+
logger.debug("createdWorkspaceChannels");
|
|
830
|
+
logger.debug(createdWorkspaceChannels);
|
|
831
831
|
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
)
|
|
840
|
-
}) || [];
|
|
832
|
+
logger.debug("Inviting users and teams to channels based on rules");
|
|
833
|
+
await this.inviteUsersAndTeamsToChannelsBasedOnRules({
|
|
834
|
+
projectId: data.projectId,
|
|
835
|
+
projectAuth: projectAuth,
|
|
836
|
+
workspaceType: workspaceType,
|
|
837
|
+
notificationRules: notificationRules,
|
|
838
|
+
notificationChannels: createdWorkspaceChannels,
|
|
839
|
+
});
|
|
841
840
|
|
|
842
|
-
|
|
843
|
-
|
|
841
|
+
logger.debug(
|
|
842
|
+
"Getting existing channel names from notification rules",
|
|
843
|
+
);
|
|
844
|
+
const existingChannelNames: Array<string> =
|
|
845
|
+
this.getExistingChannelNamesFromNotificationRules({
|
|
846
|
+
notificationRules: notificationRules.map(
|
|
847
|
+
(rule: WorkspaceNotificationRule) => {
|
|
848
|
+
return rule.notificationRule as BaseNotificationRule;
|
|
849
|
+
},
|
|
850
|
+
),
|
|
851
|
+
}) || [];
|
|
844
852
|
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
if (!existingChannelNames.includes(channel.name)) {
|
|
848
|
-
existingChannelNames.push(channel.name);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
853
|
+
logger.debug("Existing channel names:");
|
|
854
|
+
logger.debug(existingChannelNames);
|
|
851
855
|
|
|
852
|
-
|
|
853
|
-
|
|
856
|
+
logger.debug(
|
|
857
|
+
"Adding created channel names to existing channel names",
|
|
858
|
+
);
|
|
859
|
+
for (const channel of createdWorkspaceChannels) {
|
|
860
|
+
if (!existingChannelNames.includes(channel.name)) {
|
|
861
|
+
existingChannelNames.push(channel.name);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
854
864
|
|
|
855
|
-
|
|
865
|
+
logger.debug("Final list of channel names to post messages to:");
|
|
866
|
+
logger.debug(existingChannelNames);
|
|
856
867
|
|
|
857
|
-
|
|
858
|
-
logger.debug(createdWorkspaceChannels);
|
|
868
|
+
logger.debug("Posting messages to workspace channels");
|
|
859
869
|
|
|
860
|
-
|
|
861
|
-
|
|
870
|
+
logger.debug("Channels created:");
|
|
871
|
+
logger.debug(createdWorkspaceChannels);
|
|
862
872
|
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
873
|
+
channelsCreated.push(...createdWorkspaceChannels);
|
|
874
|
+
} catch (err) {
|
|
875
|
+
logger.error(
|
|
876
|
+
"Error in creating channels and inviting users to channels for workspace type " +
|
|
877
|
+
projectAuth.workspaceType,
|
|
878
|
+
);
|
|
879
|
+
logger.error(err);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
logger.debug("Returning created channels");
|
|
884
|
+
return {
|
|
885
|
+
channelsCreated: channelsCreated,
|
|
886
|
+
};
|
|
887
|
+
} catch (err) {
|
|
888
|
+
logger.error(
|
|
889
|
+
"Error in createChannelsAndInviteUsersToChannelsBasedOnRules:",
|
|
890
|
+
);
|
|
891
|
+
logger.error(err);
|
|
892
|
+
return null;
|
|
893
|
+
}
|
|
867
894
|
}
|
|
868
895
|
|
|
869
896
|
@CaptureSpan()
|