Skip to content

Commit

Permalink
feat: add some logic check when overwrite a saved object
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhoue-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Jun 26, 2023
1 parent cfe506d commit 8d80fd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/core/server/saved_objects/service/lib/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/core/types/saved_objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export interface SavedObject<T = unknown> {
* space.
*/
originId?: string;
workspaces?: string[];
}

export interface SavedObjectError {
Expand Down

0 comments on commit 8d80fd8

Please sign in to comment.