diff --git a/src/plugins/workspace/public/plugin.ts b/src/plugins/workspace/public/plugin.ts index 5271187abb3f..7bfbac596296 100644 --- a/src/plugins/workspace/public/plugin.ts +++ b/src/plugins/workspace/public/plugin.ts @@ -54,7 +54,7 @@ export class WorkspacePlugin implements Plugin<{}, {}, WorkspacePluginSetupDeps> workspaceClient.init(); const featureFlagResp = await workspaceClient.getFeatureFlag(); if (featureFlagResp.success) { - core.workspaces.workspaceEnabled$.next(featureFlagResp.result); + core.workspaces.workspaceEnabled$.next(featureFlagResp.result.enabled); } else { core.workspaces.workspaceEnabled$.next(false); } diff --git a/src/plugins/workspace/public/workspace_client.ts b/src/plugins/workspace/public/workspace_client.ts index c520db69dbe0..950f7dff8ece 100644 --- a/src/plugins/workspace/public/workspace_client.ts +++ b/src/plugins/workspace/public/workspace_client.ts @@ -329,8 +329,12 @@ export class WorkspaceClient { return result; } - public async getFeatureFlag(): Promise> { - const result = await this.safeFetch(this.getPath(['is_workspace_enabled']), { + public async getFeatureFlag(): Promise< + IResponse<{ + enabled: boolean; + }> + > { + const result = await this.safeFetch(this.getPath(['settings']), { method: 'get', }); diff --git a/src/plugins/workspace/server/plugin.ts b/src/plugins/workspace/server/plugin.ts index 4e3d5d45f243..c389b3df3ed1 100644 --- a/src/plugins/workspace/server/plugin.ts +++ b/src/plugins/workspace/server/plugin.ts @@ -91,6 +91,7 @@ export class WorkspacePlugin implements Plugin<{}, {}> { logger: this.logger, client: this.client as IWorkspaceDBImpl, enabled$: this.enabled$, + config$: this.config$, }); core.savedObjects.setClientFactoryProvider((repositoryFactory) => () => @@ -218,6 +219,5 @@ export class WorkspacePlugin implements Plugin<{}, {}> { public stop() { this.enabled$.unsubscribe(); - clearTimeout(this.loopRequestTimer); } } diff --git a/src/plugins/workspace/server/routes/index.ts b/src/plugins/workspace/server/routes/index.ts index f999768e4f08..e8baf5bdb20d 100644 --- a/src/plugins/workspace/server/routes/index.ts +++ b/src/plugins/workspace/server/routes/index.ts @@ -3,7 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ import { schema } from '@osd/config-schema'; -import { BehaviorSubject } from 'rxjs'; +import { BehaviorSubject, Observable } from 'rxjs'; +import { first } from 'rxjs/operators'; import { ensureRawRequest } from '../../../../core/server'; import { @@ -14,6 +15,7 @@ import { WorkspacePermissionMode, } from '../../../../core/server'; import { IWorkspaceDBImpl, WorkspaceRoutePermissionItem } from '../types'; +import { ConfigSchema } from '../../config'; const WORKSPACES_API_BASE_URL = '/api/workspaces'; @@ -84,11 +86,13 @@ export function registerRoutes({ logger, http, enabled$, + config$, }: { client: IWorkspaceDBImpl; logger: Logger; http: CoreSetup['http']; enabled$: BehaviorSubject; + config$: Observable; }) { const router = http.createRouter(); router.post( @@ -261,14 +265,18 @@ export function registerRoutes({ router.get( { - path: `${WORKSPACES_API_BASE_URL}/is_workspace_enabled`, + path: `${WORKSPACES_API_BASE_URL}/settings`, validate: {}, }, router.handleLegacyErrors(async (context, req, res) => { + const config = await config$.pipe(first()).toPromise(); return res.ok({ body: { success: true, - result: enabled$.getValue(), + result: { + ...config, + enabled: enabled$.getValue(), + }, }, }); })