-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Notify assignees when assigned to a case (#144391)
## Summary The PR adds the ability to notify users by email when assigned to a case. A user is: - Not notified if he/she assigns themselves - Notified if added as an assignee to a case - Not notified if removed from a case I did not add integration tests due to the complexity of simulating an email server. I added unit test coverage. If integration test coverage is needed we can add the tests on another PR. Depends on: #143303 Fixes: #142307 ## Email screenshot <img width="361" alt="Screenshot 2022-11-07 at 1 27 13 PM" src="https://user-images.githubusercontent.com/7871006/200299356-52c08515-4d43-49d6-bd47-3797b52f97e5.png"> @shanisagiv1 @lcawl What do you think about the content of the email (see screenshot)? ## Testing 1. Put the following in your `kibana.yml`: ``` notifications.connectors.default.email: 'mail-dev' xpack.actions.preconfigured: mail-dev: name: preconfigured-email-notification-maildev actionTypeId: .email config: service: other from: mlr-test-sink@elastic.co host: localhost port: 1025 secure: false hasAuth: false ``` 2. Install [`maildev`](https://www.npmjs.com/package/maildev): `npm install -g maildev` 3. Run `maildev`: `maildev` 4. Open MailDev's web interface (http://0.0.0.0:1080/) 5. Create a case and assign users. You should see the emails in the MailDev inbox. 6. Update the assignees of a case. You should see the emails in the MailDev inbox. Note: If you assign yourself you should not see an email. If you delete an assignee you should not see an email. ### Checklist Delete any items that are not applicable to this PR. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] This was checked for [cross-browser compatibility](https://www.elastic.co/support/matrix#matrix_browsers) ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) ## Release notes Notify users by email when assigned to a case
- Loading branch information
Showing
33 changed files
with
1,095 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { SECURITY_SOLUTION_OWNER } from '../../../common'; | ||
import { CaseSeverity, ConnectorTypes } from '../../../common/api'; | ||
import { mockCases } from '../../mocks'; | ||
import { createCasesClientMockArgs } from '../mocks'; | ||
import { create } from './create'; | ||
|
||
describe('create', () => { | ||
const theCase = { | ||
title: 'My Case', | ||
tags: [], | ||
description: 'testing sir', | ||
connector: { | ||
id: '.none', | ||
name: 'None', | ||
type: ConnectorTypes.none, | ||
fields: null, | ||
}, | ||
settings: { syncAlerts: true }, | ||
severity: CaseSeverity.LOW, | ||
owner: SECURITY_SOLUTION_OWNER, | ||
assignees: [{ uid: '1' }], | ||
}; | ||
|
||
const caseSO = mockCases[0]; | ||
|
||
describe('Assignees', () => { | ||
const clientArgs = createCasesClientMockArgs(); | ||
clientArgs.services.caseService.postNewCase.mockResolvedValue(caseSO); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('notifies single assignees', async () => { | ||
await create(theCase, clientArgs); | ||
|
||
expect(clientArgs.services.notificationService.notifyAssignees).toHaveBeenCalledWith({ | ||
assignees: theCase.assignees, | ||
theCase: caseSO, | ||
}); | ||
}); | ||
|
||
it('notifies multiple assignees', async () => { | ||
await create({ ...theCase, assignees: [{ uid: '1' }, { uid: '2' }] }, clientArgs); | ||
|
||
expect(clientArgs.services.notificationService.notifyAssignees).toHaveBeenCalledWith({ | ||
assignees: [{ uid: '1' }, { uid: '2' }], | ||
theCase: caseSO, | ||
}); | ||
}); | ||
|
||
it('does not notify when there are no assignees', async () => { | ||
await create({ ...theCase, assignees: [] }, clientArgs); | ||
|
||
expect(clientArgs.services.notificationService.notifyAssignees).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('does not notify the current user', async () => { | ||
await create( | ||
{ | ||
...theCase, | ||
assignees: [{ uid: '1' }, { uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], | ||
}, | ||
clientArgs | ||
); | ||
|
||
expect(clientArgs.services.notificationService.notifyAssignees).toHaveBeenCalledWith({ | ||
assignees: [{ uid: '1' }], | ||
theCase: caseSO, | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.