From 7d70ad0c0ea11bc18cebe42bc01e287f26fb161a Mon Sep 17 00:00:00 2001 From: Christos Nasikas Date: Mon, 7 Nov 2022 12:59:29 +0200 Subject: [PATCH] Improvements --- .../cases/server/client/cases/update.test.ts | 2 +- .../cases/server/client/cases/update.ts | 30 ++++++++++--------- .../email_notification_service.ts | 7 ++--- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/cases/server/client/cases/update.test.ts b/x-pack/plugins/cases/server/client/cases/update.test.ts index 71d8f6b8a25b9f1..90d050af5de8572 100644 --- a/x-pack/plugins/cases/server/client/cases/update.test.ts +++ b/x-pack/plugins/cases/server/client/cases/update.test.ts @@ -134,7 +134,7 @@ describe('update', () => { ]); }); - it('does not notify when deleting users', async () => { + it('does not notify when removing assignees', async () => { clientArgs.services.caseService.getCases.mockResolvedValue({ saved_objects: [ { diff --git a/x-pack/plugins/cases/server/client/cases/update.ts b/x-pack/plugins/cases/server/client/cases/update.ts index fd3114c903c67b5..bdcd979e65ce2b1 100644 --- a/x-pack/plugins/cases/server/client/cases/update.ts +++ b/x-pack/plugins/cases/server/client/cases/update.ts @@ -15,6 +15,7 @@ import type { SavedObjectsBulkUpdateResponse, SavedObjectsFindResponse, SavedObjectsFindResult, + SavedObjectsUpdateResponse, } from '@kbn/core/server'; import { nodeBuilder } from '@kbn/es-query'; @@ -439,13 +440,7 @@ export const update = async ( return [ ...flattenCases, flattenCaseSavedObject({ - savedObject: { - ...originalCase, - ...updatedCase, - attributes: { ...originalCase.attributes, ...updatedCase?.attributes }, - references: originalCase.references, - version: updatedCase?.version ?? originalCase.version, - }, + savedObject: mergeOriginalSOWithUpdatedSO(originalCase, updatedCase), }), ]; }, [] as CaseResponse[]); @@ -547,13 +542,7 @@ const getCasesAndAssigneesToNotifyForAssignment = ( ); if (comparedAssignees && comparedAssignees.addedItems.length > 0) { - const theCase = { - ...originalCaseSO, - ...updatedCase, - attributes: { ...originalCaseSO.attributes, ...updatedCase?.attributes }, - references: originalCaseSO.references, - version: updatedCase?.version ?? originalCaseSO.version, - }; + const theCase = mergeOriginalSOWithUpdatedSO(originalCaseSO, updatedCase); const assigneesWithoutCurrentUser = comparedAssignees.addedItems.filter( (assignee) => assignee.uid !== user.profile_uid @@ -565,3 +554,16 @@ const getCasesAndAssigneesToNotifyForAssignment = ( return acc; }, [] as Array<{ assignees: CaseAssignees; theCase: CaseSavedObject }>); }; + +const mergeOriginalSOWithUpdatedSO = ( + originalSO: CaseSavedObject, + updatedSO: SavedObjectsUpdateResponse +): CaseSavedObject => { + return { + ...originalSO, + ...updatedSO, + attributes: { ...originalSO.attributes, ...updatedSO?.attributes }, + references: updatedSO.references ?? originalSO.references, + version: updatedSO?.version ?? updatedSO.version, + }; +}; diff --git a/x-pack/plugins/cases/server/services/notifications/email_notification_service.ts b/x-pack/plugins/cases/server/services/notifications/email_notification_service.ts index 1d4dee719dfd7c8..810c8dd656f50af 100644 --- a/x-pack/plugins/cases/server/services/notifications/email_notification_service.ts +++ b/x-pack/plugins/cases/server/services/notifications/email_notification_service.ts @@ -42,12 +42,11 @@ export class EmailNotificationService implements NotificationService { } private getTitle(theCase: CaseSavedObject) { - // TODO: Better title - return `You got assigned to case "${theCase.attributes.title}"`; + return `You got assigned to an Elastic case`; } private getMessage(theCase: CaseSavedObject) { - let message = `You got assigned to case "${theCase.attributes.title}"`; + let message = `You got assigned to Elastic case "${theCase.attributes.title}"`; if (this.publicBaseUrl) { const caseUrl = getCaseViewPath({ @@ -56,7 +55,7 @@ export class EmailNotificationService implements NotificationService { owner: theCase.attributes.owner, }); - message = `${message}. [View case](${caseUrl}).`; + message = `[View case](${caseUrl}).`; } return message;