Skip to content

Commit

Permalink
refactor: move getPermittedWorkspaceIds inner find method
Browse files Browse the repository at this point in the history
Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam committed Sep 20, 2023
1 parent b724852 commit 3d3fc1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 26 deletions.
22 changes: 0 additions & 22 deletions src/plugins/workspace/server/permission_control/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 [];
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit 3d3fc1e

Please sign in to comment.