-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Response Ops][Cases] Cases with empty string assignees throwing error (
#209973) ## Summary Closes #209950 Testing steps in referenced issue ## Release note Fix error message in cases list if case assignee is an empty string (cherry picked from commit 0897d08)
- Loading branch information
Showing
11 changed files
with
230 additions
and
36 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
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
34 changes: 34 additions & 0 deletions
34
x-pack/platform/plugins/shared/cases/server/client/cases/sanitizers.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,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 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 @@ | ||
/* | ||
* 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' }; | ||
// 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 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 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