diff --git a/src/core/server/index.ts b/src/core/server/index.ts index b0e1179fbc3b..f497bed22755 100644 --- a/src/core/server/index.ts +++ b/src/core/server/index.ts @@ -341,7 +341,6 @@ export { StringValidation, StringValidationRegex, StringValidationRegexString, - UI_SETTINGS_SAVED_OBJECTS_TYPE, } from './ui_settings'; export { diff --git a/src/core/server/ui_settings/index.ts b/src/core/server/ui_settings/index.ts index 3738afef95b1..7912c0af84af 100644 --- a/src/core/server/ui_settings/index.ts +++ b/src/core/server/ui_settings/index.ts @@ -49,5 +49,3 @@ export { StringValidationRegex, StringValidationRegexString, } from './types'; - -export { UI_SETTINGS_SAVED_OBJECTS_TYPE } from './saved_objects/ui_settings'; diff --git a/src/core/server/ui_settings/saved_objects/ui_settings.ts b/src/core/server/ui_settings/saved_objects/ui_settings.ts index 968c3ceb5691..a56b12ed2063 100644 --- a/src/core/server/ui_settings/saved_objects/ui_settings.ts +++ b/src/core/server/ui_settings/saved_objects/ui_settings.ts @@ -31,10 +31,8 @@ import { SavedObjectsType } from '../../saved_objects'; import { migrations } from './migrations'; -export const UI_SETTINGS_SAVED_OBJECTS_TYPE = 'config'; - export const uiSettingsType: SavedObjectsType = { - name: UI_SETTINGS_SAVED_OBJECTS_TYPE, + name: 'config', hidden: false, namespaceType: 'single', mappings: { 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 298d0448031a..838b689328bf 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 @@ -20,8 +20,8 @@ import { const errorContent = (error: Boom.Boom) => error.output.payload; const filterWorkspacesAccordingToSourceWorkspaces = ( - targetWorkspaces?: string[], - baseWorkspaces?: string[] + targetWorkspaces?: SavedObjectsBaseOptions['workspaces'], + baseWorkspaces?: SavedObjectsBaseOptions['workspaces'] ): string[] => targetWorkspaces?.filter((item) => !baseWorkspaces?.includes(item)) || []; export class WorkspaceConflictSavedObjectsClientWrapper { @@ -110,7 +110,7 @@ export class WorkspaceConflictSavedObjectsClientWrapper { }) : []; const objectsConflictWithWorkspace: SavedObject[] = []; - const objectsMapWorkspaces: Record = {}; + const objectsMapWorkspaces: Record = {}; if (bulkGetDocs.length) { /** * Get latest status of objects diff --git a/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts b/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts index 28c9aad535af..741d7ef3662e 100644 --- a/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts +++ b/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.test.ts @@ -92,11 +92,11 @@ describe('WorkspaceIdConsumerWrapper', () => { expect(() => wrapperClient.bulkCreate([ getSavedObject({ - type: DATA_SOURCE_SAVED_OBJECT_TYPE, + type: 'config', id: 'foo', }), ]) - ).toThrow('type: data-source is not allowed to create within a workspace.'); + ).toThrow('type: config is not allowed to create within a workspace.'); expect(() => wrapperClient.bulkCreate([ diff --git a/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.ts b/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.ts index 72bd6305b61d..1466fec3897c 100644 --- a/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.ts +++ b/src/plugins/workspace/server/saved_objects/workspace_id_consumer_wrapper.ts @@ -12,13 +12,13 @@ import { SavedObjectsCheckConflictsObject, OpenSearchDashboardsRequest, SavedObjectsFindOptions, - UI_SETTINGS_SAVED_OBJECTS_TYPE, - SavedObjectsErrorHelpers, } from '../../../../core/server'; import { DATA_SOURCE_SAVED_OBJECT_TYPE } from '../../../../plugins/data_source/common'; type WorkspaceOptions = Pick | undefined; +const UI_SETTINGS_SAVED_OBJECTS_TYPE = 'config'; + export class WorkspaceIdConsumerWrapper { private formatWorkspaceIdParams( request: OpenSearchDashboardsRequest, @@ -72,30 +72,24 @@ export class WorkspaceIdConsumerWrapper { options: SavedObjectsCreateOptions = {} ) => { const { workspaces } = this.formatWorkspaceIdParams(wrapperOptions.request, options); - const disallowedSavedObjects = objects.filter((item) => { - // If create out of workspace, allow the operation - if (!workspaces?.length && !item.workspaces?.length) { + const allowedSavedObjects = objects.filter((item) => { + const isImportIntoWorkspace = workspaces?.length || item.workspaces?.length; + // config can not be created inside a workspace + if (this.isConfigType(item.type) && isImportIntoWorkspace) { return false; } - // config and data-sources can not be created inside a workspace - return this.isConfigType(item.type) || this.isDataSourceType(item.type); - }); - - if (!disallowedSavedObjects?.length) { - return wrapperOptions.client.bulkCreate( - objects, - this.formatWorkspaceIdParams(wrapperOptions.request, options) - ); - } + // For 2.14, data source can only be created without workspace info + if (this.isDataSourceType(item.type) && isImportIntoWorkspace) { + return false; + } - const disallowedTypes = [...new Set(disallowedSavedObjects.map((item) => item.type))]; + return true; + }); - throw SavedObjectsErrorHelpers.decorateBadRequestError( - new Error(''), - `${disallowedTypes.map((item) => `type: ${item}`).join(', ')} ${ - disallowedTypes.length > 1 ? 'are' : 'is' - } not allowed to create within a workspace.` + return wrapperOptions.client.bulkCreate( + allowedSavedObjects, + this.formatWorkspaceIdParams(wrapperOptions.request, options) ); }, checkConflicts: (