diff --git a/x-pack/plugins/ml/kibana.json b/x-pack/plugins/ml/kibana.json index e944af6821c0b..3bdf859731438 100644 --- a/x-pack/plugins/ml/kibana.json +++ b/x-pack/plugins/ml/kibana.json @@ -3,7 +3,8 @@ "version": "0.0.1", "kibanaVersion": "kibana", "configPath": ["ml"], - "requiredPlugins": ["cloud", "features", "home", "licensing", "security", "spaces", "usageCollection"], + "requiredPlugins": ["cloud", "features", "home", "licensing", "usageCollection"], + "optionalPlugins": ["security", "spaces"], "server": true, "ui": false } diff --git a/x-pack/plugins/ml/server/plugin.ts b/x-pack/plugins/ml/server/plugin.ts index a3f5733738432..547d3f8ab06cb 100644 --- a/x-pack/plugins/ml/server/plugin.ts +++ b/x-pack/plugins/ml/server/plugin.ts @@ -117,7 +117,7 @@ export class MlServerPlugin { resultsServiceRoutes(routeInit); jobValidationRoutes(routeInit, this.version); systemRoutes(routeInit, { - spacesPlugin: plugins.spaces, + spaces: plugins.spaces, cloud: plugins.cloud, }); initMlServerLog({ log: this.log }); diff --git a/x-pack/plugins/ml/server/routes/annotations.ts b/x-pack/plugins/ml/server/routes/annotations.ts index 16483bf8b887e..c481fb8698855 100644 --- a/x-pack/plugins/ml/server/routes/annotations.ts +++ b/x-pack/plugins/ml/server/routes/annotations.ts @@ -36,7 +36,7 @@ function getAnnotationsFeatureUnavailableErrorMessage() { */ export function annotationRoutes( { router, mlLicense }: RouteInitialization, - securityPlugin: SecurityPluginSetup + securityPlugin?: SecurityPluginSetup ) { /** * @apiGroup Annotations @@ -101,9 +101,12 @@ export function annotationRoutes( } const { indexAnnotation } = annotationServiceProvider(context); - const user = securityPlugin.authc.getCurrentUser(request) || {}; + + const currentUser = + securityPlugin !== undefined ? securityPlugin.authc.getCurrentUser(request) : {}; // @ts-ignore username doesn't exist on {} - const resp = await indexAnnotation(request.body, user.username || ANNOTATION_USER_UNKNOWN); + const username = currentUser?.username ?? ANNOTATION_USER_UNKNOWN; + const resp = await indexAnnotation(request.body, username); return response.ok({ body: resp, diff --git a/x-pack/plugins/ml/server/routes/system.ts b/x-pack/plugins/ml/server/routes/system.ts index a0d7d312c04d4..2a0a760e94f79 100644 --- a/x-pack/plugins/ml/server/routes/system.ts +++ b/x-pack/plugins/ml/server/routes/system.ts @@ -19,7 +19,7 @@ import { RouteInitialization, SystemRouteDeps } from '../types'; */ export function systemRoutes( { router, mlLicense }: RouteInitialization, - { spacesPlugin, cloud }: SystemRouteDeps + { spaces, cloud }: SystemRouteDeps ) { async function getNodeCount(context: RequestHandlerContext) { const filterPath = 'nodes.*.attributes'; @@ -120,8 +120,8 @@ export function systemRoutes( const ignoreSpaces = request.query && request.query.ignoreSpaces === 'true'; // if spaces is disabled force isMlEnabledInSpace to be true const { isMlEnabledInSpace } = - spacesPlugin !== undefined - ? spacesUtilsProvider(spacesPlugin, (request as unknown) as Request) + spaces !== undefined + ? spacesUtilsProvider(spaces, (request as unknown) as Request) : { isMlEnabledInSpace: async () => true }; const { getPrivileges } = privilegesProvider( diff --git a/x-pack/plugins/ml/server/types.ts b/x-pack/plugins/ml/server/types.ts index aeb4c505ec55e..def8a1e5fa649 100644 --- a/x-pack/plugins/ml/server/types.ts +++ b/x-pack/plugins/ml/server/types.ts @@ -25,7 +25,7 @@ export interface LicenseCheckResult { export interface SystemRouteDeps { cloud: CloudSetup; - spacesPlugin: SpacesPluginSetup; + spaces?: SpacesPluginSetup; } export interface PluginsSetup { @@ -33,8 +33,8 @@ export interface PluginsSetup { features: FeaturesPluginSetup; home: HomeServerPluginSetup; licensing: LicensingPluginSetup; - security: SecurityPluginSetup; - spaces: SpacesPluginSetup; + security?: SecurityPluginSetup; + spaces?: SpacesPluginSetup; usageCollection: UsageCollectionSetup; }