From 3d1be7d0f5ffb7a29240cb98a4dc8d434d149279 Mon Sep 17 00:00:00 2001 From: SuZhoue-Joe Date: Sun, 25 Jun 2023 19:23:16 +0800 Subject: [PATCH] feat: add some logic check when overwrite a saved object Signed-off-by: SuZhoue-Joe --- .../server/saved_objects/service/lib/repository.ts | 14 +++++++++++++- src/core/types/saved_objects.ts | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index 4a8ceb5e0b3b..b992adc0f24e 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -280,6 +280,18 @@ export class SavedObjectsRepository { } } + let savedObjectWorkspaces; + + if (id && overwrite) { + // do not overwrite workspaces + const currentItem = await this.get(type, id); + if (currentItem && currentItem.workspaces) { + savedObjectWorkspaces = currentItem.workspaces; + } + } else { + savedObjectWorkspaces = workspaces; + } + const migrated = this._migrator.migrateDocument({ id, type, @@ -290,7 +302,7 @@ export class SavedObjectsRepository { migrationVersion, updated_at: time, ...(Array.isArray(references) && { references }), - ...(Array.isArray(workspaces) && { workspaces }), + ...(Array.isArray(savedObjectWorkspaces) && { workspaces: savedObjectWorkspaces }), }); const raw = this._serializer.savedObjectToRaw(migrated as SavedObjectSanitizedDoc); diff --git a/src/core/types/saved_objects.ts b/src/core/types/saved_objects.ts index 81e1ed029ddc..47faffb0b922 100644 --- a/src/core/types/saved_objects.ts +++ b/src/core/types/saved_objects.ts @@ -113,6 +113,7 @@ export interface SavedObject { * space. */ originId?: string; + workspaces?: string[]; } export interface SavedObjectError {