Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SecuritySolution] Register AI Assistant management settings according to productFeatureKeys #213105

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
import { Subject, combineLatestWith } from 'rxjs';
import { Subject, withLatestFrom, combineLatestWith } from 'rxjs';
import type * as H from 'history';
import type {
AppMountParameters,
Expand Down Expand Up @@ -61,6 +61,7 @@ import { PluginContract } from './plugin_contract';
import { PluginServices } from './plugin_services';
import { getExternalReferenceAttachmentEndpointRegular } from './cases/attachments/external_reference';
import { hasAccessToSecuritySolution } from './helpers_access';
import { ProductFeatureAssistantKey } from '../../../packages/features/src/product_features_keys';

export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, StartPlugins> {
private config: SecuritySolutionUiConfigType;
Expand Down Expand Up @@ -99,6 +100,7 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
this.services.setup(core, plugins);

const { home, usageCollection, management, cases } = plugins;
const { productFeatureKeys$ } = this.contract;

// Lazily instantiate subPlugins and initialize services
const mountDependencies = async (params?: AppMountParameters) => {
Expand Down Expand Up @@ -183,23 +185,32 @@ export class Plugin implements IPlugin<PluginSetup, PluginStart, SetupPlugins, S
category: 'admin',
});

management?.sections.section.kibana.registerApp({
id: 'securityAiAssistantManagement',
title: ASSISTANT_MANAGEMENT_TITLE,
hideFromSidebar: true,
order: 1,
mount: async (params) => {
const { renderApp, services, store } = await mountDependencies();
const { ManagementSettings } = await this.lazyAssistantSettingsManagement();

return renderApp({
...params,
services,
store,
usageCollection,
children: <ManagementSettings />,
productFeatureKeys$.pipe(withLatestFrom(plugins.licensing.license$)).subscribe(([productFeatureKeys, license]) => {

const isInProductFeatureKeys = productFeatureKeys?.has(ProductFeatureAssistantKey.assistant);
const hasRegistered = management?.sections.section.kibana.getApp('securityAiAssistantManagement')

if (isInProductFeatureKeys && license?.hasAtLeast('enterprise') && !hasRegistered) {
management?.sections.section.kibana.registerApp({
id: 'securityAiAssistantManagement',
title: ASSISTANT_MANAGEMENT_TITLE,
hideFromSidebar: true,
order: 1,
mount: async (params) => {
const { renderApp, services, store } = await mountDependencies();
const { ManagementSettings } = await this.lazyAssistantSettingsManagement();

return renderApp({
...params,
services,
store,
usageCollection,
children: <ManagementSettings />,
});
},
});
},
}
});

cases?.attachmentFramework.registerExternalReference(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { BehaviorSubject } from 'rxjs';
import { UpsellingService } from '@kbn/security-solution-upselling/service';
import type { CoreStart } from '@kbn/core/public';
Expand All @@ -14,24 +13,31 @@ import { navLinks$, updateNavLinks } from './common/links/nav_links';
import { breadcrumbsNav$ } from './common/breadcrumbs';
import { ContractComponentsService } from './contract_components';
import { OnboardingService } from './onboarding/service';
import { ProductFeatureKeyType } from '../../../packages/features/src/types';

export class PluginContract {
public componentsService: ContractComponentsService;
public upsellingService: UpsellingService;
public onboardingService: OnboardingService;
public isSolutionNavigationEnabled$: BehaviorSubject<boolean>;
public productFeatureKeys$: BehaviorSubject<Set<ProductFeatureKeyType> | null>;

constructor(private readonly experimentalFeatures: ExperimentalFeatures) {
this.onboardingService = new OnboardingService();
this.componentsService = new ContractComponentsService();
this.upsellingService = new UpsellingService();
this.isSolutionNavigationEnabled$ = new BehaviorSubject<boolean>(false); // defaults to classic navigation
this.productFeatureKeys$ = new BehaviorSubject<Set<ProductFeatureKeyType> | null>(null);
}

public getSetupContract(): PluginSetup {

return {
resolver: lazyResolver,
experimentalFeatures: { ...this.experimentalFeatures },
setProductFeatureKeys: (productFeatureKeys: Set<ProductFeatureKeyType>) => {
this.productFeatureKeys$.next(productFeatureKeys);
},
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import type { GuidedOnboardingPluginStart } from '@kbn/guided-onboarding-plugin/
import type { DataViewsServicePublic } from '@kbn/data-views-plugin/public';
import type { ContentManagementPublicStart } from '@kbn/content-management-plugin/public';
import type { ExpressionsStart } from '@kbn/expressions-plugin/public';
import type { ProductFeatureKeyType } from '@kbn/security-solution-features/keys';

import type { DiscoverStart } from '@kbn/discover-plugin/public';
import type { ManagementSetup } from '@kbn/management-plugin/public';
Expand Down Expand Up @@ -213,6 +214,7 @@ export type StartRenderServices = Pick<
export interface PluginSetup {
resolver: () => Promise<ResolverPluginSetup>;
experimentalFeatures: ExperimentalFeatures;
setProductFeatureKeys: (productFeatureKeys: Set<ProductFeatureKeyType>) => void;
}

export interface PluginStart {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
SecuritySolutionEssPluginStartDeps,
} from './types';
import { setOnboardingSettings } from './onboarding';
import { DEFAULT_PRODUCT_FEATURES } from '../server/constants';

export class SecuritySolutionEssPlugin
implements
Expand All @@ -30,6 +31,10 @@ export class SecuritySolutionEssPlugin
_core: CoreSetup,
_setupDeps: SecuritySolutionEssPluginSetupDeps
): SecuritySolutionEssPluginSetup {
const { securitySolution } = _setupDeps;

securitySolution.setProductFeatureKeys(new Set(DEFAULT_PRODUCT_FEATURES));

return {};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
} from '../common/experimental_features';
import { setOnboardingSettings } from './onboarding';
import { getAdditionalChargesMessage } from './components/additional_charges_message';
import { getProductProductFeatures } from '../common/pli/pli_features';

export class SecuritySolutionServerlessPlugin
implements
Expand All @@ -47,12 +48,14 @@ export class SecuritySolutionServerlessPlugin
setupDeps: SecuritySolutionServerlessPluginSetupDeps
): SecuritySolutionServerlessPluginSetup {
const { securitySolution } = setupDeps;
const { productTypes } = this.config;

this.experimentalFeatures = parseExperimentalConfigValue(
this.config.enableExperimental,
securitySolution.experimentalFeatures
).features;

securitySolution.setProductFeatureKeys(new Set(getProductProductFeatures(productTypes)));
return {};
}

Expand Down