-
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.
[Cases] Adding _find API for user actions (#148861)
This PR adds a new find API for retrieving a subset of the user actions for a case. Issue: #134344 ``` GET /api/cases/<case_id>/user_actions/_find Query Paramaters { types?: Array of "assignees" | "comment" | "connector" | "description" | "pushed" | "tags" | "title" | "status" | "settings" | "severity" | "create_case" | "delete_case" | "action" | "alert" | "user" | "attachment" sortOrder?: "asc" | "desc" page?: number as a string perPage?: number as a string } ``` <details><summary>Example request and response</summary> Request ``` curl --location --request GET 'http://localhost:5601/api/cases/8df5fe00-96b1-11ed-9341-471c9630b5ec/user_actions/_find?types=create_case&sortOrder=asc' \ --header 'kbn-xsrf: hello' \ --header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \ --data-raw '' ``` Response ``` { "userActions": [ { "created_at": "2023-01-17T21:54:45.527Z", "created_by": { "username": "elastic", "full_name": null, "email": null, "profile_uid": "u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0" }, "owner": "cases", "action": "create", "payload": { "title": "Awesome case", "tags": [], "severity": "low", "description": "super", "assignees": [], "connector": { "name": "none", "type": ".none", "fields": null, "id": "none" }, "settings": { "syncAlerts": false }, "owner": "cases", "status": "open" }, "type": "create_case", "id": "8e121180-96b1-11ed-9341-471c9630b5ec", "case_id": "8df5fe00-96b1-11ed-9341-471c9630b5ec", "comment_id": null } ], "page": 1, "perPage": 20, "total": 1 } ``` </details> ## Notable Changes - Created the new `_find` route - Created a new `UserActionFinder` class and moved the find* methods from the `index.ts` file into there as well as the new find logic - Extracted the transform logic to its own file since its shared between multiple files now - Extracted the user action related integration test functions to the `user_action.ts` utility file Co-authored-by: kibanamachine <[email protected]> Co-authored-by: lcawl <[email protected]>
- Loading branch information
1 parent
a31328c
commit a78fece
Showing
66 changed files
with
3,948 additions
and
1,021 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
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/cases/common/api/cases/user_actions/operations/find.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,45 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
import { CaseUserActionsResponseWithoutActionIdRt } from '../response'; | ||
import { ActionTypes } from '../common'; | ||
import { NumberFromString } from '../../../saved_object'; | ||
|
||
const AdditionalFilterTypes = { | ||
action: 'action', | ||
alert: 'alert', | ||
user: 'user', | ||
attachment: 'attachment', | ||
} as const; | ||
|
||
export const FindTypes = { | ||
...ActionTypes, | ||
...AdditionalFilterTypes, | ||
} as const; | ||
|
||
const FindTypeFieldRt = rt.keyof(FindTypes); | ||
|
||
export type FindTypeField = rt.TypeOf<typeof FindTypeFieldRt>; | ||
|
||
export const UserActionFindRequestRt = rt.partial({ | ||
types: rt.array(FindTypeFieldRt), | ||
sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]), | ||
page: NumberFromString, | ||
perPage: NumberFromString, | ||
}); | ||
|
||
export type UserActionFindRequest = rt.TypeOf<typeof UserActionFindRequestRt>; | ||
|
||
export const UserActionFindResponseRt = rt.type({ | ||
userActions: CaseUserActionsResponseWithoutActionIdRt, | ||
page: rt.number, | ||
perPage: rt.number, | ||
total: rt.number, | ||
}); | ||
|
||
export type UserActionFindResponse = rt.TypeOf<typeof UserActionFindResponseRt>; |
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/cases/common/api/cases/user_actions/operations/index.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,8 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export * from './find'; |
Oops, something went wrong.