diff --git a/src/core/server/saved_objects/migrations/core/build_active_mappings.ts b/src/core/server/saved_objects/migrations/core/build_active_mappings.ts index 439a962ad110..01a7ba11b707 100644 --- a/src/core/server/saved_objects/migrations/core/build_active_mappings.ts +++ b/src/core/server/saved_objects/migrations/core/build_active_mappings.ts @@ -34,7 +34,7 @@ import crypto from 'crypto'; import { cloneDeep, mapValues } from 'lodash'; -import { Config } from 'packages/osd-config/target'; +import { Config } from '@osd/config'; import { IndexMapping, SavedObjectsMappingProperties, diff --git a/src/core/server/saved_objects/migrations/core/migration_context.ts b/src/core/server/saved_objects/migrations/core/migration_context.ts index 8a1e9b648bce..91114701d95f 100644 --- a/src/core/server/saved_objects/migrations/core/migration_context.ts +++ b/src/core/server/saved_objects/migrations/core/migration_context.ts @@ -36,7 +36,7 @@ */ import { Logger } from 'src/core/server/logging'; -import { Config } from 'packages/osd-config/target'; +import { Config } from '@osd/config'; import { MigrationOpenSearchClient } from './migration_opensearch_client'; import { SavedObjectsSerializer } from '../../serialization'; import { diff --git a/src/core/server/saved_objects/migrations/opensearch_dashboards/opensearch_dashboards_migrator.ts b/src/core/server/saved_objects/migrations/opensearch_dashboards/opensearch_dashboards_migrator.ts index 468aea3e905d..d6c119569a2e 100644 --- a/src/core/server/saved_objects/migrations/opensearch_dashboards/opensearch_dashboards_migrator.ts +++ b/src/core/server/saved_objects/migrations/opensearch_dashboards/opensearch_dashboards_migrator.ts @@ -35,8 +35,7 @@ import { OpenSearchDashboardsConfigType } from 'src/core/server/opensearch_dashboards_config'; import { BehaviorSubject } from 'rxjs'; - -import { Config } from 'packages/osd-config/target'; +import { Config } from '@osd/config'; import { Logger } from '../../../logging'; import { IndexMapping, SavedObjectsTypeMappingDefinitions } from '../../mappings'; import { SavedObjectUnsanitizedDoc, SavedObjectsSerializer } from '../../serialization'; diff --git a/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.test.ts b/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.test.ts index 961accac262f..9c29684e58e4 100644 --- a/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.test.ts +++ b/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.test.ts @@ -89,17 +89,11 @@ describe('WorkspaceConflictSavedObjectsClientWrapper', () => { }); it(`Should use options.workspaces when get throws error`, async () => { - mockedClient.get.mockRejectedValueOnce( - getSavedObject({ - id: 'dashboard:foo', - workspaces: ['foo'], - error: { - statusCode: 404, - error: 'Not found', - message: 'Not found', - }, - }) - ); + mockedClient.get.mockRejectedValueOnce({ + output: { + statusCode: 404, + }, + }); await wrapperClient.create( 'dashboard', diff --git a/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.ts b/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.ts index a190fcc88613..298d0448031a 100644 --- a/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.ts +++ b/src/plugins/workspace/server/saved_objects/saved_objects_wrapper_for_check_workspace_conflict.ts @@ -35,6 +35,13 @@ export class WorkspaceConflictSavedObjectsClientWrapper { `${props.type}:${props.id}` ); } + + /** + * Workspace is a concept to manage saved objects and the `workspaces` field of each object indicates workspaces the object belongs to. + * When user tries to update an existing object's attribute, workspaces field should be preserved. Below are some cases that this conflict wrapper will take effect: + * 1. Overwrite a object belonging to workspace A with parameter workspace B, in this case we should deny the request as it conflicts with workspaces check. + * 2. Overwrite a object belonging to workspace [A, B] with parameters workspace B, we need to preserved the workspaces fields to [A, B]. + */ public wrapperFactory: SavedObjectsClientWrapperFactory = (wrapperOptions) => { const createWithWorkspaceConflictCheck = async ( type: string, @@ -90,10 +97,11 @@ export class WorkspaceConflictSavedObjectsClientWrapper { ? objects .filter((object) => !!object.id) .map((object) => { - const { type, id } = object; /** - * It requires a check when overwriting objects to target workspaces + * If the object waiting to import has id and type, + * Add it to the buldGetDocs to fetch the latest metadata. */ + const { type, id } = object; return { type, id: id as string,