Skip to content

Commit

Permalink
[Workspace] add missing method for workspace client interface (opense…
Browse files Browse the repository at this point in the history
…arch-project#9070)

* add missing method for workspace client interface

Signed-off-by: yubonluo <[email protected]>

* Changeset file for PR opensearch-project#9070 created/updated

* fix bootstrap issue

Signed-off-by: yubonluo <[email protected]>

* fix error

Signed-off-by: yubonluo <[email protected]>

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
yubonluo and opensearch-changeset-bot[bot] authored Dec 25, 2024
1 parent 6e851ff commit c836e60
Show file tree
Hide file tree
Showing 23 changed files with 147 additions and 54 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/9070.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
refactor:
- [Workspace] add missing method for workspace client interface ([#9070](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/9070))
2 changes: 2 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ export {
WorkspaceAttributeWithPermission,
UiSettingScope,
PermissionModeId,
WorkspacePermissionMode,
WorkspaceFindOptions,
} from '../types';

export {
Expand Down
91 changes: 88 additions & 3 deletions src/core/public/workspace/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { WorkspaceAttribute } from '../../types';
import {
SavedObjectPermissions,
WorkspaceAttribute,
WorkspaceAttributeWithPermission,
WorkspaceFindOptions,
} from '../../types';

export type WorkspaceObject = WorkspaceAttribute & { readonly?: boolean; owner?: boolean };

Expand All @@ -25,8 +30,6 @@ export interface AssociationResult {
/**
* This interface representing a client for managing workspace-related operations.
* Workspace client should implement this interface.
*
* TODO: Refactor the current workspace client implementation in workspace plugin to add the missing operations to this interface
*/
export interface IWorkspaceClient {
/**
Expand Down Expand Up @@ -74,6 +77,88 @@ export interface IWorkspaceClient {
): Promise<IWorkspaceResponse<AssociationResult[]>>;

ui(): WorkspaceUI;

/**
* A bypass layer to get current workspace id
*/
getCurrentWorkspaceId(): IWorkspaceResponse<WorkspaceAttributeWithPermission['id']>;

/**
* Do a find in the latest workspace list with current workspace id
*/
getCurrentWorkspace(): Promise<IWorkspaceResponse<WorkspaceAttributeWithPermission>>;

/**
* Create a workspace
*
* @param attributes
* @returns {Promise<IResponse<Pick<WorkspaceAttribute, 'id'>>>} id of the new created workspace
*/
create(
attributes: Omit<WorkspaceAttribute, 'id'>,
settings: {
dataSources?: string[];
permissions?: SavedObjectPermissions;
dataConnections?: string[];
}
): Promise<IWorkspaceResponse<Pick<WorkspaceAttributeWithPermission, 'id'>>>;

/**
* Deletes a workspace by workspace id
*
* @param id
* @returns {Promise<IWorkspaceResponse<null>>} result for this operation
*/
delete(id: string): Promise<IWorkspaceResponse<null>>;

/**
* Search for workspaces
*
* @param {object} [options={}]
* @property {string} options.search
* @property {string} options.searchFields - see OpenSearch Simple Query String
* Query field argument for more information
* @property {integer} [options.page=1]
* @property {integer} [options.perPage=20]
* @property {array} options.fields
* @property {string array} permissionModes
* @returns A find result with workspaces matching the specified search.
*/
list(
options?: WorkspaceFindOptions
): Promise<
IWorkspaceResponse<{
workspaces: WorkspaceAttributeWithPermission[];
total: number;
per_page: number;
page: number;
}>
>;

/**
* Fetches a single workspace by a workspace id
*
* @param {string} id
* @returns {Promise<IWorkspaceResponse<WorkspaceAttributeWithPermission>>} The metadata of the workspace for the given id.
*/
get(id: string): Promise<IWorkspaceResponse<WorkspaceAttributeWithPermission>>;

/**
* Updates a workspace
*
* @param {string} id
* @param {object} attributes
* @returns {Promise<IWorkspaceResponse<boolean>>} result for this operation
*/
update(
id: string,
attributes: Partial<WorkspaceAttribute>,
settings: {
dataSources?: string[];
permissions?: SavedObjectPermissions;
dataConnections?: string[];
}
): Promise<IWorkspaceResponse<boolean>>;
}

interface DataSourceAssociationProps {
Expand Down
7 changes: 7 additions & 0 deletions src/core/public/workspace/workspaces_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ describe('WorkspacesService', () => {
associate: jest.fn(),
dissociate: jest.fn(),
ui: jest.fn(),
list: jest.fn(),
get: jest.fn(),
getCurrentWorkspace: jest.fn(),
getCurrentWorkspaceId: jest.fn(),
update: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
};
workspacesSetUp.setClient(client);
expect(workspacesStart.client$.value).toEqual(client);
Expand Down
8 changes: 7 additions & 1 deletion src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,13 @@ export {
MetricsServiceStart,
} from './metrics';

export { AppCategory, WorkspaceAttribute, PermissionModeId } from '../types';
export {
AppCategory,
WorkspaceAttribute,
PermissionModeId,
WorkspaceFindOptions,
WorkspacePermissionMode,
} from '../types';
export {
DEFAULT_APP_CATEGORIES,
WORKSPACE_TYPE,
Expand Down
17 changes: 17 additions & 0 deletions src/core/types/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,20 @@ export interface WorkspaceAttributeWithPermission extends WorkspaceAttribute {
permissions?: Permissions;
permissionMode?: PermissionModeId;
}

export enum WorkspacePermissionMode {
Read = 'read',
Write = 'write',
LibraryRead = 'library_read',
LibraryWrite = 'library_write',
}

export interface WorkspaceFindOptions {
page?: number;
perPage?: number;
search?: string;
searchFields?: string[];
sortField?: string;
sortOrder?: string;
permissionModes?: WorkspacePermissionMode[];
}
7 changes: 0 additions & 7 deletions src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ export const WORKSPACE_UI_SETTINGS_CLIENT_WRAPPER_ID = 'workspace_ui_settings';
*/
export const DEFAULT_WORKSPACE = 'defaultWorkspace';

export enum WorkspacePermissionMode {
Read = 'read',
Write = 'write',
LibraryRead = 'library_read',
LibraryWrite = 'library_write',
}

export const WORKSPACE_ID_CONSUMER_WRAPPER_ID = 'workspace_id_consumer';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { WorkspaceFormDataState } from '../workspace_form';
import { WorkspaceUseCase } from '../../types';
import { RightSidebarScrollField, RIGHT_SIDEBAR_SCROLL_KEY } from './utils';
import { WorkspaceCreateActionPanel } from './workspace_create_action_panel';
import { WorkspacePermissionMode } from '../../../common/constants';

const SCROLL_FIELDS = {
[RightSidebarScrollField.Name]: i18n.translate('workspace.form.summary.panel.name.title', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*/

import { i18n } from '@osd/i18n';
import { WorkspacePermissionMode } from '../../../common/constants';
import { PermissionModeId } from '../../../../../core/public';
import { PermissionModeId, WorkspacePermissionMode } from '../../../../../core/public';
import { WORKSPACE_ACCESS_LEVEL_NAMES } from '../../constants';

export enum WorkspaceOperationType {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import type {
AppMountParameters,
ApplicationStart,
SavedObjectsStart,
WorkspacePermissionMode,
} from '../../../../../core/public';
import type { WorkspacePermissionMode } from '../../../common/constants';
import type { WorkspaceOperationType, WorkspacePermissionItemType } from './constants';
import { DataSourceConnection } from '../../../common/types';
import { DataSourceManagementPluginSetup } from '../../../../../plugins/data_source_management/public';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import {
isWorkspacePermissionSetting,
getPermissionModeName,
} from './utils';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionItemType, optionIdToWorkspacePermissionModesMap } from './constants';
import { DataSourceConnectionType } from '../../../common/types';
import { WorkspaceFormErrorCode } from './types';
import { PermissionModeId } from '../../../../../core/public';
import { PermissionModeId, WorkspacePermissionMode } from '../../../../../core/public';

describe('convertPermissionSettingsToPermissions', () => {
it('should return undefined if permission items not provided', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { i18n } from '@osd/i18n';
import { euiPaletteColorBlind } from '@elastic/eui';
import type { SavedObjectPermissions } from '../../../../../core/types';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionMode } from '../../../../../core/public';
import { isUseCaseFeatureConfig } from '../../utils';
import {
optionIdToWorkspacePermissionModesMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WorkspacePermissionSettingInputProps,
} from './workspace_permission_setting_input';
import { WorkspacePermissionItemType } from './constants';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionMode } from '../../../../../core/public';

const setup = (options?: Partial<WorkspacePermissionSettingInputProps>) => {
const onGroupOrUserIdChangeMock = jest.fn();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
EuiFieldText,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionMode } from '../../../../../core/public';
import {
WorkspacePermissionItemType,
optionIdToWorkspacePermissionModesMap,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
WorkspacePermissionSettingPanelProps,
} from './workspace_permission_setting_panel';
import { WorkspacePermissionItemType } from './constants';
import { WorkspacePermissionMode } from '../../../common/constants';
import { WorkspacePermissionMode } from '../../../../../core/public';

const setup = (options?: Partial<WorkspacePermissionSettingPanelProps>) => {
const onChangeMock = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/public/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { i18n } from '@osd/i18n';

import { WorkspaceCollaboratorAccessLevel } from './types';
import { WorkspacePermissionMode } from '../common/constants';
import { WorkspacePermissionMode } from '../../../core/public';

export const WORKSPACE_ACCESS_LEVEL_NAMES: { [key in WorkspaceCollaboratorAccessLevel]: string } = {
readOnly: i18n.translate('workspace.accessLevel.readOnlyName', {
Expand Down
13 changes: 2 additions & 11 deletions src/plugins/workspace/public/workspace_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
WorkspacesSetup,
IWorkspaceClient,
IWorkspaceResponse as IResponse,
WorkspaceFindOptions,
WorkspacePermissionMode,
} from '../../../core/public';
import { WorkspacePermissionMode } from '../common/constants';
import { SavedObjectPermissions, WorkspaceAttributeWithPermission } from '../../../core/types';
import { DataSourceAssociation } from './components/data_source_association/data_source_association';

Expand All @@ -25,16 +26,6 @@ const join = (...uriComponents: Array<string | undefined>) =>
.map(encodeURIComponent)
.join('/');

interface WorkspaceFindOptions {
page?: number;
perPage?: number;
search?: string;
searchFields?: string[];
sortField?: string;
sortOrder?: string;
permissionModes?: WorkspacePermissionMode[];
}

/**
* Workspaces is OpenSearchDashboards's visualize mechanism allowing admins to
* organize related features
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ export const config: PluginConfigDescriptor = {
schema: configSchema,
};

export { WorkspaceFindOptions, WorkspacePluginSetup, WorkspacePluginStart } from './types';
export { WorkspacePluginSetup, WorkspacePluginStart } from './types';
10 changes: 8 additions & 2 deletions src/plugins/workspace/server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@
*/

import { schema } from '@osd/config-schema';
import { IRouter, Logger, PrincipalType, ACL, DEFAULT_NAV_GROUPS } from '../../../../core/server';
import { getUseCaseFeatureConfig } from '../../common/utils';
import {
IRouter,
Logger,
PrincipalType,
ACL,
DEFAULT_NAV_GROUPS,
WorkspacePermissionMode,
} from '../../../../core/server';
import { getUseCaseFeatureConfig } from '../../common/utils';
import {
MAX_WORKSPACE_NAME_LENGTH,
MAX_WORKSPACE_DESCRIPTION_LENGTH,
} from '../../common/constants';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,10 @@ import {
SavedObjectsClientContract,
SavedObjectsDeleteByWorkspaceOptions,
SavedObjectsFindResult,
WorkspacePermissionMode,
} from '../../../../core/server';
import { SavedObjectsPermissionControlContract } from '../permission_control/client';
import {
WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID,
WorkspacePermissionMode,
} from '../../common/constants';
import { WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID } from '../../common/constants';
import { validateIsWorkspaceDataSourceAndConnectionObjectType } from '../../common/utils';

// Can't throw unauthorized for now, the page will be refreshed if unauthorized
Expand Down
13 changes: 1 addition & 12 deletions src/plugins/workspace/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,20 @@
*/

import {
Logger,
OpenSearchDashboardsRequest,
SavedObjectsFindResponse,
CoreSetup,
WorkspaceAttribute,
SavedObjectsServiceStart,
Permissions,
UiSettingsServiceStart,
WorkspaceFindOptions,
} from '../../../core/server';
import { PermissionModeId } from '../../../core/server';
export interface WorkspaceAttributeWithPermission extends WorkspaceAttribute {
permissions?: Permissions;
permissionMode?: PermissionModeId;
}
import { WorkspacePermissionMode } from '../common/constants';

export interface WorkspaceFindOptions {
page?: number;
perPage?: number;
search?: string;
searchFields?: string[];
sortField?: string;
sortOrder?: string;
permissionModes?: WorkspacePermissionMode[];
}

export interface IRequestDetail {
request: OpenSearchDashboardsRequest;
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/workspace/server/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import {
SavedObjectsClientContract,
IUiSettingsClient,
Principals,
WorkspacePermissionMode,
} from '../../../core/server';
import { updateWorkspaceState } from '../../../core/server/utils';
import { DEFAULT_DATA_SOURCE_UI_SETTINGS_ID } from '../../data_source_management/common';
import {
CURRENT_USER_PLACEHOLDER,
WorkspacePermissionMode,
WORKSPACE_DATA_SOURCE_AND_CONNECTION_OBJECT_TYPES,
OSD_ADMIN_WILDCARD_MATCH_ALL,
} from '../common/constants';
Expand Down
Loading

0 comments on commit c836e60

Please sign in to comment.