Skip to content

Commit

Permalink
[SecuritySolution] Fix behavior of pinnend events and comments on uns…
Browse files Browse the repository at this point in the history
…aved timelines (#178212)

> This PR is the implementation of the results in the discussion around
[[ADR] 0001 - Saving of timeline-associated saved
objects](#179830)

## Summary

As described in #178182, the
removal of autosave on timeline resulted in a regression in which pinned
events and comments on unsaved timelines are lost.

In this PR, we're re-introducing the previous behavior by saving the
timeline when a comment is made / an event is pinned on an unsaved
timeline. The timeline will then be auto-saved in a `draft` state
instead of an `active` state that would persist it permanently.

Fixes #178182

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
janmonschke and kibanamachine authored Apr 8, 2024
1 parent d6a942b commit 8e9fa4a
Show file tree
Hide file tree
Showing 29 changed files with 623 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { ErrorSchema } from './error_schema';

export const BareNoteSchema = runtimeTypes.intersection([
runtimeTypes.type({
timelineId: unionWithNullType(runtimeTypes.string),
timelineId: runtimeTypes.string,
}),
runtimeTypes.partial({
eventId: unionWithNullType(runtimeTypes.string),
Expand All @@ -51,9 +51,6 @@ export const NoteRuntimeType = runtimeTypes.intersection([
noteId: runtimeTypes.string,
version: runtimeTypes.string,
}),
runtimeTypes.partial({
timelineVersion: unionWithNullType(runtimeTypes.string),
}),
]);

export type Note = runtimeTypes.TypeOf<typeof NoteRuntimeType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ components:
type: object
properties:
columns:
$ref: '#/components/schemas/ColumnHeaderResult'
$ref: '#/components/schemas/ColumnHeaderResult'
created:
type: number
createdBy:
Expand Down Expand Up @@ -244,19 +244,13 @@ components:
type: string
version:
type: string
timelineVersion:
nullable: true
type: string
GlobalNote:
type: object
properties:
noteId:
type: string
version:
type: string
timelineVersion:
nullable: true
type: string
note:
type: string
timelineId:
Expand All @@ -278,8 +272,6 @@ components:
type: string
version:
type: string
timelineVersion:
type: string
RowRendererId:
type: string
enum:
Expand Down Expand Up @@ -384,8 +376,6 @@ components:
type: string
version:
type: string
timelineVersion:
type: string
Sort:
type: object
properties:
Expand Down Expand Up @@ -415,30 +405,30 @@ components:
description: The status of the timeline. Valid values are `active`, `draft`, and `immutable`.
ImportTimelines:
allOf:
- $ref: '#/components/schemas/SavedTimeline'
- type: object
properties:
savedObjectId:
type: string
nullable: true
version:
- $ref: '#/components/schemas/SavedTimeline'
- type: object
properties:
savedObjectId:
type: string
nullable: true
version:
type: string
nullable: true
globalNotes:
nullable: true
type: array
items:
$ref: '#/components/schemas/BareNote'
eventNotes:
nullable: true
type: array
items:
$ref: '#/components/schemas/BareNote'
pinnedEventIds:
nullable: true
type: array
items:
type: string
nullable: true
globalNotes:
nullable: true
type: array
items:
$ref: '#/components/schemas/BareNote'
eventNotes:
nullable: true
type: array
items:
$ref: '#/components/schemas/BareNote'
pinnedEventIds:
nullable: true
type: array
items:
type: string
ImportTimelineResult:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Elastic Security - Timeline - Notes API
version: 8.9.0
version: 8.14.0
externalDocs:
url: https://www.elastic.co/guide/en/security/current/timeline-api-update.html
description: Documentation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export const pinnedEventIds = unionWithNullType(runtimeTypes.array(runtimeTypes.
export const persistPinnedEventSchema = runtimeTypes.intersection([
runtimeTypes.type({
eventId: runtimeTypes.string,
timelineId: runtimeTypes.string,
}),
runtimeTypes.partial({
pinnedEventId: unionWithNullType(runtimeTypes.string),
timelineId: unionWithNullType(runtimeTypes.string),
}),
]);

Expand Down Expand Up @@ -51,9 +51,6 @@ export const PinnedEventRuntimeType = runtimeTypes.intersection([
version: runtimeTypes.string,
}),
BarePinnedEventType,
runtimeTypes.partial({
timelineVersion: unionWithNullType(runtimeTypes.string),
}),
]);

export interface PinnedEvent extends runtimeTypes.TypeOf<typeof PinnedEventRuntimeType> {}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
openapi: 3.0.0
info:
title: Elastic Security - Timeline - Pinned Event API (https://www.elastic.co/guide/en/security/current/_pin_an_event_to_an_existing_timeline.html)
version: 8.9.0
version: 8.14.0
servers:
- url: 'http://{kibana_host}:{port}'
variables:
Expand Down Expand Up @@ -33,7 +33,6 @@ paths:
nullable: true
timelineId:
type: string
nullable: true
responses:
200:
description: Indicate the event was successfully pinned in the timeline.
Expand All @@ -55,4 +54,4 @@ paths:
message:
type: string
required:
- data
- data
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { unionWithNullType } from '../../../utility_types';
*/
const SavedNoteRuntimeType = runtimeTypes.intersection([
runtimeTypes.type({
timelineId: unionWithNullType(runtimeTypes.string),
timelineId: runtimeTypes.string,
}),
runtimeTypes.partial({
eventId: unionWithNullType(runtimeTypes.string),
Expand All @@ -39,11 +39,6 @@ export const SavedObjectNoteRuntimeType = runtimeTypes.intersection([
}),
runtimeTypes.partial({
noteId: runtimeTypes.string,
timelineVersion: runtimeTypes.union([
runtimeTypes.string,
runtimeTypes.null,
runtimeTypes.undefined,
]),
}),
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const SavedObjectPinnedEventRuntimeType = runtimeTypes.intersection([
}),
runtimeTypes.partial({
pinnedEventId: unionWithNullType(runtimeTypes.string),
timelineVersion: unionWithNullType(runtimeTypes.string),
}),
]);

Expand Down
Loading

0 comments on commit 8e9fa4a

Please sign in to comment.