From 3d3fc1eaeb81ad4c7c95bacd39a7ccb15ac42a87 Mon Sep 17 00:00:00 2001 From: Lin Wang Date: Tue, 19 Sep 2023 14:06:15 +0800 Subject: [PATCH] refactor: move getPermittedWorkspaceIds inner find method Signed-off-by: Lin Wang --- .../server/permission_control/client.ts | 22 ------------------- .../workspace_saved_objects_client_wrapper.ts | 14 ++++++++---- 2 files changed, 10 insertions(+), 26 deletions(-) diff --git a/src/plugins/workspace/server/permission_control/client.ts b/src/plugins/workspace/server/permission_control/client.ts index 3740518995d8..2c7d16ad9422 100644 --- a/src/plugins/workspace/server/permission_control/client.ts +++ b/src/plugins/workspace/server/permission_control/client.ts @@ -10,7 +10,6 @@ import { SavedObjectsBulkGetObject, SavedObjectsServiceStart, Logger, - WORKSPACE_TYPE, } from '../../../../core/server'; import { WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID } from '../../common/constants'; import { getPrincipalsFromRequest } from '../utils'; @@ -130,25 +129,4 @@ export class SavedObjectsPermissionControl { }; }, {}); } - - public async getPermittedWorkspaceIds( - request: OpenSearchDashboardsRequest, - permissionModes: SavedObjectsPermissionModes - ) { - const principals = getPrincipalsFromRequest(request); - const savedObjectClient = this.getScopedClient?.(request); - try { - const result = await savedObjectClient?.find({ - type: [WORKSPACE_TYPE], - ACLSearchParams: { - permissionModes, - principals, - }, - perPage: 999, - }); - return result?.saved_objects.map((item) => item.id); - } catch (e) { - return []; - } - } } diff --git a/src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts b/src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts index 8e86b9ce004f..5a8f59af9e37 100644 --- a/src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts +++ b/src/plugins/workspace/server/saved_objects/workspace_saved_objects_client_wrapper.ts @@ -378,10 +378,16 @@ export class WorkspaceSavedObjectsClientWrapper { options.ACLSearchParams.permissionModes = workspaceInnerPermissionModes; options.ACLSearchParams.principals = principals; } else { - const permittedWorkspaceIds = await this.permissionControl.getPermittedWorkspaceIds( - wrapperOptions.request, - workspaceInnerPermissionModes - ); + const permittedWorkspaceIds = ( + await wrapperOptions.client.find({ + type: WORKSPACE_TYPE, + perPage: 999, + ACLSearchParams: { + principals, + permissionModes: workspaceInnerPermissionModes, + }, + }) + ).saved_objects.map((item) => item.id); if (options.workspaces) { const permittedWorkspaces = options.workspaces.filter((item) =>