Skip to content

Commit 85c20b0

Browse files
committed
Improvements
1 parent 17d82d5 commit 85c20b0

4 files changed

Lines changed: 62 additions & 27 deletions

File tree

x-pack/plugins/cases/server/client/cases/update.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ describe('update', () => {
134134
]);
135135
});
136136

137-
it('does not notify when deleting users', async () => {
137+
it('does not notify when removing assignees', async () => {
138138
clientArgs.services.caseService.getCases.mockResolvedValue({
139139
saved_objects: [
140140
{

x-pack/plugins/cases/server/client/cases/update.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import type {
1515
SavedObjectsBulkUpdateResponse,
1616
SavedObjectsFindResponse,
1717
SavedObjectsFindResult,
18+
SavedObjectsUpdateResponse,
1819
} from '@kbn/core/server';
1920

2021
import { nodeBuilder } from '@kbn/es-query';
@@ -439,13 +440,7 @@ export const update = async (
439440
return [
440441
...flattenCases,
441442
flattenCaseSavedObject({
442-
savedObject: {
443-
...originalCase,
444-
...updatedCase,
445-
attributes: { ...originalCase.attributes, ...updatedCase?.attributes },
446-
references: originalCase.references,
447-
version: updatedCase?.version ?? originalCase.version,
448-
},
443+
savedObject: mergeOriginalSOWithUpdatedSO(originalCase, updatedCase),
449444
}),
450445
];
451446
}, [] as CaseResponse[]);
@@ -547,13 +542,7 @@ const getCasesAndAssigneesToNotifyForAssignment = (
547542
);
548543

549544
if (comparedAssignees && comparedAssignees.addedItems.length > 0) {
550-
const theCase = {
551-
...originalCaseSO,
552-
...updatedCase,
553-
attributes: { ...originalCaseSO.attributes, ...updatedCase?.attributes },
554-
references: originalCaseSO.references,
555-
version: updatedCase?.version ?? originalCaseSO.version,
556-
};
545+
const theCase = mergeOriginalSOWithUpdatedSO(originalCaseSO, updatedCase);
557546

558547
const assigneesWithoutCurrentUser = comparedAssignees.addedItems.filter(
559548
(assignee) => assignee.uid !== user.profile_uid
@@ -565,3 +554,16 @@ const getCasesAndAssigneesToNotifyForAssignment = (
565554
return acc;
566555
}, [] as Array<{ assignees: CaseAssignees; theCase: CaseSavedObject }>);
567556
};
557+
558+
const mergeOriginalSOWithUpdatedSO = (
559+
originalSO: CaseSavedObject,
560+
updatedSO: SavedObjectsUpdateResponse<CaseAttributes>
561+
): CaseSavedObject => {
562+
return {
563+
...originalSO,
564+
...updatedSO,
565+
attributes: { ...originalSO.attributes, ...updatedSO?.attributes },
566+
references: updatedSO.references ?? originalSO.references,
567+
version: updatedSO?.version ?? updatedSO.version,
568+
};
569+
};

x-pack/plugins/cases/server/services/notifications/email_notification_service.test.ts

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ describe('EmailNotificationService', () => {
5656
],
5757
},
5858
message:
59-
'You got assigned to case "Super Bad Security Issue". [View case](https://example.com/app/security/cases/mock-id-1).',
60-
subject: 'You got assigned to case "Super Bad Security Issue"',
59+
'You got assigned to an Elastic Case.\r\n\r\nTitle: Super Bad Security Issue\r\n\r\nStatus: open\r\n\r\nSeverity: low\r\n\r\nTags: defacement\r\n\r\n\r\n\r\n[View case](https://example.com/app/security/cases/mock-id-1)',
60+
subject: '[Elastic] Super Bad Security Issue',
6161
to: ['damaged_raccoon@elastic.co', 'physical_dinosaur@elastic.co', 'wet_dingo@elastic.co'],
6262
});
6363
});
@@ -79,8 +79,8 @@ describe('EmailNotificationService', () => {
7979
],
8080
},
8181
message:
82-
'You got assigned to case "Super Bad Security Issue". [View case](https://example.com/app/security/cases/mock-id-1).',
83-
subject: 'You got assigned to case "Super Bad Security Issue"',
82+
'You got assigned to an Elastic Case.\r\n\r\nTitle: Super Bad Security Issue\r\n\r\nStatus: open\r\n\r\nSeverity: low\r\n\r\nTags: defacement\r\n\r\n\r\n\r\n[View case](https://example.com/app/security/cases/mock-id-1)',
83+
subject: '[Elastic] Super Bad Security Issue',
8484
to: ['damaged_raccoon@elastic.co', 'physical_dinosaur@elastic.co', 'wet_dingo@elastic.co'],
8585
});
8686
});
@@ -107,8 +107,8 @@ describe('EmailNotificationService', () => {
107107
],
108108
},
109109
message:
110-
'You got assigned to case "Super Bad Security Issue". [View case](https://example.com/app/security/cases/mock-id-1).',
111-
subject: 'You got assigned to case "Super Bad Security Issue"',
110+
'You got assigned to an Elastic Case.\r\n\r\nTitle: Super Bad Security Issue\r\n\r\nStatus: open\r\n\r\nSeverity: low\r\n\r\nTags: defacement\r\n\r\n\r\n\r\n[View case](https://example.com/app/security/cases/mock-id-1)',
111+
subject: '[Elastic] Super Bad Security Issue',
112112
to: ['physical_dinosaur@elastic.co'],
113113
});
114114
});
@@ -130,8 +130,37 @@ describe('EmailNotificationService', () => {
130130
],
131131
},
132132
message:
133-
'You got assigned to case "Super Bad Security Issue". [View case](https://example.com/app/security/cases/mock-id-1).',
134-
subject: 'You got assigned to case "Super Bad Security Issue"',
133+
'You got assigned to an Elastic Case.\r\n\r\nTitle: Super Bad Security Issue\r\n\r\nStatus: open\r\n\r\nSeverity: low\r\n\r\nTags: defacement\r\n\r\n\r\n\r\n[View case](https://example.com/app/security/cases/mock-id-1)',
134+
subject: '[Elastic] Super Bad Security Issue',
135+
to: ['damaged_raccoon@elastic.co', 'physical_dinosaur@elastic.co', 'wet_dingo@elastic.co'],
136+
});
137+
});
138+
139+
it('does not include the backlink of the publicBaseUrl is not defined', async () => {
140+
emailNotificationService = new EmailNotificationService({
141+
logger: clientArgs.logger,
142+
security: clientArgs.securityStartPlugin,
143+
notifications,
144+
});
145+
146+
await emailNotificationService.notifyAssignees({
147+
assignees,
148+
theCase: caseSO,
149+
});
150+
151+
expect(sendPlainTextEmail).toHaveBeenCalledWith({
152+
context: {
153+
relatedObjects: [
154+
{
155+
id: 'mock-id-1',
156+
namespace: undefined,
157+
type: 'cases',
158+
},
159+
],
160+
},
161+
message:
162+
'You got assigned to an Elastic Case.\r\n\r\nTitle: Super Bad Security Issue\r\n\r\nStatus: open\r\n\r\nSeverity: low\r\n\r\nTags: defacement\r\n\r\n',
163+
subject: '[Elastic] Super Bad Security Issue',
135164
to: ['damaged_raccoon@elastic.co', 'physical_dinosaur@elastic.co', 'wet_dingo@elastic.co'],
136165
});
137166
});

x-pack/plugins/cases/server/services/notifications/email_notification_service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,16 @@ export class EmailNotificationService implements NotificationService {
4242
}
4343

4444
private getTitle(theCase: CaseSavedObject) {
45-
// TODO: Better title
46-
return `You got assigned to case "${theCase.attributes.title}"`;
45+
return `[Elastic] ${theCase.attributes.title}`;
4746
}
4847

4948
private getMessage(theCase: CaseSavedObject) {
50-
let message = `You got assigned to case "${theCase.attributes.title}"`;
49+
const lineBreak = '\r\n\r\n';
50+
let message = `You got assigned to an Elastic Case.${lineBreak}`;
51+
message = `${message}Title: ${theCase.attributes.title}${lineBreak}`;
52+
message = `${message}Status: ${theCase.attributes.status}${lineBreak}`;
53+
message = `${message}Severity: ${theCase.attributes.severity}${lineBreak}`;
54+
message = `${message}Tags: ${theCase.attributes.tags.join(',')}${lineBreak}`;
5155

5256
if (this.publicBaseUrl) {
5357
const caseUrl = getCaseViewPath({
@@ -56,7 +60,7 @@ export class EmailNotificationService implements NotificationService {
5660
owner: theCase.attributes.owner,
5761
});
5862

59-
message = `${message}. [View case](${caseUrl}).`;
63+
message = `${message}${lineBreak}[View case](${caseUrl})`;
6064
}
6165

6266
return message;

0 commit comments

Comments
 (0)