Skip to content

Commit

Permalink
[Cases] User actions enhancements (#120342)
Browse files Browse the repository at this point in the history
Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
cnasikas and kibanamachine authored Dec 22, 2021
1 parent 47abd52 commit 61dd51a
Show file tree
Hide file tree
Showing 105 changed files with 6,463 additions and 4,554 deletions.
5 changes: 3 additions & 2 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const caseTypeField = 'type';

const CaseTypeRt = rt.union([rt.literal(CaseType.collection), rt.literal(CaseType.individual)]);

const SettingsRt = rt.type({
export const SettingsRt = rt.type({
syncAlerts: rt.boolean,
});

Expand Down Expand Up @@ -102,7 +102,7 @@ export const CaseUserActionExternalServiceRt = rt.type({

export const CaseExternalServiceBasicRt = rt.intersection([
rt.type({
connector_id: rt.union([rt.string, rt.null]),
connector_id: rt.string,
}),
CaseUserActionExternalServiceRt,
]);
Expand Down Expand Up @@ -339,6 +339,7 @@ export type CasesPatchRequest = rt.TypeOf<typeof CasesPatchRequestRt>;
export type CaseFullExternalService = rt.TypeOf<typeof CaseFullExternalServiceRt>;
export type CaseSettings = rt.TypeOf<typeof SettingsRt>;
export type ExternalServiceResponse = rt.TypeOf<typeof ExternalServiceResponseRt>;
export type CaseExternalServiceBasic = rt.TypeOf<typeof CaseExternalServiceBasicRt>;

export type AllTagsFindRequest = rt.TypeOf<typeof AllTagsFindRequestRt>;
export type AllReportersFindRequest = AllTagsFindRequest;
Expand Down
69 changes: 0 additions & 69 deletions x-pack/plugins/cases/common/api/cases/user_actions.ts

This file was deleted.

19 changes: 19 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/comment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 { CommentRequestRt } from '../comment';
import { ActionTypes, UserActionWithAttributes } from './common';

export const CommentUserActionPayloadRt = rt.type({ comment: CommentRequestRt });

export const CommentUserActionRt = rt.type({
type: rt.literal(ActionTypes.comment),
payload: CommentUserActionPayloadRt,
});

export type CommentUserAction = UserActionWithAttributes<rt.TypeOf<typeof CommentUserActionRt>>;
55 changes: 55 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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 { UserRT } from '../../user';

export const ActionTypes = {
comment: 'comment',
connector: 'connector',
description: 'description',
pushed: 'pushed',
tags: 'tags',
title: 'title',
status: 'status',
settings: 'settings',
create_case: 'create_case',
delete_case: 'delete_case',
} as const;

export const Actions = {
add: 'add',
create: 'create',
delete: 'delete',
update: 'update',
push_to_service: 'push_to_service',
} as const;

/* To the next developer, if you add/removed fields here
* make sure to check this file (x-pack/plugins/cases/server/services/user_actions/helpers.ts) too
*/
export const ActionTypesRt = rt.keyof(ActionTypes);
export const ActionsRt = rt.keyof(Actions);

export const UserActionCommonAttributesRt = rt.type({
created_at: rt.string,
created_by: UserRT,
owner: rt.string,
action: ActionsRt,
});

export const CaseUserActionSavedObjectIdsRt = rt.intersection([
rt.type({
action_id: rt.string,
case_id: rt.string,
comment_id: rt.union([rt.string, rt.null]),
}),
rt.partial({ sub_case_id: rt.string }),
]);

export type UserActionWithAttributes<T> = T & rt.TypeOf<typeof UserActionCommonAttributesRt>;
export type UserActionWithResponse<T> = T & rt.TypeOf<typeof CaseUserActionSavedObjectIdsRt>;
33 changes: 33 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/connector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 { CaseUserActionConnectorRt, CaseConnectorRt } from '../../connectors';
import { ActionTypes, UserActionWithAttributes } from './common';

export const ConnectorUserActionPayloadWithoutConnectorIdRt = rt.type({
connector: CaseUserActionConnectorRt,
});

export const ConnectorUserActionPayloadRt = rt.type({
connector: CaseConnectorRt,
});

export const ConnectorUserActionWithoutConnectorIdRt = rt.type({
type: rt.literal(ActionTypes.connector),
payload: ConnectorUserActionPayloadWithoutConnectorIdRt,
});

export const ConnectorUserActionRt = rt.type({
type: rt.literal(ActionTypes.connector),
payload: ConnectorUserActionPayloadRt,
});

export type ConnectorUserAction = UserActionWithAttributes<rt.TypeOf<typeof ConnectorUserActionRt>>;
export type ConnectorUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof ConnectorUserActionWithoutConnectorIdRt>
>;
54 changes: 54 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/create_case.ts
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 * as rt from 'io-ts';
import { ActionTypes, UserActionWithAttributes } from './common';
import {
ConnectorUserActionPayloadRt,
ConnectorUserActionPayloadWithoutConnectorIdRt,
} from './connector';
import { DescriptionUserActionPayloadRt } from './description';
import { SettingsUserActionPayloadRt } from './settings';
import { TagsUserActionPayloadRt } from './tags';
import { TitleUserActionPayloadRt } from './title';

export const CommonFieldsRt = rt.type({
type: rt.literal(ActionTypes.create_case),
});

const CommonPayloadAttributesRt = rt.type({
description: DescriptionUserActionPayloadRt.props.description,
status: rt.string,
tags: TagsUserActionPayloadRt.props.tags,
title: TitleUserActionPayloadRt.props.title,
settings: SettingsUserActionPayloadRt.props.settings,
owner: rt.string,
});

export const CreateCaseUserActionRt = rt.intersection([
CommonFieldsRt,
rt.type({
payload: rt.intersection([ConnectorUserActionPayloadRt, CommonPayloadAttributesRt]),
}),
]);

export const CreateCaseUserActionWithoutConnectorIdRt = rt.intersection([
CommonFieldsRt,
rt.type({
payload: rt.intersection([
ConnectorUserActionPayloadWithoutConnectorIdRt,
CommonPayloadAttributesRt,
]),
}),
]);

export type CreateCaseUserAction = UserActionWithAttributes<
rt.TypeOf<typeof CreateCaseUserActionRt>
>;
export type CreateCaseUserActionWithoutConnectorId = UserActionWithAttributes<
rt.TypeOf<typeof CreateCaseUserActionWithoutConnectorIdRt>
>;
18 changes: 18 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/delete_case.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* 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 { ActionTypes, UserActionWithAttributes } from './common';

export const DeleteCaseUserActionRt = rt.type({
type: rt.literal(ActionTypes.delete_case),
payload: rt.type({}),
});

export type DeleteCaseUserAction = UserActionWithAttributes<
rt.TypeOf<typeof DeleteCaseUserActionRt>
>;
20 changes: 20 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/description.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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 { ActionTypes, UserActionWithAttributes } from './common';

export const DescriptionUserActionPayloadRt = rt.type({ description: rt.string });

export const DescriptionUserActionRt = rt.type({
type: rt.literal(ActionTypes.description),
payload: DescriptionUserActionPayloadRt,
});

export type DescriptionUserAction = UserActionWithAttributes<
rt.TypeOf<typeof DescriptionUserActionRt>
>;
91 changes: 91 additions & 0 deletions x-pack/plugins/cases/common/api/cases/user_actions/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* 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 {
ActionsRt,
UserActionCommonAttributesRt,
CaseUserActionSavedObjectIdsRt,
ActionTypesRt,
} from './common';
import { CreateCaseUserActionRt } from './create_case';
import { DescriptionUserActionRt } from './description';
import { CommentUserActionRt } from './comment';
import { ConnectorUserActionRt } from './connector';
import { PushedUserActionRt } from './pushed';
import { TagsUserActionRt } from './tags';
import { TitleUserActionRt } from './title';
import { SettingsUserActionRt } from './settings';
import { StatusUserActionRt } from './status';
import { DeleteCaseUserActionRt } from './delete_case';

export * from './common';
export * from './comment';
export * from './connector';
export * from './create_case';
export * from './delete_case';
export * from './description';
export * from './pushed';
export * from './settings';
export * from './status';
export * from './tags';
export * from './title';

const CommonUserActionsRt = rt.union([
DescriptionUserActionRt,
CommentUserActionRt,
TagsUserActionRt,
TitleUserActionRt,
SettingsUserActionRt,
StatusUserActionRt,
]);

export const UserActionsRt = rt.union([
CommonUserActionsRt,
CreateCaseUserActionRt,
ConnectorUserActionRt,
PushedUserActionRt,
DeleteCaseUserActionRt,
]);

export const UserActionsWithoutConnectorIdRt = rt.union([
CommonUserActionsRt,
CreateCaseUserActionRt,
ConnectorUserActionRt,
PushedUserActionRt,
DeleteCaseUserActionRt,
]);

const CaseUserActionBasicRt = rt.intersection([UserActionsRt, UserActionCommonAttributesRt]);
const CaseUserActionBasicWithoutConnectorIdRt = rt.intersection([
UserActionsWithoutConnectorIdRt,
UserActionCommonAttributesRt,
]);

const CaseUserActionResponseRt = rt.intersection([
CaseUserActionBasicRt,
CaseUserActionSavedObjectIdsRt,
]);

export const CaseUserActionAttributesRt = CaseUserActionBasicRt;
export const CaseUserActionsResponseRt = rt.array(CaseUserActionResponseRt);

export type CaseUserActionAttributes = rt.TypeOf<typeof CaseUserActionAttributesRt>;
export type CaseUserActionAttributesWithoutConnectorId = rt.TypeOf<
typeof CaseUserActionAttributesRt
>;
export type CaseUserActionsResponse = rt.TypeOf<typeof CaseUserActionsResponseRt>;
export type CaseUserActionResponse = rt.TypeOf<typeof CaseUserActionResponseRt>;

export type UserAction = rt.TypeOf<typeof ActionsRt>;
export type UserActionTypes = rt.TypeOf<typeof ActionTypesRt>;

export type CaseUserAction = rt.TypeOf<typeof CaseUserActionBasicRt>;
export type CaseUserActionWithoutConnectorId = rt.TypeOf<
typeof CaseUserActionBasicWithoutConnectorIdRt
>;
Loading

0 comments on commit 61dd51a

Please sign in to comment.