From 6de58fb7f66d16547b02c58309a2bc1e850f0781 Mon Sep 17 00:00:00 2001
From: Julie Huang <julhuang@gitlab.com>
Date: Fri, 7 Mar 2025 15:20:25 +1100
Subject: [PATCH] Pass ai_duo_chat_sub_features_settings as prop to the
 frontend

---
 .../pages/admin/ai/duo_self_hosted/index.js        | 11 ++++++++---
 .../helpers/admin/ai/self_hosted_models_helper.rb  |  4 ++++
 .../views/admin/ai/duo_self_hosted/index.html.haml |  2 +-
 .../admin/ai/self_hosted_models_helper_spec.rb     | 14 ++++++++++++++
 4 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/ee/app/assets/javascripts/pages/admin/ai/duo_self_hosted/index.js b/ee/app/assets/javascripts/pages/admin/ai/duo_self_hosted/index.js
index 164a03571256b..452787dec7ece 100644
--- a/ee/app/assets/javascripts/pages/admin/ai/duo_self_hosted/index.js
+++ b/ee/app/assets/javascripts/pages/admin/ai/duo_self_hosted/index.js
@@ -16,9 +16,13 @@ function mountSelfHostedModelsApp() {
     return null;
   }
 
-  const { basePath, modelOptions, betaModelsEnabled, duoConfigurationSettingsPath } = JSON.parse(
-    el.dataset.viewModel,
-  );
+  const {
+    basePath,
+    modelOptions,
+    betaModelsEnabled,
+    duoChatSubFeaturesEnabled,
+    duoConfigurationSettingsPath,
+  } = JSON.parse(el.dataset.viewModel);
 
   const router = createRouter(basePath);
 
@@ -31,6 +35,7 @@ function mountSelfHostedModelsApp() {
       basePath,
       modelOptions,
       betaModelsEnabled,
+      duoChatSubFeaturesEnabled,
       duoConfigurationSettingsPath,
     },
     render(createElement) {
diff --git a/ee/app/helpers/admin/ai/self_hosted_models_helper.rb b/ee/app/helpers/admin/ai/self_hosted_models_helper.rb
index bc6e2ea8dc745..f6187eeffe9da 100644
--- a/ee/app/helpers/admin/ai/self_hosted_models_helper.rb
+++ b/ee/app/helpers/admin/ai/self_hosted_models_helper.rb
@@ -35,6 +35,10 @@ def model_choices_as_options
       def beta_models_enabled?
         ::Ai::TestingTermsAcceptance.has_accepted?
       end
+
+      def duo_chat_sub_features_enabled?
+        Feature.enabled?(:ai_duo_chat_sub_features_settings) # rubocop:disable Gitlab/FeatureFlagWithoutActor -- global feature flag
+      end
     end
   end
 end
diff --git a/ee/app/views/admin/ai/duo_self_hosted/index.html.haml b/ee/app/views/admin/ai/duo_self_hosted/index.html.haml
index 79ada4f8ed1fd..a39fa9944abfd 100644
--- a/ee/app/views/admin/ai/duo_self_hosted/index.html.haml
+++ b/ee/app/views/admin/ai/duo_self_hosted/index.html.haml
@@ -1,2 +1,2 @@
 - page_title s_("AdminSelfHostedModels|GitLab Duo Self-Hosted")
-#js-duo-self-hosted{ data: { view_model: { basePath: admin_ai_duo_self_hosted_path, modelOptions: model_choices_as_options, betaModelsEnabled: beta_models_enabled?, duoConfigurationSettingsPath: admin_gitlab_duo_configuration_index_url }.to_json } }
+#js-duo-self-hosted{ data: { view_model: { basePath: admin_ai_duo_self_hosted_path, modelOptions: model_choices_as_options, betaModelsEnabled: beta_models_enabled?, duoChatSubFeaturesEnabled: duo_chat_sub_features_enabled?, duoConfigurationSettingsPath: admin_gitlab_duo_configuration_index_url }.to_json } }
diff --git a/ee/spec/helpers/admin/ai/self_hosted_models_helper_spec.rb b/ee/spec/helpers/admin/ai/self_hosted_models_helper_spec.rb
index 38f35cb4fd197..10c8d3ac73290 100644
--- a/ee/spec/helpers/admin/ai/self_hosted_models_helper_spec.rb
+++ b/ee/spec/helpers/admin/ai/self_hosted_models_helper_spec.rb
@@ -60,4 +60,18 @@
       expect(helper.beta_models_enabled?).to be(false)
     end
   end
+
+  describe '#duo_chat_sub_features_enabled?' do
+    it 'returns true if ai_duo_chat_sub_features_settings is enabled' do
+      stub_feature_flags(ai_duo_chat_sub_features_settings: true)
+
+      expect(helper.duo_chat_sub_features_enabled?).to be(true)
+    end
+
+    it 'returns false if ai_duo_chat_sub_features_settings is disabled' do
+      stub_feature_flags(ai_duo_chat_sub_features_settings: false)
+
+      expect(helper.duo_chat_sub_features_enabled?).to be(false)
+    end
+  end
 end
-- 
GitLab