Skip to content

Commit 80afba1

Browse files
[Cases] Add category field to mapping (#159205)
Fixes #159116 ## Summary - Add the new `category` field to cases. - Update the types to take `category` into account. - Update `transforms` to return a default value for `category`. --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent babaec8 commit 80afba1

16 files changed

Lines changed: 105 additions & 18 deletions

File tree

packages/kbn-check-mappings-update-cli/current_mappings.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -874,27 +874,27 @@
874874
}
875875
}
876876
},
877-
"search": {
878-
"dynamic": false,
877+
"tag": {
879878
"properties": {
880-
"title": {
879+
"name": {
881880
"type": "text"
882881
},
883882
"description": {
884883
"type": "text"
884+
},
885+
"color": {
886+
"type": "text"
885887
}
886888
}
887889
},
888-
"tag": {
890+
"search": {
891+
"dynamic": false,
889892
"properties": {
890-
"name": {
893+
"title": {
891894
"type": "text"
892895
},
893896
"description": {
894897
"type": "text"
895-
},
896-
"color": {
897-
"type": "text"
898898
}
899899
}
900900
},
@@ -1341,6 +1341,9 @@
13411341
},
13421342
"total_comments": {
13431343
"type": "integer"
1344+
},
1345+
"category": {
1346+
"type": "keyword"
13441347
}
13451348
}
13461349
},

src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
6969
"canvas-element": "b39dfe54b9ff3ecc4c6bc5bed6a14b0a0fe83644",
7070
"canvas-workpad": "4df66cf25eba8e7e25c061a1b2a5aadbb1f436e9",
7171
"canvas-workpad-template": "52a35f737b579a570510fca361fddd158d2a92ad",
72-
"cases": "3d968144040b829dddb8826bad90f9f0ab57a403",
72+
"cases": "b43a8ce985c406167e1d115381805a48cb3b0e61",
7373
"cases-comments": "ded400d82c5ea26959c2ee8e54896981d499a226",
7474
"cases-configure": "44ed7b8e0f44df39516b8870589b89e32224d2bf",
7575
"cases-connector-mappings": "f9d1ac57e484e69506c36a8051e4d61f4a8cfd25",

x-pack/plugins/cases/common/api/cases/case.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ const basicCase = {
8686
},
8787
// damaged_raccoon uid
8888
assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }],
89+
category: null,
8990
};
9091

9192
describe('Case', () => {
@@ -227,6 +228,7 @@ describe('Case', () => {
227228
external_service: null,
228229
updated_at: '2020-02-20T15:02:57.995Z',
229230
updated_by: null,
231+
category: null,
230232
};
231233

232234
it('has expected attributes in request', () => {

x-pack/plugins/cases/common/api/cases/case.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ const CaseBasicRt = rt.strict({
8585
* The users assigned to this case
8686
*/
8787
assignees: CaseAssigneesRt,
88+
/**
89+
* The category of the case.
90+
*/
91+
category: rt.union([rt.string, rt.null]),
8892
});
8993

9094
/**
@@ -162,6 +166,10 @@ export const CasePostRequestRt = rt.intersection([
162166
* default it to "low" if not provided.
163167
*/
164168
severity: CaseSeverityRt,
169+
/**
170+
* The category of the case.
171+
*/
172+
category: rt.string,
165173
})
166174
),
167175
]);
@@ -269,6 +277,10 @@ export const CasesFindRequestRt = rt.exact(
269277
*/
270278

271279
owner: rt.union([rt.array(rt.string), rt.string]),
280+
/**
281+
* The category of the case.
282+
*/
283+
category: rt.string,
272284
})
273285
);
274286

x-pack/plugins/cases/public/containers/mock.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ export const basicCase: CaseUI = {
241241
},
242242
// damaged_raccoon uid
243243
assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }],
244+
category: null,
244245
};
245246

246247
export const basicFileMock: FileJSON = {
@@ -357,6 +358,7 @@ export const mockCase: CaseUI = {
357358
syncAlerts: true,
358359
},
359360
assignees: [],
361+
category: null,
360362
};
361363

362364
export const basicCasePost: CaseUI = {

x-pack/plugins/cases/server/common/types/case.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface CasePersistedAttributes {
4747
total_comments: number;
4848
updated_at: string | null;
4949
updated_by: User | null;
50+
category?: string | null;
5051
}
5152

5253
export type CaseTransformedAttributes = CaseAttributes;

x-pack/plugins/cases/server/common/utils.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ describe('common utils', () => {
106106
expect(res).toMatchInlineSnapshot(`
107107
Object {
108108
"assignees": Array [],
109+
"category": null,
109110
"closed_at": null,
110111
"closed_by": null,
111112
"connector": Object {
@@ -159,6 +160,7 @@ describe('common utils', () => {
159160
expect(res).toMatchInlineSnapshot(`
160161
Object {
161162
"assignees": Array [],
163+
"category": null,
162164
"closed_at": null,
163165
"closed_by": null,
164166
"connector": Object {
@@ -216,6 +218,7 @@ describe('common utils', () => {
216218
"uid": "1",
217219
},
218220
],
221+
"category": null,
219222
"closed_at": null,
220223
"closed_by": null,
221224
"connector": Object {
@@ -276,6 +279,7 @@ describe('common utils', () => {
276279
"cases": Array [
277280
Object {
278281
"assignees": Array [],
282+
"category": null,
279283
"closed_at": null,
280284
"closed_by": null,
281285
"comments": Array [],
@@ -317,6 +321,7 @@ describe('common utils', () => {
317321
},
318322
Object {
319323
"assignees": Array [],
324+
"category": null,
320325
"closed_at": null,
321326
"closed_by": null,
322327
"comments": Array [],
@@ -358,6 +363,7 @@ describe('common utils', () => {
358363
},
359364
Object {
360365
"assignees": Array [],
366+
"category": null,
361367
"closed_at": null,
362368
"closed_by": null,
363369
"comments": Array [],
@@ -403,6 +409,7 @@ describe('common utils', () => {
403409
},
404410
Object {
405411
"assignees": Array [],
412+
"category": null,
406413
"closed_at": "2019-11-25T22:32:17.947Z",
407414
"closed_by": Object {
408415
"email": "testemail@elastic.co",
@@ -473,6 +480,7 @@ describe('common utils', () => {
473480
expect(res).toMatchInlineSnapshot(`
474481
Object {
475482
"assignees": Array [],
483+
"category": null,
476484
"closed_at": null,
477485
"closed_by": null,
478486
"comments": Array [],
@@ -530,6 +538,7 @@ describe('common utils', () => {
530538
expect(res).toMatchInlineSnapshot(`
531539
Object {
532540
"assignees": Array [],
541+
"category": null,
533542
"closed_at": null,
534543
"closed_by": null,
535544
"comments": Array [],
@@ -588,6 +597,7 @@ describe('common utils', () => {
588597
expect(res).toMatchInlineSnapshot(`
589598
Object {
590599
"assignees": Array [],
600+
"category": null,
591601
"closed_at": null,
592602
"closed_by": null,
593603
"comments": Array [
@@ -669,6 +679,7 @@ describe('common utils', () => {
669679
expect(res).toMatchInlineSnapshot(`
670680
Object {
671681
"assignees": Array [],
682+
"category": null,
672683
"closed_at": null,
673684
"closed_by": null,
674685
"comments": Array [],

x-pack/plugins/cases/server/common/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const transformNewCase = ({
8484
updated_at: null,
8585
updated_by: null,
8686
assignees: dedupAssignees(newCase.assignees) ?? [],
87+
category: null,
8788
});
8889

8990
export const transformCases = ({

x-pack/plugins/cases/server/mocks.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const mockCases: CaseSavedObjectTransformed[] = [
5656
},
5757
owner: SECURITY_SOLUTION_OWNER,
5858
assignees: [],
59+
category: null,
5960
},
6061
references: [],
6162
updated_at: '2019-11-25T21:54:48.952Z',
@@ -97,6 +98,7 @@ export const mockCases: CaseSavedObjectTransformed[] = [
9798
},
9899
owner: SECURITY_SOLUTION_OWNER,
99100
assignees: [],
101+
category: null,
100102
},
101103
references: [],
102104
updated_at: '2019-11-25T22:32:00.900Z',
@@ -138,6 +140,7 @@ export const mockCases: CaseSavedObjectTransformed[] = [
138140
},
139141
owner: SECURITY_SOLUTION_OWNER,
140142
assignees: [],
143+
category: null,
141144
},
142145
references: [],
143146
updated_at: '2019-11-25T22:32:17.947Z',
@@ -183,6 +186,7 @@ export const mockCases: CaseSavedObjectTransformed[] = [
183186
},
184187
owner: SECURITY_SOLUTION_OWNER,
185188
assignees: [],
189+
category: null,
186190
},
187191
references: [],
188192
updated_at: '2019-11-25T22:32:17.947Z',

x-pack/plugins/cases/server/saved_object_types/cases.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ export const createCaseSavedObjectType = (
188188
total_comments: {
189189
type: 'integer',
190190
},
191+
category: {
192+
type: 'keyword',
193+
},
191194
},
192195
},
193196
migrations: caseMigrations,

0 commit comments

Comments
 (0)