From d2dd7686fefb997f8040295ef7320e14f7373875 Mon Sep 17 00:00:00 2001 From: Ievgen Sorokopud Date: Fri, 18 Oct 2024 13:35:04 +0200 Subject: [PATCH] Hide assistant's knowledge base UI when `assistantKnowledgeBaseByDefault` feature flag is disabled (#196762) ## Summary This is the followup to https://github.com/elastic/kibana/pull/195733 where we implemented the RBAC to allow managing Global Knowledge Base docs. With those changes we introduced a bug where we do not hide the RBAC configuration setting when `assistantKnowledgeBaseByDefault` feature flag is disabled. It means that in Serverless users will see this setting but it will do nothing for them. ### Screenshots of the fixed behaviour * `assistantKnowledgeBaseByDefault = true` ![Capture-2024-10-17-204859](https://github.com/user-attachments/assets/ca4489b1-8ad9-4e57-824f-455ddb74da6c) * `assistantKnowledgeBaseByDefault = false` ![Capture-2024-10-17-204752](https://github.com/user-attachments/assets/fbd2511f-4e09-4ef9-8403-6578366728e4) (cherry picked from commit f6e8065dd75116ddf596b77f75a8468804008323) --- .../features/src/assistant/index.ts | 8 +++-- .../src/assistant/kibana_sub_features.ts | 29 +++++++++++++++---- .../product_features_service.ts | 2 +- x-pack/test/api_integration/config.ts | 3 ++ 4 files changed, 33 insertions(+), 9 deletions(-) diff --git a/x-pack/packages/security-solution/features/src/assistant/index.ts b/x-pack/packages/security-solution/features/src/assistant/index.ts index eaca4b4913ee2..ea0658d795455 100644 --- a/x-pack/packages/security-solution/features/src/assistant/index.ts +++ b/x-pack/packages/security-solution/features/src/assistant/index.ts @@ -9,11 +9,13 @@ import type { ProductFeatureParams } from '../types'; import { getAssistantBaseKibanaFeature } from './kibana_features'; import { getAssistantBaseKibanaSubFeatureIds, - assistantSubFeaturesMap, + getAssistantSubFeaturesMap, } from './kibana_sub_features'; -export const getAssistantFeature = (): ProductFeatureParams => ({ +export const getAssistantFeature = ( + experimentalFeatures: Record +): ProductFeatureParams => ({ baseKibanaFeature: getAssistantBaseKibanaFeature(), baseKibanaSubFeatureIds: getAssistantBaseKibanaSubFeatureIds(), - subFeaturesMap: assistantSubFeaturesMap, + subFeaturesMap: getAssistantSubFeaturesMap(experimentalFeatures), }); diff --git a/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts b/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts index d116aa36d21f0..dbf9505193ecf 100644 --- a/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts +++ b/x-pack/packages/security-solution/features/src/assistant/kibana_sub_features.ts @@ -102,9 +102,28 @@ export const getAssistantBaseKibanaSubFeatureIds = (): AssistantSubFeatureId[] = * Defines all the Security Assistant subFeatures available. * The order of the subFeatures is the order they will be displayed */ -export const assistantSubFeaturesMap = Object.freeze( - new Map([ +export const getAssistantSubFeaturesMap = ( + experimentalFeatures: Record +): Map => { + const assistantSubFeaturesList: Array<[AssistantSubFeatureId, SubFeatureConfig]> = [ [AssistantSubFeatureId.updateAnonymization, updateAnonymizationSubFeature], - [AssistantSubFeatureId.manageGlobalKnowledgeBase, manageGlobalKnowledgeBaseSubFeature], - ]) -); + ]; + + // Use the following code to add feature based on feature flag + // if (experimentalFeatures.featureFlagName) { + // assistantSubFeaturesList.push([AssistantSubFeatureId.featureId, featureSubFeature]); + // } + + if (experimentalFeatures.assistantKnowledgeBaseByDefault) { + assistantSubFeaturesList.push([ + AssistantSubFeatureId.manageGlobalKnowledgeBase, + manageGlobalKnowledgeBaseSubFeature, + ]); + } + + const assistantSubFeaturesMap = new Map( + assistantSubFeaturesList + ); + + return Object.freeze(assistantSubFeaturesMap); +}; diff --git a/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts b/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts index e30c067a0d4a4..29ef513b40bb3 100644 --- a/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts +++ b/x-pack/plugins/security_solution/server/lib/product_features_service/product_features_service.ts @@ -62,7 +62,7 @@ export class ProductFeaturesService { casesFeature.baseKibanaSubFeatureIds ); - const assistantFeature = getAssistantFeature(); + const assistantFeature = getAssistantFeature(this.experimentalFeatures); this.securityAssistantProductFeatures = new ProductFeatures( this.logger, assistantFeature.subFeaturesMap, diff --git a/x-pack/test/api_integration/config.ts b/x-pack/test/api_integration/config.ts index e43c76d42adfa..9cb5a134681a9 100644 --- a/x-pack/test/api_integration/config.ts +++ b/x-pack/test/api_integration/config.ts @@ -30,6 +30,9 @@ export async function getApiIntegrationConfig({ readConfigFile }: FtrConfigProvi '--xpack.ruleRegistry.write.enabled=true', '--xpack.ruleRegistry.write.enabled=true', '--xpack.ruleRegistry.write.cache.enabled=false', + `--xpack.securitySolution.enableExperimental=${JSON.stringify([ + 'assistantKnowledgeBaseByDefault', + ])}`, '--monitoring_collection.opentelemetry.metrics.prometheus.enabled=true', ], },