-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Cases] Notify assignees when assigned to a case #144391
Conversation
Documentation preview: |
0f90bb7
to
2458b2f
Compare
Pinging @elastic/response-ops (Team:ResponseOps) |
Pinging @elastic/response-ops-cases (Feature:Cases) |
7d70ad0
to
85c20b0
Compare
a few comments:
not related to the content - how the FROM address is defined? |
Ofc!
This is my mistake. @lcawl suggested, "You are assigned to a case". I forgot to update.
Ok!
From the email connector configuration. The user decides what the FROM address will be. |
@shanisagiv1, @gsoldevila found out that in the cloud the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest replacing "got" in the message, otherwise text LGTM
x-pack/plugins/cases/server/services/notifications/email_notification_service.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/server/services/notifications/email_notification_service.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/server/services/notifications/email_notification_service.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/server/services/notifications/email_notification_service.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/server/services/notifications/email_notification_service.test.ts
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/server/services/notifications/email_notification_service.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks great, left a few comments. I still need to test it. As for integration tests, it looks like the email connector uses a mock email server to receive its emails. Do you think we could implement the same thing? We can do it as a follow up PR.
]); | ||
}); | ||
|
||
it('does not notify if the case does not exist', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test ensure that the clientArgs.services.notificationService.bulkNotifyAssignees
function was not called?
); | ||
}); | ||
|
||
it('does not notify if the case is patched with the same assignee', async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this test ensure that the clientArgs.services.notificationService.bulkNotifyAssignees
function was not called?
user | ||
); | ||
|
||
if (casesAndAssigneesToNotifyForAssignment.length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we move the if check inside of the bulkNotifyAssignees
and just have it return if the passed in value is an empty array?
} | ||
|
||
return acc; | ||
}, [] as Array<{ assignees: CaseAssignees; theCase: CaseSavedObject }>); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we can avoid the cast if we add this definition to the reduce<Array<{ assignees: CaseAssignees; theCase: CaseSavedObject }>>
const caseSO = mockCases[0]; | ||
const assignees = userProfiles.map((userProfile) => ({ uid: userProfile.uid })); | ||
|
||
const notifications = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, does the notification plugin return a mock that we could leverage here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! When I wrote the code they did not but they added it later. I will update it to include it.
]); | ||
|
||
await emailNotificationService.notifyAssignees({ | ||
assignees: [...assignees, { uid: assignees[0].uid }], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: to make it clearer maybe we should remove the duplicate assignee?
this.publicBaseUrl = publicBaseUrl; | ||
} | ||
|
||
private getTitle(theCase: CaseSavedObject) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: we could make this a private static getTitle
method.
} | ||
|
||
public async notifyAssignees({ assignees, theCase }: NotifyArgs) { | ||
if (!this.notifications.isEmailServiceAvailable()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't know if it's possible for isEmailServiceAvailable()
to throw an error but maybe we should move it into the try
?
|
||
public async bulkNotifyAssignees(args: NotifyArgs[]) { | ||
await Promise.all( | ||
args.map(({ assignees, theCase }) => this.notifyAssignees({ assignees, theCase })) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use the pMap
to ensure we don't make to many concurrent requests.
Thank you @jonathan-buttner for the feedback. I addressed all the suggestions. The email server is not mocked. The |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work! Tested and looks good.
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Unknown metric groupsESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
Wanted to share that I have done a quick test and seen the 'Cases Assignment will send an email notification' feature working via Cloud-QA deploy of latest 8.6 snapshot code, with the current known requirement that the users that shall receive email notifications are whitelisted in cloud, per this meaning |
Summary
The PR adds the ability to notify users by email when assigned to a case. A user is:
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
@shanisagiv1 @lcawl What do you think about the content of the email (see screenshot)?
Testing
kibana.yml
:maildev
:npm install -g maildev
maildev
:maildev
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.
For maintainers
Release notes
Notify users by email when assigned to a case