-
Notifications
You must be signed in to change notification settings - Fork 75
Expand file tree
/
Copy pathalert-action-select.component.ts
More file actions
228 lines (208 loc) · 8.86 KB
/
Copy pathalert-action-select.component.ts
File metadata and controls
228 lines (208 loc) · 8.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import {Component, EventEmitter, Input, OnDestroy, OnInit, Output} from '@angular/core';
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
import {TranslateService} from '@ngx-translate/core';
import {UtmToastService} from '../../../../../shared/alert/utm-toast.service';
import {AlertIncidentStatusChangeBehavior} from '../../../../../shared/behaviors/alert-incident-status-change.behavior';
import {
CLOSED,
CLOSED_ICON,
IGNORED,
IGNORED_ICON,
OPEN,
OPEN_ICON,
REVIEW,
REVIEW_ICON
} from '../../../../../shared/constants/alert/alert-status.constant';
import {UtmIncidentAlertsService} from '../../../../../shared/services/incidents/utm-incident-alerts.service';
import {AlertStatusEnum, UtmAlertType} from '../../../../../shared/types/alert/utm-alert.type';
import {AlertIncidentStatusUpdateType} from '../../../../../shared/types/incident/alert-incident-status-update.type';
import {AlertStatusBehavior} from '../../behavior/alert-status.behavior';
import {AlertUpdateHistoryBehavior} from '../../behavior/alert-update-history.behavior';
import {EventDataTypeEnum} from '../../enums/event-data-type.enum';
import {AlertManagementService} from '../../services/alert-management.service';
import {getStatusName} from '../../util/alert-util-function';
import {AlertCompleteComponent} from '../alert-complete/alert-complete.component';
export enum AlertActionType {
ADD_OR_CREATE_INCIDENT,
ADD_FALSE_POSITIVE_TAG_RULE,
ADD_INCIDENT,
CREATE_INCIDENT
}
export interface AlertAction {
label: string;
value?: AlertStatusEnum;
group: string;
subActions?: AlertAction[];
icon?: string;
background?: string;
action?: AlertActionType;
}
@Component({
selector: 'app-alert-action-select',
templateUrl: './alert-action-select.component.html',
styleUrls: ['./alert-action-select.component.css']
})
export class AlertActionSelectComponent implements OnInit, OnDestroy {
@Input() alert: UtmAlertType;
@Input() showDrop: boolean;
@Input() statusField: string;
@Output() statusChange = new EventEmitter<number>();
@Input() status: number;
@Input() tags: any[];
@Input() dataType: EventDataTypeEnum;
rawActions: AlertAction[] = [
{ label: 'Open', value: AlertStatusEnum.OPEN , group: 'Estado', icon: OPEN_ICON, background: 'border-success-400 text-success-400' },
{ label: 'In Review', value: AlertStatusEnum.IN_REVIEW, group: 'Estado',
icon: REVIEW_ICON, background: 'border-info-400 text-info-400' },
{label: 'Completed', value: AlertStatusEnum.COMPLETED, group: 'Estado', icon: CLOSED_ICON,
background: 'border-blue-800 text-blue-800'},
{label: 'Completed as False Positive', value: AlertStatusEnum.COMPLETED_AS_FALSE_POSITIVE, group: 'Estado', icon: 'icon-checkmark',
background: 'border-warning-400 text-warning-800'},
/*subActions: [
{ label: 'Completed', value: 'completed_plain', group: 'Estado', icon: CLOSED_ICON,
background: 'border-blue-800 text-blue-800', },
{ label: 'Completed – Has False Positive', value: 'completed_fp', group: 'Estado', icon: CLOSED_ICON,
background: 'border-blue-800 text-blue-800', }
]*/
{ label: 'Manage Incident',
value: AlertStatusEnum.AUTOMATIC_REVIEW,
group: 'Acciones',
icon: 'icon-target',
background: 'border-blue-800 text-blue-800',
action: AlertActionType.ADD_OR_CREATE_INCIDENT,
subActions: [
{ label: 'Add to Incident', group: 'Estado', icon: 'icon-make-group',
background: 'border-blue-800 text-blue-800', action: AlertActionType.ADD_INCIDENT },
{ label: 'Create an Incident', group: 'Estado', icon: 'icon-plus2',
background: 'border-blue-800 text-blue-800', action: AlertActionType.CREATE_INCIDENT },
]},
{ label: 'Create False Positive Rule', value: AlertStatusEnum.AUTOMATIC_REVIEW, group: 'Acciones',
icon: 'icon-price-tag3', background: 'border-blue-800 text-blue-800', action: AlertActionType.ADD_FALSE_POSITIVE_TAG_RULE },
];
actionGroups: { [group: string]: AlertAction[] } = {};
icon: string;
background: string;
label: string;
changing = false;
isIncident: boolean;
incidentId: number;
AlertActionType = AlertActionType;
constructor(private alertServiceManagement: AlertManagementService,
private modalService: NgbModal,
private translate: TranslateService,
private alertUpdateHistoryBehavior: AlertUpdateHistoryBehavior,
private updateStatusServiceBehavior: AlertStatusBehavior,
private alertIncidentStatusChangeBehavior: AlertIncidentStatusChangeBehavior,
private utmIncidentAlertsService: UtmIncidentAlertsService,
private utmToastService: UtmToastService) { }
ngOnInit() {
this.actionGroups = this.rawActions.reduce((acc, action) => {
if (!acc[action.group]) { acc[action.group] = []; }
acc[action.group].push(action);
return acc;
}, {} as { [group: string]: AlertAction[] });
if (typeof this.status === 'string') {
this.status = Number(this.status);
}
if (!this.status) {
this.status = this.alert.status;
}
this.isIncident = this.alert.isIncident;
if (this.isIncident) {
this.incidentId = Number(this.alert.incidentDetail.incidentId);
}
this.resolveAlert();
}
handleAction(action: any) {
}
private resolveAlert() {
switch (this.status) {
case OPEN:
this.icon = OPEN_ICON;
this.background = 'border-success-400 text-success-400';
this.label = 'alertStatus.open';
break;
case REVIEW:
this.icon = REVIEW_ICON;
this.background = 'border-info-400 text-info-400';
this.label = 'alertStatus.inReview';
break;
case CLOSED:
this.icon = CLOSED_ICON;
this.background = 'border-blue-800 text-blue-800';
this.label = 'alertStatus.closed';
break;
case IGNORED:
this.icon = IGNORED_ICON;
this.background = 'border-warning-400 text-warning-400';
this.label = 'alertStatus.ignored';
break;
default:
this.icon = 'icon-hammer';
this.background = 'border-slate-800 text-slate-800';
this.label = 'alertStatus.pending';
break;
}
}
changeStatus(status: number) {
const alert = this.alert;
this.changing = true;
if (status === AlertStatusEnum.COMPLETED || status === AlertStatusEnum.COMPLETED_AS_FALSE_POSITIVE) {
const modalRef = this.modalService.open(AlertCompleteComponent, {centered: true});
modalRef.componentInstance.alertsIDs = [alert.id];
modalRef.componentInstance.canCreateRule = true;
modalRef.componentInstance.status = AlertStatusEnum.COMPLETED;
modalRef.componentInstance.asFalsePositive = status === AlertStatusEnum.COMPLETED_AS_FALSE_POSITIVE;
modalRef.componentInstance.alert = this.alert;
modalRef.componentInstance.statusClose.subscribe(() => {
this.changing = false;
});
modalRef.componentInstance.statusChange.subscribe((statusChange) => {
this.changing = false;
if (statusChange === 'success') {
this.statusChange.emit(status);
this.alertUpdateHistoryBehavior.$refreshHistory.next(true);
this.statusChangedSuccess(status);
this.syncIncidentAlertStatus([this.alert.id], status);
} else {
this.changing = false;
this.utmToastService.showError('Error', 'An error occurred while changing the alert status. Please try again later.');
}
});
} else {
this.alertServiceManagement.updateAlertStatus([this.alert.id], status).subscribe(al => {
this.statusChangedSuccess(status);
this.changing = false;
this.alertUpdateHistoryBehavior.$refreshHistory.next(true);
this.syncIncidentAlertStatus([this.alert.id], status);
}, () => {
this.changing = false;
this.utmToastService.showError('Error', 'An error occurred while changing the alert status. Please try again later.');
});
}
}
statusChangedSuccess(status) {
this.updateStatusServiceBehavior.$updateStatus.next(true);
this.status = status;
this.resolveAlert();
this.statusChange.emit(status);
const msg = getStatusName(status);
this.translate.get(['toast.changeAlertStatus', msg]).subscribe(value => {
this.utmToastService.showSuccessBottom(value['toast.changeAlertStatus'] + ' ' + value[msg].toString().toUpperCase());
});
}
syncIncidentAlertStatus(alerts: string[], status: number) {
if (this.isIncident) {
const update: AlertIncidentStatusUpdateType = {
status,
incidentId: Number(this.incidentId),
alertIds: alerts
};
this.utmIncidentAlertsService.updateIncidentAlertStatus(update).subscribe(() => {
this.alertIncidentStatusChangeBehavior.$incidentAlertChange.next(this.incidentId);
});
}
}
ngOnDestroy(): void {
}
}