Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Nov 7, 2022
1 parent 17d82d5 commit 7d70ad0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion x-pack/plugins/cases/server/client/cases/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down
30 changes: 16 additions & 14 deletions x-pack/plugins/cases/server/client/cases/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
SavedObjectsBulkUpdateResponse,
SavedObjectsFindResponse,
SavedObjectsFindResult,
SavedObjectsUpdateResponse,
} from '@kbn/core/server';

import { nodeBuilder } from '@kbn/es-query';
Expand Down Expand Up @@ -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[]);
Expand Down Expand Up @@ -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
Expand All @@ -565,3 +554,16 @@ const getCasesAndAssigneesToNotifyForAssignment = (
return acc;
}, [] as Array<{ assignees: CaseAssignees; theCase: CaseSavedObject }>);
};

const mergeOriginalSOWithUpdatedSO = (
originalSO: CaseSavedObject,
updatedSO: SavedObjectsUpdateResponse<CaseAttributes>
): CaseSavedObject => {
return {
...originalSO,
...updatedSO,
attributes: { ...originalSO.attributes, ...updatedSO?.attributes },
references: updatedSO.references ?? originalSO.references,
version: updatedSO?.version ?? updatedSO.version,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -56,7 +55,7 @@ export class EmailNotificationService implements NotificationService {
owner: theCase.attributes.owner,
});

message = `${message}. [View case](${caseUrl}).`;
message = `[View case](${caseUrl}).`;
}

return message;
Expand Down

0 comments on commit 7d70ad0

Please sign in to comment.