-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Response Ops][Cases] Cases with empty string assignees throwing error #209973
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
Merged
jcger
merged 9 commits into
elastic:main
from
jcger:issue-209950-cases-list-broken-assignee
Feb 12, 2025
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
24146dc
filter empty assignees in cases list
jcger 9498aab
Merge branch 'main' into issue-209950-cases-list-broken-assignee
jcger e4c340e
Merge branch 'main' into issue-209950-cases-list-broken-assignee
jcger 743d8f1
filter out empty uids for post and patch case
jcger a68716a
Merge branch 'issue-209950-cases-list-broken-assignee' of github.com:…
jcger c59a06e
add tests
jcger fc56a08
add api test
jcger 68426ee
Merge branch 'main' into issue-209950-cases-list-broken-assignee
jcger 1bd6564
move sanitizer to client level
jcger 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
34 changes: 34 additions & 0 deletions
34
x-pack/platform/plugins/shared/cases/server/client/cases/sanitizers.ts
This file contains hidden or 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,34 @@ | ||
| /* | ||
| * 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 { isEmpty } from 'lodash'; | ||
| import type { CaseUserProfile } from '../../../common/types/domain/user/v1'; | ||
|
|
||
| export const emptyCaseAssigneesSanitizer = <T extends { assignees?: CaseUserProfile[] }>( | ||
| theCase: T | ||
| ): T => { | ||
| if (isEmpty(theCase.assignees)) { | ||
| return theCase; | ||
| } | ||
|
|
||
| return { | ||
| ...theCase, | ||
| assignees: theCase.assignees?.filter(({ uid }) => !isEmpty(uid)), | ||
| }; | ||
| }; | ||
|
|
||
| export const emptyCasesAssigneesSanitizer = <T extends { assignees?: CaseUserProfile[] }>({ | ||
| cases, | ||
| }: { | ||
| cases: T[]; | ||
| }): { cases: T[] } => { | ||
| return { | ||
| cases: cases.map((theCase) => { | ||
| return emptyCaseAssigneesSanitizer(theCase); | ||
| }), | ||
| }; | ||
| }; |
54 changes: 54 additions & 0 deletions
54
x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/patch_case.ts
This file contains hidden or 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,54 @@ | ||
| /* | ||
|
Contributor
Author
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. test in trial because only premium users can assign cases to a user |
||
| * 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 expect from '@kbn/expect'; | ||
|
|
||
| import { postCaseReq, postCaseResp } from '../../../../common/lib/mock'; | ||
| import { | ||
| deleteAllCaseItems, | ||
| createCase, | ||
| removeServerGeneratedPropertiesFromCase, | ||
| updateCase, | ||
| } from '../../../../common/lib/api'; | ||
| import { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
|
|
||
| export const defaultUser = { email: null, full_name: null, username: 'elastic' }; | ||
|
Member
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. You can use this from |
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext): void => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('patch_case', () => { | ||
| afterEach(async () => { | ||
| await deleteAllCaseItems(es); | ||
| }); | ||
|
|
||
| it('should filter out empty assignee.uid values', async () => { | ||
| const randomUid = '7f3e9d2a-1b8c-4c5f-9e6d-8f2a4b1d3c7e'; | ||
| const postedCase = await createCase(supertest, postCaseReq); | ||
| const patchedCases = await updateCase({ | ||
| supertest, | ||
| params: { | ||
| cases: [ | ||
| { | ||
| id: postedCase.id, | ||
| version: postedCase.version, | ||
| assignees: [{ uid: '' }, { uid: randomUid }], | ||
| }, | ||
| ], | ||
| }, | ||
| }); | ||
|
|
||
| const data = removeServerGeneratedPropertiesFromCase(patchedCases[0]); | ||
| expect(data).to.eql({ | ||
| ...postCaseResp(), | ||
| assignees: [{ uid: randomUid }], | ||
| updated_by: defaultUser, | ||
| }); | ||
| }); | ||
| }); | ||
| }; | ||
42 changes: 42 additions & 0 deletions
42
x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/post_case.ts
This file contains hidden or 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,42 @@ | ||
| /* | ||
| * 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 expect from '@kbn/expect'; | ||
|
|
||
| import { getPostCaseRequest } from '../../../../common/lib/mock'; | ||
| import { | ||
| deleteAllCaseItems, | ||
| createCase, | ||
| removeServerGeneratedPropertiesFromCase, | ||
| } from '../../../../common/lib/api'; | ||
| import { FtrProviderContext } from '../../../../common/ftr_provider_context'; | ||
|
|
||
| // eslint-disable-next-line import/no-default-export | ||
| export default ({ getService }: FtrProviderContext): void => { | ||
| const supertest = getService('supertest'); | ||
| const es = getService('es'); | ||
|
|
||
| describe('post_case', () => { | ||
| afterEach(async () => { | ||
| await deleteAllCaseItems(es); | ||
| }); | ||
|
|
||
| it('should filter out empty assignee.uid values', async () => { | ||
| const randomUid = '7f3e9d2a-1b8c-4c5f-9e6d-8f2a4b1d3c7e'; | ||
| const createdCase = await createCase( | ||
| supertest, | ||
| getPostCaseRequest({ | ||
| assignees: [{ uid: '' }, { uid: randomUid }], | ||
| }) | ||
| ); | ||
|
|
||
| const data = removeServerGeneratedPropertiesFromCase(createdCase); | ||
|
|
||
| expect(data.assignees).to.eql([{ uid: randomUid }]); | ||
| }); | ||
| }); | ||
| }; |
This file contains hidden or 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
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.
changed this initially, not needed anymore but keeping just because it's cleaner/easier to reuse if needed