mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
* remove MLs use of internal Spaces utilities * move logic to SpacesService for testability * make TS happy * Apply suggestions from code review Co-Authored-By: Brandon Kobel <brandon.kobel@gmail.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
/*
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
*/
|
|
|
|
import { Request } from 'hapi';
|
|
import { SpacesPlugin } from '../../../spaces';
|
|
import { Space } from '../../../spaces/common/model/space';
|
|
|
|
interface GetActiveSpaceResponse {
|
|
valid: boolean;
|
|
space?: Space;
|
|
}
|
|
|
|
export function spacesUtilsProvider(spacesPlugin: SpacesPlugin, request: Request) {
|
|
async function activeSpace(): Promise<GetActiveSpaceResponse> {
|
|
try {
|
|
return {
|
|
valid: true,
|
|
space: await spacesPlugin.getActiveSpace(request),
|
|
};
|
|
} catch (e) {
|
|
return {
|
|
valid: false,
|
|
};
|
|
}
|
|
}
|
|
|
|
async function isMlEnabledInSpace(): Promise<boolean> {
|
|
const { valid, space } = await activeSpace();
|
|
if (valid === true && space !== undefined) {
|
|
return space.disabledFeatures.includes('ml') === false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
return { isMlEnabledInSpace };
|
|
}
|