-
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] Remove case info from alerts when deleting an alert attachment #154024
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7b218e8
Remove alerts from case
cnasikas c7e2d82
Add tests
cnasikas 4735868
Add integration tests
cnasikas 476502b
Show a success toaster when deleting attachments
cnasikas 7aaa9c2
PR feedback
cnasikas 0a62126
PR feedback
cnasikas 623a999
Merge branch 'main' into remove_alerts
cnasikas c0cc933
Merge branch 'main' into remove_alerts
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
*/ | ||
|
||
import type { | ||
AttributesTypeAlerts, | ||
CommentAttributes, | ||
CommentRequest, | ||
CommentRequestExternalReferenceType, | ||
CommentRequestPersistableStateType, | ||
|
@@ -29,3 +31,7 @@ export const isCommentRequestTypePersistableState = ( | |
): context is CommentRequestPersistableStateType => { | ||
return context.type === CommentType.persistableState; | ||
}; | ||
|
||
export const isAlertAttachment = ( | ||
attachment: CommentAttributes | ||
): attachment is AttributesTypeAlerts => attachment.type === CommentType.alert; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add unit test for this function? |
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
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
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
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/cases/server/client/attachments/delete.test.ts
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,46 @@ | ||
/* | ||
* 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 { mockCaseComments } from '../../mocks'; | ||
import { createCasesClientMockArgs } from '../mocks'; | ||
import { deleteComment } from './delete'; | ||
|
||
describe('deleteComment', () => { | ||
const clientArgs = createCasesClientMockArgs(); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
describe('Alerts', () => { | ||
const commentSO = mockCaseComments[0]; | ||
const alertsSO = mockCaseComments[3]; | ||
clientArgs.services.attachmentService.getter.get.mockResolvedValue(alertsSO); | ||
|
||
it('delete alerts correctly', async () => { | ||
await deleteComment({ caseID: 'mock-id-4', attachmentID: 'mock-comment-4' }, clientArgs); | ||
|
||
expect(clientArgs.services.alertsService.ensureAlertsAuthorized).toHaveBeenCalledWith({ | ||
alerts: [{ id: 'test-id', index: 'test-index' }], | ||
}); | ||
|
||
expect(clientArgs.services.alertsService.removeAlertsFromCase).toHaveBeenCalledWith({ | ||
alerts: [{ id: 'test-id', index: 'test-index' }], | ||
caseId: 'mock-id-4', | ||
}); | ||
}); | ||
|
||
it('does not call the alert service when the attachment is not an alert', async () => { | ||
clientArgs.services.attachmentService.getter.get.mockResolvedValue(commentSO); | ||
await deleteComment({ caseID: 'mock-id-1', attachmentID: 'mock-comment-1' }, clientArgs); | ||
|
||
expect(clientArgs.services.alertsService.ensureAlertsAuthorized).not.toHaveBeenCalledWith(); | ||
|
||
expect(clientArgs.services.alertsService.removeAlertsFromCase).not.toHaveBeenCalledWith(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Can we use the type guard here: https://github.com/elastic/kibana/blob/main/x-pack/plugins/cases/server/common/utils.ts#L254
It's slightly different as it operates on the request rather than attributes.
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.
Ah, thanks. And I was searching for an existing one.