Skip to content

Commit

Permalink
feat: update
Browse files Browse the repository at this point in the history
Signed-off-by: SuZhou-Joe <[email protected]>
  • Loading branch information
SuZhou-Joe committed Aug 8, 2023
1 parent 1bbf441 commit 24e1e9a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 22 deletions.
13 changes: 6 additions & 7 deletions src/core/public/saved_objects/saved_objects_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,9 @@ export class SavedObjectsClient {
};
const currentWorkspaceId = this._getCurrentWorkspace();
let finalWorkspaces;
if (options.workspaces) {
if (options.hasOwnProperty('workspaces')) {
finalWorkspaces = options.workspaces;
} else if (typeof currentWorkspaceId === 'string') {
/**
* When the currentWorkspaceId is an empty string instead of undefined
* It means user is creating object in public workspace.
*/
finalWorkspaces = [currentWorkspaceId];
}

Expand Down Expand Up @@ -383,10 +379,13 @@ export class SavedObjectsClient {

const currentWorkspaceId = this._getCurrentWorkspace();
let finalWorkspaces;
if (options.workspaces) {
if (options.hasOwnProperty('workspaces')) {
finalWorkspaces = options.workspaces;
} else if (typeof currentWorkspaceId === 'string') {
finalWorkspaces = currentWorkspaceId ? [PUBLIC_WORKSPACE, currentWorkspaceId] : undefined;
finalWorkspaces =
currentWorkspaceId === PUBLIC_WORKSPACE
? undefined
: [PUBLIC_WORKSPACE, currentWorkspaceId];
}

const renamedQuery = renameKeys<SavedObjectsFindOptions, any>(renameMap, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,7 @@ export class WorkspaceSavedObjectsClientWrapper {
throw generateWorkspacePermissionError();
}
} else {
const queryDSL = ACL.genereateGetPermittedSavedObjectsQueryDSL(
[
PermissionMode.LibraryRead,
PermissionMode.LibraryWrite,
PermissionMode.Management,
PermissionMode.Read,
PermissionMode.Write,
],
principals,
options.type
);
options.workspaces = permittedWorkspaceIds;
options.queryDSL = queryDSL;
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/core/server/workspaces/workspaces_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ export class WorkspacesClientWithSavedObject implements IWorkspaceDBImpl {
requestDetail: IRequestDetail,
payload: Omit<WorkspaceAttribute, 'id'>
): ReturnType<IWorkspaceDBImpl['create']> {
const { permissions, ...others } = payload;
try {
const result = await this.getSavedObjectClientsFromRequestDetail(requestDetail).create<
Omit<WorkspaceAttribute, 'id'>
>(WORKSPACE_TYPE, payload);
Omit<WorkspaceAttribute, 'id' | 'permissions'>
>(WORKSPACE_TYPE, others, {
permissions,
});
return {
success: true,
result: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ export class SavedObjectsTable extends Component<SavedObjectsTableProps, SavedOb
}

private get workspaceIdQuery() {
return this.state.workspaceId
return this.state.workspaceId !== PUBLIC_WORKSPACE && this.state.workspaceId
? Array.from(new Set([PUBLIC_WORKSPACE, this.state.workspaceId]))
: undefined;
}
Expand Down

0 comments on commit 24e1e9a

Please sign in to comment.