Skip to content

Commit

Permalink
feat: some special logic on specific operation
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <suzhou@amazon.com>
  • Loading branch information
SuZhou-Joe committed Mar 22, 2024
1 parent 637c9c4 commit eaeef0c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ export class WorkspaceIdConsumerWrapper {
const workspaceIdParsedFromRequest = workspaceState?.id;
const workspaceIdsInUserOptions = options?.workspaces;
let finalWorkspaces: string[] = [];
if (options?.hasOwnProperty('workspaces')) {
finalWorkspaces = workspaceIdsInUserOptions || [];
if (workspaceIdsInUserOptions) {
finalWorkspaces = workspaceIdsInUserOptions;
} else if (workspaceIdParsedFromRequest) {
finalWorkspaces = [workspaceIdParsedFromRequest];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,9 @@ export class WorkspaceSavedObjectsClientWrapper {
[WorkspacePermissionMode.LibraryRead, WorkspacePermissionMode.LibraryWrite]
),
},
// By declaring workspaces as empty array,
// workspaces won't be appended automatically into the options.
workspaces: [],
})
).saved_objects.map((item) => item.id);

Expand Down
16 changes: 9 additions & 7 deletions src/plugins/workspace/server/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,15 @@ export class WorkspaceClient implements IWorkspaceClientImpl {
requestDetail: IRequestDetail
): SavedObjectsClientContract | undefined {
return this.savedObjects?.getScopedClient(requestDetail.request, {
excludedWrappers: [WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID],
excludedWrappers: [
WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID,
/**
* workspace object does not have workspaces field
* so need to bypass workspace id consumer wrapper
* for any kind of operation to saved objects client.
*/
WORKSPACE_ID_CONSUMER_WRAPPER_ID,
],
includedHiddenTypes: [WORKSPACE_TYPE],
});
}
Expand All @@ -59,12 +67,6 @@ export class WorkspaceClient implements IWorkspaceClientImpl {
requestDetail: IRequestDetail
): SavedObjectsClientContract {
return this.savedObjects?.getScopedClient(requestDetail.request, {
/**
* workspace object does not have workspaces field
* so need to bypass the consumer wrapper
* or it will append workspaces into the options.workspaces
* when list all the workspaces inside a workspace
*/
excludedWrappers: [WORKSPACE_ID_CONSUMER_WRAPPER_ID],
includedHiddenTypes: [WORKSPACE_TYPE],
}) as SavedObjectsClientContract;
Expand Down

0 comments on commit eaeef0c

Please sign in to comment.