Skip to content

Commit

Permalink
feat: merge code
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 Aug 11, 2023
2 parents a341f08 + 166c06d commit 31d62c4
Show file tree
Hide file tree
Showing 51 changed files with 433 additions and 489 deletions.
6 changes: 3 additions & 3 deletions src/core/public/application/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { IUiSettingsClient } from '../ui_settings';
import { SavedObjectsStart } from '../saved_objects';
import { AppCategory } from '../../types';
import { ScopedHistory } from './scoped_history';
import { WorkspacesStart } from '../workspace';
import { WorkspaceStart } from '../workspace';

/**
* Accessibility status of an application.
Expand Down Expand Up @@ -345,8 +345,8 @@ export interface AppMountContext {
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
};
/** {@link WorkspacesService} */
workspaces: WorkspacesStart;
/** {@link WorkspaceService} */
workspaces: WorkspaceStart;
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import { ContextService } from './context';
import { IntegrationsService } from './integrations';
import { CoreApp } from './core_app';
import type { InternalApplicationSetup, InternalApplicationStart } from './application/types';
import { WorkspacesService } from './workspace';
import { WorkspaceService } from './workspace';

interface Params {
rootDomElement: HTMLElement;
Expand Down Expand Up @@ -111,7 +111,7 @@ export class CoreSystem {

private readonly rootDomElement: HTMLElement;
private readonly coreContext: CoreContext;
private readonly workspaces: WorkspacesService;
private readonly workspaces: WorkspaceService;
private fatalErrorsSetup: FatalErrorsSetup | null = null;

constructor(params: Params) {
Expand Down Expand Up @@ -140,7 +140,7 @@ export class CoreSystem {
this.rendering = new RenderingService();
this.application = new ApplicationService();
this.integrations = new IntegrationsService();
this.workspaces = new WorkspacesService();
this.workspaces = new WorkspaceService();

this.coreContext = { coreId: Symbol('core'), env: injectedMetadata.env };

Expand All @@ -163,7 +163,7 @@ export class CoreSystem {
const http = this.http.setup({ injectedMetadata, fatalErrors: this.fatalErrorsSetup });
const uiSettings = this.uiSettings.setup({ http, injectedMetadata });
const notifications = this.notifications.setup({ uiSettings });
const workspaces = await this.workspaces.setup({ http, uiSettings });
const workspaces = this.workspaces.setup();

const pluginDependencies = this.plugins.getOpaqueIds();
const context = this.context.setup({
Expand Down Expand Up @@ -225,7 +225,7 @@ export class CoreSystem {
targetDomElement: notificationsTargetDomElement,
});
const application = await this.application.start({ http, overlays });
const workspaces = await this.workspaces.start();
const workspaces = this.workspaces.start();
const chrome = await this.chrome.start({
application,
docLinks,
Expand Down
22 changes: 8 additions & 14 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ import {
HandlerParameters,
} from './context';
import { Branding } from '../types';
import { WorkspacesStart, WorkspacesSetup } from './workspace';
import { WorkspaceStart, WorkspaceSetup } from './workspace';

export { PackageInfo, EnvironmentMode } from '../server/types';
/** @interal */
Expand Down Expand Up @@ -240,8 +240,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
};
/** {@link StartServicesAccessor} */
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
/** {@link WorkspacesSetup} */
workspaces: WorkspacesSetup;
/** {@link WorkspaceSetup} */
workspaces: WorkspaceSetup;
}

/**
Expand Down Expand Up @@ -296,8 +296,8 @@ export interface CoreStart {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => Branding;
};
/** {@link WorkspacesStart} */
workspaces: WorkspacesStart;
/** {@link WorkspaceStart} */
workspaces: WorkspaceStart;
}

export {
Expand Down Expand Up @@ -348,14 +348,8 @@ export {

export { __osdBootstrap__ } from './osd_bootstrap';

export {
WorkspacesClientContract,
WorkspacesClient,
WorkspacesStart,
WorkspacesService,
WorkspaceAttribute,
WorkspaceFindOptions,
WorkspacePermissionMode,
} from './workspace';
export { WorkspaceStart, WorkspaceService, WorkspaceAttribute } from './workspace';

export { WorkspacePermissionMode, PUBLIC_WORKSPACE, MANAGEMENT_WORKSPACE } from '../utils';

export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './utils';
6 changes: 1 addition & 5 deletions src/core/public/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,4 @@ export { shareWeakReplay } from './share_weak_replay';
export { Sha256 } from './crypto';
export { MountWrapper, mountReactNode } from './mount';
export { getWorkspaceIdFromUrl, WORKSPACE_TYPE } from './workspace';
export {
WORKSPACE_PATH_PREFIX,
PUBLIC_WORKSPACE,
WORKSPACE_FEATURE_FLAG_KEY_IN_UI_SETTINGS,
} from '../../utils';
export { WORKSPACE_PATH_PREFIX, PUBLIC_WORKSPACE } from '../../utils';
10 changes: 0 additions & 10 deletions src/core/public/workspace/consts.ts

This file was deleted.

10 changes: 2 additions & 8 deletions src/core/public/workspace/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
export { WorkspacesClientContract, WorkspacesClient } from './workspaces_client';
export { WorkspacesStart, WorkspacesService, WorkspacesSetup } from './workspaces_service';
export type {
WorkspaceAttribute,
WorkspaceFindOptions,
WorkspaceRoutePermissionItem,
} from '../../server/types';
export { PermissionMode as WorkspacePermissionMode } from '../../utils/constants';
export { WorkspaceStart, WorkspaceService, WorkspaceSetup } from './workspaces_service';
export type { WorkspaceAttribute } from './workspaces_service';
21 changes: 3 additions & 18 deletions src/core/public/workspace/workspaces_service.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,9 @@ const workspaceList$ = new BehaviorSubject<WorkspaceAttribute[]>([]);
const currentWorkspace$ = new BehaviorSubject<WorkspaceAttribute | null>(null);

const createWorkspacesSetupContractMock = () => ({
client: {
currentWorkspaceId$,
workspaceList$,
currentWorkspace$,
init: jest.fn(),
stop: jest.fn(),
enterWorkspace: jest.fn(),
exitWorkspace: jest.fn(),
create: jest.fn(),
delete: jest.fn(),
list: jest.fn(),
getCurrentWorkspace: jest.fn(),
getCurrentWorkspaceId: jest.fn(),
get: jest.fn(),
update: jest.fn(),
},
formatUrlWithWorkspaceId: jest.fn(),
setFormatUrlWithWorkspaceId: jest.fn(),
currentWorkspaceId$,
workspaceList$,
currentWorkspace$,
});

const createWorkspacesStartContractMock = createWorkspacesSetupContractMock;
Expand Down
68 changes: 38 additions & 30 deletions src/core/public/workspace/workspaces_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,58 @@
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { CoreService } from 'src/core/types';
import { WorkspacesClient, WorkspacesClientContract } from './workspaces_client';
import type { WorkspaceAttribute } from '../../server/types';
import { HttpSetup } from '../http';
import { IUiSettingsClient } from '../ui_settings';
import { BehaviorSubject } from 'rxjs';
import { CoreService } from '../../types';

/**
* @public
*/
export interface WorkspacesStart {
client: WorkspacesClientContract;
formatUrlWithWorkspaceId: (url: string, id: WorkspaceAttribute['id']) => string;
setFormatUrlWithWorkspaceId: (formatFn: WorkspacesStart['formatUrlWithWorkspaceId']) => void;
export interface WorkspaceStart {
currentWorkspaceId$: BehaviorSubject<string>;
currentWorkspace$: BehaviorSubject<WorkspaceAttribute | null>;
workspaceList$: BehaviorSubject<WorkspaceAttribute[]>;
hasFetchedWorkspaceList$: BehaviorSubject<boolean>;
}

export type WorkspacesSetup = WorkspacesStart;
export type WorkspaceSetup = WorkspaceStart;

export class WorkspacesService implements CoreService<WorkspacesSetup, WorkspacesStart> {
private client?: WorkspacesClientContract;
private formatUrlWithWorkspaceId(url: string, id: string) {
return url;
}
private setFormatUrlWithWorkspaceId(formatFn: WorkspacesStart['formatUrlWithWorkspaceId']) {
this.formatUrlWithWorkspaceId = formatFn;
}
public async setup({ http }: { http: HttpSetup; uiSettings: IUiSettingsClient }) {
this.client = new WorkspacesClient(http);
export interface WorkspaceAttribute {
id: string;
name: string;
description?: string;
features?: string[];
color?: string;
icon?: string;
defaultVISTheme?: string;
}

export class WorkspaceService implements CoreService<WorkspaceSetup, WorkspaceStart> {
private currentWorkspaceId$ = new BehaviorSubject<string>('');
private workspaceList$ = new BehaviorSubject<WorkspaceAttribute[]>([]);
private currentWorkspace$ = new BehaviorSubject<WorkspaceAttribute | null>(null);
private hasFetchedWorkspaceList$ = new BehaviorSubject<boolean>(false);

public setup(): WorkspaceSetup {
return {
client: this.client,
formatUrlWithWorkspaceId: (url: string, id: string) => this.formatUrlWithWorkspaceId(url, id),
setFormatUrlWithWorkspaceId: (fn: WorkspacesStart['formatUrlWithWorkspaceId']) =>
this.setFormatUrlWithWorkspaceId(fn),
currentWorkspaceId$: this.currentWorkspaceId$,
currentWorkspace$: this.currentWorkspace$,
workspaceList$: this.workspaceList$,
hasFetchedWorkspaceList$: this.hasFetchedWorkspaceList$,
};
}
public async start(): Promise<WorkspacesStart> {

public start(): WorkspaceStart {
return {
client: this.client as WorkspacesClientContract,
formatUrlWithWorkspaceId: this.formatUrlWithWorkspaceId,
setFormatUrlWithWorkspaceId: (fn: WorkspacesStart['formatUrlWithWorkspaceId']) =>
this.setFormatUrlWithWorkspaceId(fn),
currentWorkspaceId$: this.currentWorkspaceId$,
currentWorkspace$: this.currentWorkspace$,
workspaceList$: this.workspaceList$,
hasFetchedWorkspaceList$: this.hasFetchedWorkspaceList$,
};
}

public async stop() {
this.client?.stop();
this.currentWorkspace$.unsubscribe();
this.currentWorkspaceId$.unsubscribe();
this.workspaceList$.unsubscribe();
}
}
13 changes: 10 additions & 3 deletions src/core/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,10 @@ export {
SavedObjectsShareObjects,
SavedObjectsAddToWorkspacesOptions,
SavedObjectsAddToWorkspacesResponse,
WORKSPACE_TYPE,
Permissions,
ACL,
SavedObjectsPermissionControlContract,
} from './saved_objects';

export {
Expand Down Expand Up @@ -349,7 +353,12 @@ export {
} from './metrics';

export { AppCategory } from '../types';
export { DEFAULT_APP_CATEGORIES } from '../utils';
export {
DEFAULT_APP_CATEGORIES,
WorkspacePermissionMode,
PUBLIC_WORKSPACE,
MANAGEMENT_WORKSPACE,
} from '../utils';

export {
SavedObject,
Expand Down Expand Up @@ -511,5 +520,3 @@ export const config = {
appenders: appendersSchema as Type<AppenderConfigType>,
},
};

export { formatWorkspaces, workspacesValidator, WORKSPACE_TYPE } from './workspaces';
File renamed without changes.
4 changes: 4 additions & 0 deletions src/core/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,7 @@ export {

export { savedObjectsConfig, savedObjectsMigrationConfig } from './saved_objects_config';
export { SavedObjectTypeRegistry, ISavedObjectTypeRegistry } from './saved_objects_type_registry';

export { WORKSPACE_TYPE } from './constants';
export { Permissions, ACL } from './permission_control/acl';
export { SavedObjectsPermissionControlContract } from './permission_control/client';
21 changes: 8 additions & 13 deletions src/core/server/saved_objects/permission_control/acl.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { PermissionMode } from '../../../../core/utils/constants';
import { Principals, Permissions, ACL } from './acl';

describe('SavedObjectTypeRegistry', () => {
Expand All @@ -19,13 +18,13 @@ describe('SavedObjectTypeRegistry', () => {
};
acl = new ACL(permissions);
expect(
acl.hasPermission([PermissionMode.Read], {
acl.hasPermission(['read'], {
users: ['user1'],
groups: [],
})
).toEqual(true);
expect(
acl.hasPermission([PermissionMode.Read], {
acl.hasPermission(['read'], {
users: ['user2'],
groups: [],
})
Expand All @@ -35,7 +34,7 @@ describe('SavedObjectTypeRegistry', () => {
it('test add permission', () => {
acl = new ACL();
const result1 = acl
.addPermission([PermissionMode.Read], {
.addPermission(['read'], {
users: ['user1'],
groups: [],
})
Expand All @@ -44,7 +43,7 @@ describe('SavedObjectTypeRegistry', () => {

acl.resetPermissions();
const result2 = acl
.addPermission([PermissionMode.Write, PermissionMode.Management], {
.addPermission(['write', 'management'], {
users: ['user2'],
groups: ['group1', 'group2'],
})
Expand All @@ -64,11 +63,11 @@ describe('SavedObjectTypeRegistry', () => {
};
acl = new ACL(permissions1);
const result1 = acl
.removePermission([PermissionMode.Read], {
.removePermission(['read'], {
users: ['user1'],
groups: [],
})
.removePermission([PermissionMode.Write], {
.removePermission(['write'], {
users: [],
groups: ['group2'],
})
Expand All @@ -88,7 +87,7 @@ describe('SavedObjectTypeRegistry', () => {

acl = new ACL(permissions2);
const result2 = acl
.removePermission([PermissionMode.Read, PermissionMode.Write], {
.removePermission(['read', 'write'], {
users: ['user1'],
groups: ['group1'],
})
Expand Down Expand Up @@ -125,11 +124,7 @@ describe('SavedObjectTypeRegistry', () => {
users: ['user1'],
groups: ['group1'],
};
const result = ACL.genereateGetPermittedSavedObjectsQueryDSL(
[PermissionMode.Read],
principals,
'workspace'
);
const result = ACL.genereateGetPermittedSavedObjectsQueryDSL(['read'], principals, 'workspace');
expect(result).toEqual({
query: {
bool: {
Expand Down
5 changes: 4 additions & 1 deletion src/core/server/saved_objects/permission_control/acl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { PrincipalType } from '../../../utils/constants';
export enum PrincipalType {
Users = 'users',
Groups = 'groups',
}

export interface Principals {
users?: string[];
Expand Down
Loading

0 comments on commit 31d62c4

Please sign in to comment.