Skip to content
This repository has been archived by the owner on Mar 31, 2024. It is now read-only.

Commit

Permalink
Revert "[Case] Detection rules for case (elastic#88726)"
Browse files Browse the repository at this point in the history
This reverts commit f8b8d5b.
  • Loading branch information
spalger committed Feb 13, 2021
1 parent 874fadf commit 5a471d6
Show file tree
Hide file tree
Showing 123 changed files with 2,181 additions and 8,319 deletions.
54 changes: 12 additions & 42 deletions x-pack/plugins/case/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@ import * as rt from 'io-ts';
import { NumberFromString } from '../saved_object';
import { UserRT } from '../user';
import { CommentResponseRt } from './comment';
import { CasesStatusResponseRt, CaseStatusRt } from './status';
import { CasesStatusResponseRt } from './status';
import { CaseConnectorRt, ESCaseConnector } from '../connectors';
import { SubCaseResponseRt } from './sub_case';

export enum CaseType {
collection = 'collection',
individual = 'individual',
export enum CaseStatuses {
open = 'open',
'in-progress' = 'in-progress',
closed = 'closed',
}

/**
* Exposing the field used to define the case type so that it can be used for filtering in saved object find queries.
*/
export const caseTypeField = 'type';
const CaseStatusRt = rt.union([
rt.literal(CaseStatuses.open),
rt.literal(CaseStatuses['in-progress']),
rt.literal(CaseStatuses.closed),
]);

const CaseTypeRt = rt.union([rt.literal(CaseType.collection), rt.literal(CaseType.individual)]);
export const caseStatuses = Object.values(CaseStatuses);

const SettingsRt = rt.type({
syncAlerts: rt.boolean,
Expand All @@ -35,7 +36,6 @@ const CaseBasicRt = rt.type({
status: CaseStatusRt,
tags: rt.array(rt.string),
title: rt.string,
[caseTypeField]: CaseTypeRt,
connector: CaseConnectorRt,
settings: SettingsRt,
});
Expand Down Expand Up @@ -72,35 +72,15 @@ export const CaseAttributesRt = rt.intersection([
}),
]);

const CasePostRequestNoTypeRt = rt.type({
export const CasePostRequestRt = rt.type({
description: rt.string,
tags: rt.array(rt.string),
title: rt.string,
connector: CaseConnectorRt,
settings: SettingsRt,
});

/**
* This type is used for validating a create case request. It requires that the type field be defined.
*/
export const CaseClientPostRequestRt = rt.type({
...CasePostRequestNoTypeRt.props,
[caseTypeField]: CaseTypeRt,
});

/**
* This type is not used for validation when decoding a request because intersection does not have props defined which
* required for the excess function. Instead we use this as the type used by the UI. This allows the type field to be
* optional and the server will handle setting it to a default value before validating that the request
* has all the necessary fields. CaseClientPostRequestRt is used for validation.
*/
export const CasePostRequestRt = rt.intersection([
rt.partial({ type: CaseTypeRt }),
CasePostRequestNoTypeRt,
]);

export const CasesFindRequestRt = rt.partial({
type: CaseTypeRt,
tags: rt.union([rt.array(rt.string), rt.string]),
status: CaseStatusRt,
reporters: rt.union([rt.array(rt.string), rt.string]),
Expand All @@ -119,11 +99,9 @@ export const CaseResponseRt = rt.intersection([
rt.type({
id: rt.string,
totalComment: rt.number,
totalAlerts: rt.number,
version: rt.string,
}),
rt.partial({
subCases: rt.array(SubCaseResponseRt),
comments: rt.array(CommentResponseRt),
}),
]);
Expand Down Expand Up @@ -172,21 +150,13 @@ export const ExternalServiceResponseRt = rt.intersection([
]);

export type CaseAttributes = rt.TypeOf<typeof CaseAttributesRt>;
/**
* This field differs from the CasePostRequest in that the post request's type field can be optional. This type requires
* that the type field be defined. The CasePostRequest should be used in most places (the UI etc). This type is really
* only necessary for validation.
*/
export type CaseClientPostRequest = rt.TypeOf<typeof CaseClientPostRequestRt>;
export type CasePostRequest = rt.TypeOf<typeof CasePostRequestRt>;
export type CaseResponse = rt.TypeOf<typeof CaseResponseRt>;
export type CasesResponse = rt.TypeOf<typeof CasesResponseRt>;
export type CasesFindRequest = rt.TypeOf<typeof CasesFindRequestRt>;
export type CasesFindResponse = rt.TypeOf<typeof CasesFindResponseRt>;
export type CasePatchRequest = rt.TypeOf<typeof CasePatchRequestRt>;
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 ESCaseAttributes = Omit<CaseAttributes, 'connector'> & { connector: ESCaseConnector };
Expand Down
51 changes: 16 additions & 35 deletions x-pack/plugins/case/common/api/cases/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,7 @@ import * as rt from 'io-ts';

import { UserRT } from '../user';

/**
* this is used to differentiate between an alert attached to a top-level case and a group of alerts that should only
* be attached to a sub case. The reason we need this is because an alert group comment will have references to both a case and
* sub case when it is created. For us to be able to filter out alert groups in a top-level case we need a field to
* use as a filter.
*/
export enum AssociationType {
case = 'case',
subCase = 'sub_case',
}

export const CommentAttributesBasicRt = rt.type({
associationType: rt.union([
rt.literal(AssociationType.case),
rt.literal(AssociationType.subCase),
]),
created_at: rt.string,
created_by: UserRT,
pushed_at: rt.union([rt.string, rt.null]),
Expand All @@ -33,33 +18,24 @@ export const CommentAttributesBasicRt = rt.type({
updated_by: rt.union([UserRT, rt.null]),
});

export enum CommentType {
user = 'user',
alert = 'alert',
generatedAlert = 'generated_alert',
}

export const ContextTypeUserRt = rt.type({
comment: rt.string,
type: rt.literal(CommentType.user),
type: rt.literal('user'),
});

/**
* This defines the structure of how alerts (generated or user attached) are stored in saved objects documents. It also
* represents of an alert after it has been transformed. A generated alert will be transformed by the connector so that
* it matches this structure. User attached alerts do not need to be transformed.
*/
export const AlertCommentRequestRt = rt.type({
type: rt.union([rt.literal(CommentType.generatedAlert), rt.literal(CommentType.alert)]),
alertId: rt.union([rt.array(rt.string), rt.string]),
export const ContextTypeAlertRt = rt.type({
type: rt.literal('alert'),
alertId: rt.string,
index: rt.string,
});

const AttributesTypeUserRt = rt.intersection([ContextTypeUserRt, CommentAttributesBasicRt]);
const AttributesTypeAlertsRt = rt.intersection([AlertCommentRequestRt, CommentAttributesBasicRt]);
const AttributesTypeAlertsRt = rt.intersection([ContextTypeAlertRt, CommentAttributesBasicRt]);
const CommentAttributesRt = rt.union([AttributesTypeUserRt, AttributesTypeAlertsRt]);

export const CommentRequestRt = rt.union([ContextTypeUserRt, AlertCommentRequestRt]);
const ContextBasicRt = rt.union([ContextTypeUserRt, ContextTypeAlertRt]);

export const CommentRequestRt = ContextBasicRt;

export const CommentResponseRt = rt.intersection([
CommentAttributesRt,
Expand All @@ -84,7 +60,7 @@ export const CommentPatchRequestRt = rt.intersection([
* Partial updates are not allowed.
* We want to prevent the user for changing the type without removing invalid fields.
*/
CommentRequestRt,
ContextBasicRt,
rt.type({ id: rt.string, version: rt.string }),
]);

Expand All @@ -95,7 +71,7 @@ export const CommentPatchRequestRt = rt.intersection([
* We ensure that partial updates of CommentContext is not going to happen inside the patch comment route.
*/
export const CommentPatchAttributesRt = rt.intersection([
rt.union([rt.partial(CommentAttributesBasicRt.props), rt.partial(AlertCommentRequestRt.props)]),
rt.union([rt.partial(CommentAttributesBasicRt.props), rt.partial(ContextTypeAlertRt.props)]),
rt.partial(CommentAttributesBasicRt.props),
]);

Expand All @@ -106,6 +82,11 @@ export const CommentsResponseRt = rt.type({
total: rt.number,
});

export enum CommentType {
user = 'user',
alert = 'alert',
}

export const AllCommentsResponseRt = rt.array(CommentResponseRt);

export type CommentAttributes = rt.TypeOf<typeof CommentAttributesRt>;
Expand All @@ -117,4 +98,4 @@ export type CommentsResponse = rt.TypeOf<typeof CommentsResponseRt>;
export type CommentPatchRequest = rt.TypeOf<typeof CommentPatchRequestRt>;
export type CommentPatchAttributes = rt.TypeOf<typeof CommentPatchAttributesRt>;
export type CommentRequestUserType = rt.TypeOf<typeof ContextTypeUserRt>;
export type CommentRequestAlertType = rt.TypeOf<typeof AlertCommentRequestRt>;
export type CommentRequestAlertType = rt.TypeOf<typeof ContextTypeAlertRt>;
35 changes: 0 additions & 35 deletions x-pack/plugins/case/common/api/cases/commentable_case.ts

This file was deleted.

2 changes: 0 additions & 2 deletions x-pack/plugins/case/common/api/cases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,3 @@ export * from './configure';
export * from './comment';
export * from './status';
export * from './user_actions';
export * from './sub_case';
export * from './commentable_case';
14 changes: 0 additions & 14 deletions x-pack/plugins/case/common/api/cases/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,6 @@

import * as rt from 'io-ts';

export enum CaseStatuses {
open = 'open',
'in-progress' = 'in-progress',
closed = 'closed',
}

export const CaseStatusRt = rt.union([
rt.literal(CaseStatuses.open),
rt.literal(CaseStatuses['in-progress']),
rt.literal(CaseStatuses.closed),
]);

export const caseStatuses = Object.values(CaseStatuses);

export const CasesStatusResponseRt = rt.type({
count_open_cases: rt.number,
count_in_progress_cases: rt.number,
Expand Down
80 changes: 0 additions & 80 deletions x-pack/plugins/case/common/api/cases/sub_case.ts

This file was deleted.

25 changes: 12 additions & 13 deletions x-pack/plugins/case/common/api/cases/user_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import { UserRT } from '../user';
/* To the next developer, if you add/removed fields here
* make sure to check this file (x-pack/plugins/case/server/services/user_actions/helpers.ts) too
*/
const UserActionFieldTypeRt = rt.union([
rt.literal('comment'),
rt.literal('connector'),
rt.literal('description'),
rt.literal('pushed'),
rt.literal('tags'),
rt.literal('title'),
rt.literal('status'),
rt.literal('settings'),
rt.literal('sub_case'),
]);
const UserActionFieldRt = rt.array(UserActionFieldTypeRt);
const UserActionFieldRt = rt.array(
rt.union([
rt.literal('comment'),
rt.literal('connector'),
rt.literal('description'),
rt.literal('pushed'),
rt.literal('tags'),
rt.literal('title'),
rt.literal('status'),
rt.literal('settings'),
])
);
const UserActionRt = rt.union([
rt.literal('add'),
rt.literal('create'),
Expand Down Expand Up @@ -60,4 +60,3 @@ export type CaseUserActionsResponse = rt.TypeOf<typeof CaseUserActionsResponseRt

export type UserAction = rt.TypeOf<typeof UserActionRt>;
export type UserActionField = rt.TypeOf<typeof UserActionFieldRt>;
export type UserActionFieldType = rt.TypeOf<typeof UserActionFieldTypeRt>;
Loading

0 comments on commit 5a471d6

Please sign in to comment.