Skip to content

Commit

Permalink
Add some logic check when overwrite a saved object (opensearch-projec…
Browse files Browse the repository at this point in the history
…t#32)

* feat: add some logic check when overwrite a saved object

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* fix: type check

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

* feat: update

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>

---------

Signed-off-by: SuZhoue-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe authored and ruanyl committed Aug 3, 2023
1 parent 29fccee commit 274c96d
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 274c96d

Please sign in to comment.