From ad7eca2fbafa99a09385d22135c60b6c82ac9eea Mon Sep 17 00:00:00 2001 From: Hailong Cui Date: Tue, 12 Sep 2023 18:18:59 +0800 Subject: [PATCH] Remove pulic workspace logic for share API Signed-off-by: Hailong Cui --- src/core/server/saved_objects/routes/index.ts | 1 - src/core/server/saved_objects/routes/share.ts | 24 ++++++------------- .../saved_objects/service/lib/repository.ts | 11 ++------- .../service/saved_objects_client.ts | 6 ++--- 4 files changed, 12 insertions(+), 30 deletions(-) diff --git a/src/core/server/saved_objects/routes/index.ts b/src/core/server/saved_objects/routes/index.ts index 4794c00a9b78..00ee383ae38a 100644 --- a/src/core/server/saved_objects/routes/index.ts +++ b/src/core/server/saved_objects/routes/index.ts @@ -74,7 +74,6 @@ export function registerRoutes({ registerImportRoute(router, config); registerCopyRoute(router, config); registerResolveImportErrorsRoute(router, config); - // TODO disable when workspace is not enabled registerShareRoute(router); const internalRouter = http.createRouter('/internal/saved_objects/'); diff --git a/src/core/server/saved_objects/routes/share.ts b/src/core/server/saved_objects/routes/share.ts index e3d87ecd7098..6d767e08c227 100644 --- a/src/core/server/saved_objects/routes/share.ts +++ b/src/core/server/saved_objects/routes/share.ts @@ -8,7 +8,7 @@ import { IRouter } from '../../http'; import { exportSavedObjectsToStream } from '../export'; import { validateObjects } from './utils'; import { collectSavedObjects } from '../import/collect_saved_objects'; -import { PUBLIC_WORKSPACE_ID, WORKSPACE_TYPE } from '../../../utils'; +import { WORKSPACE_TYPE } from '../../../utils'; const SHARE_LIMIT = 10000; @@ -66,17 +66,11 @@ export const registerShareRoute = (router: IRouter) => { const savedObjects = collectSavedObjectsResult.collectedObjects; - const nonPublicSharedObjects = savedObjects - // non-public - .filter( - (obj) => - obj.workspaces && - obj.workspaces.length > 0 && - !obj.workspaces.includes(PUBLIC_WORKSPACE_ID) - ) + const sharedObjects = savedObjects + .filter((obj) => obj.workspaces && obj.workspaces.length > 0) .map((obj) => ({ id: obj.id, type: obj.type, workspaces: obj.workspaces })); - if (nonPublicSharedObjects.length === 0) { + if (sharedObjects.length === 0) { return res.ok({ body: savedObjects.map((savedObject) => ({ type: savedObject.type, @@ -86,13 +80,9 @@ export const registerShareRoute = (router: IRouter) => { }); } - const response = await savedObjectsClient.addToWorkspaces( - nonPublicSharedObjects, - targetWorkspaceIds, - { - workspaces: sourceWorkspaceId ? [sourceWorkspaceId] : undefined, - } - ); + const response = await savedObjectsClient.addToWorkspaces(sharedObjects, targetWorkspaceIds, { + workspaces: sourceWorkspaceId ? [sourceWorkspaceId] : undefined, + }); return res.ok({ body: response, }); diff --git a/src/core/server/saved_objects/service/lib/repository.ts b/src/core/server/saved_objects/service/lib/repository.ts index be7c093b59c9..9305d7e8d585 100644 --- a/src/core/server/saved_objects/service/lib/repository.ts +++ b/src/core/server/saved_objects/service/lib/repository.ts @@ -90,8 +90,6 @@ import { FIND_DEFAULT_PER_PAGE, SavedObjectsUtils, } from './utils'; -import { PUBLIC_WORKSPACE_ID } from '../../../../utils/constants'; - // BEWARE: The SavedObjectClient depends on the implementation details of the SavedObjectsRepository // so any breaking changes to this repository are considered breaking changes to the SavedObjectsClient. @@ -1424,11 +1422,7 @@ export class SavedObjectsRepository { // saved objects must exist in specified workspace if (options.workspaces) { const invalidObjects = savedObjects.filter((obj) => { - if ( - obj.workspaces && - obj.workspaces.length > 0 && - !obj.workspaces.includes(PUBLIC_WORKSPACE_ID) - ) { + if (obj.workspaces && obj.workspaces.length > 0) { return intersection(obj.workspaces, options.workspaces).length === 0; } return false; @@ -1469,7 +1463,7 @@ export class SavedObjectsRepository { { script: { source: ` - if (params.workspaces != null && ctx._source.workspaces != null && !ctx._source.workspaces?.contains(params.globalWorkspaceId)) { + if (params.workspaces != null && ctx._source.workspaces != null) { ctx._source.workspaces.addAll(params.workspaces); HashSet workspacesSet = new HashSet(ctx._source.workspaces); ctx._source.workspaces = new ArrayList(workspacesSet); @@ -1480,7 +1474,6 @@ export class SavedObjectsRepository { params: { time, workspaces, - globalWorkspaceId: PUBLIC_WORKSPACE_ID, }, }, }, diff --git a/src/core/server/saved_objects/service/saved_objects_client.ts b/src/core/server/saved_objects/service/saved_objects_client.ts index b6f5abea26ef..c94f3e980b31 100644 --- a/src/core/server/saved_objects/service/saved_objects_client.ts +++ b/src/core/server/saved_objects/service/saved_objects_client.ts @@ -468,16 +468,16 @@ export class SavedObjectsClient { /** * Adds workspace to SavedObjects * - * @param objects + * @param savedObjects * @param workspaces * @param options */ addToWorkspaces = async ( - objects: SavedObjectsShareObjects[], + savedObjects: SavedObjectsShareObjects[], workspaces: string[], options: SavedObjectsAddToWorkspacesOptions = {} ): Promise => { - return await this._repository.addToWorkspaces(objects, workspaces, options); + return await this._repository.addToWorkspaces(savedObjects, workspaces, options); }; /**