Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Workspace] Only OSD admin can create workspace #6831

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ffb4a0f
Only OSD admin can create workspace
yubonluo May 24, 2024
2ba437e
Changeset file for PR #6831 created/updated
opensearch-changeset-bot[bot] May 24, 2024
ec1f413
Changeset file for PR #6831 created/updated
opensearch-changeset-bot[bot] May 24, 2024
893b039
optimize the code
yubonluo May 27, 2024
5ec5b15
Merge branch 'main' of github.com:opensearch-project/OpenSearch-Dashb…
yubonluo May 27, 2024
832b1e5
Merge branch 'main-create-workspace-OSDAdmin' of github.com:yubonluo/…
yubonluo May 27, 2024
11f6396
delete useless code
yubonluo May 27, 2024
dec5cbe
add integration tests
yubonluo May 27, 2024
d83e340
optimize the code
yubonluo May 27, 2024
fa6809d
delete useless code
yubonluo May 27, 2024
e979d77
optimize the code
yubonluo May 27, 2024
87ebeef
optimize the code
yubonluo May 27, 2024
5b9a786
optimize the code
yubonluo May 27, 2024
0cfa4b0
add overwrite check
yubonluo May 27, 2024
41b17ab
optimize the code
yubonluo May 27, 2024
a179855
optimize the code
yubonluo May 27, 2024
deb4341
solve conflict
yubonluo May 28, 2024
9417e21
Add the logic of whether to update the operation
yubonluo May 30, 2024
8816831
Merge branch 'main' of github.com:opensearch-project/OpenSearch-Dashb…
yubonluo May 30, 2024
a10a23b
Merge branch 'main' into main-create-workspace-OSDAdmin
yubonluo May 31, 2024
8c3675b
optimize the code
yubonluo May 31, 2024
2e2350b
Merge branch 'main-create-workspace-OSDAdmin' of github.com:yubonluo/…
yubonluo May 31, 2024
8a5721e
Optimize the code
yubonluo May 31, 2024
edf33c2
Merge branch 'main' into main-create-workspace-OSDAdmin
yubonluo Jun 3, 2024
35b04bd
Optimize the code
yubonluo Jun 3, 2024
4962ab2
Merge branch 'main-create-workspace-OSDAdmin' of github.com:yubonluo/…
yubonluo Jun 3, 2024
acadee6
Merge branch 'main' into main-create-workspace-OSDAdmin
yubonluo Jun 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/6831.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
feat:
- [Workspace] Only OSD admin can create workspace ([#6831](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/6831))
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export class WorkspacePlugin implements Plugin<WorkspacePluginSetup, WorkspacePl
const globalConfig = await this.globalConfig$.pipe(first()).toPromise();
const isPermissionControlEnabled = globalConfig.savedObjects.permission.enabled === true;

this.client = new WorkspaceClient(core);
this.client = new WorkspaceClient(core, isPermissionControlEnabled);

await this.client.setup(core);

Expand Down
18 changes: 17 additions & 1 deletion src/plugins/workspace/server/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { i18n } from '@osd/i18n';
import { getWorkspaceState } from '../../../core/server/utils';
import {
SavedObject,
SavedObjectsClientContract,
Expand Down Expand Up @@ -32,12 +33,18 @@
defaultMessage: 'workspace name has already been used, try with a different name',
});

const INVALID_PERMISSION_ERROR = i18n.translate('workspace.invalid.permission.error', {
defaultMessage: 'No permission to perform this operation, please contact OSD admin',
});

export class WorkspaceClient implements IWorkspaceClientImpl {
private setupDep: CoreSetup;
private savedObjects?: SavedObjectsServiceStart;
private isPermissionControlEnabled: boolean;

constructor(core: CoreSetup) {
constructor(core: CoreSetup, isPermissionControlEnabled: boolean) {
this.setupDep = core;
this.isPermissionControlEnabled = isPermissionControlEnabled;
}

private getScopedClientWithoutPermission(
Expand Down Expand Up @@ -77,6 +84,14 @@
private formatError(error: Error | any): string {
return error.message || error.error || 'Error';
}
private hasOSDAdminPermission(requestDetail: IRequestDetail) {
if (
yubonluo marked this conversation as resolved.
Show resolved Hide resolved
this.isPermissionControlEnabled &&
!getWorkspaceState(requestDetail.request).isDashboardAdmin
) {
throw new Error(INVALID_PERMISSION_ERROR);

Check warning on line 92 in src/plugins/workspace/server/workspace_client.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/server/workspace_client.ts#L92

Added line #L92 was not covered by tests
}
}
public async setup(core: CoreSetup): Promise<IResponse<boolean>> {
this.setupDep.savedObjects.registerType(workspace);
return {
Expand All @@ -89,6 +104,7 @@
payload: Omit<WorkspaceAttributeWithPermission, 'id'>
): ReturnType<IWorkspaceClientImpl['create']> {
try {
this.hasOSDAdminPermission(requestDetail);

Check warning on line 107 in src/plugins/workspace/server/workspace_client.ts

View check run for this annotation

Codecov / codecov/patch

src/plugins/workspace/server/workspace_client.ts#L107

Added line #L107 was not covered by tests
yubonluo marked this conversation as resolved.
Show resolved Hide resolved
const { permissions, ...attributes } = payload;
const id = generateRandomId(WORKSPACE_ID_SIZE);
const client = this.getSavedObjectClientsFromRequestDetail(requestDetail);
Expand Down
Loading