From dae5b62c22df98e434caa1d325e30f405ca2cc0c Mon Sep 17 00:00:00 2001
From: rossfuhrman <rfuhrman@gitlab.com>
Date: Mon, 11 Dec 2023 16:22:48 +0000
Subject: [PATCH] Display settings panel for Dedicated

Change to showing the application setting for pre receive secret
detection based on whether or not the instance is Dedicated

EE: true
Changelog: changed
---
 .../admin/application_settings_controller.rb  |  2 +-
 .../security_and_compliance.html.haml         |  2 +-
 .../secret_detection_application_setting.yml  |  8 ---
 .../application_settings_controller_spec.rb   |  8 ++-
 .../security_and_compliance.html.haml_spec.rb | 61 +++++++++++++++++++
 5 files changed, 69 insertions(+), 12 deletions(-)
 delete mode 100644 ee/config/feature_flags/development/secret_detection_application_setting.yml
 create mode 100644 ee/spec/views/admin/application_settings/security_and_compliance.html.haml_spec.rb

diff --git a/ee/app/controllers/ee/admin/application_settings_controller.rb b/ee/app/controllers/ee/admin/application_settings_controller.rb
index 22c6731ffc730..4953133bb1d6a 100644
--- a/ee/app/controllers/ee/admin/application_settings_controller.rb
+++ b/ee/app/controllers/ee/admin/application_settings_controller.rb
@@ -140,7 +140,7 @@ def visible_application_setting_attributes
         end
 
         if License.feature_available?(:pre_receive_secret_detection) &&
-            ::Feature.enabled?(:secret_detection_application_setting)
+            ::Gitlab::CurrentSettings.gitlab_dedicated_instance?
           attrs << :pre_receive_secret_detection_enabled
         end
 
diff --git a/ee/app/views/admin/application_settings/security_and_compliance.html.haml b/ee/app/views/admin/application_settings/security_and_compliance.html.haml
index ad911e0a5fd10..1dd719c2bd7ae 100644
--- a/ee/app/views/admin/application_settings/security_and_compliance.html.haml
+++ b/ee/app/views/admin/application_settings/security_and_compliance.html.haml
@@ -14,7 +14,7 @@
   .settings-content
     = render 'license_compliance'
 
-- if Feature.enabled?(:secret_detection_application_setting) && License.feature_available?(:pre_receive_secret_detection)
+- if ::Gitlab::CurrentSettings.gitlab_dedicated_instance? && License.feature_available?(:pre_receive_secret_detection)
   %section.settings.as-secret-detection.no-animate#js-secret-detection-settings{ class: ('expanded' if expanded_by_default?), data: { testid: 'admin-secret-detection-settings' } }
     .settings-header
       %h4.settings-title.js-settings-toggle.js-settings-toggle-trigger-only
diff --git a/ee/config/feature_flags/development/secret_detection_application_setting.yml b/ee/config/feature_flags/development/secret_detection_application_setting.yml
deleted file mode 100644
index 17b32abee9be5..0000000000000
--- a/ee/config/feature_flags/development/secret_detection_application_setting.yml
+++ /dev/null
@@ -1,8 +0,0 @@
----
-name: secret_detection_application_setting
-introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/135273 
-rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/431584
-milestone: '16.7'
-type: development
-group: group::static analysis
-default_enabled: false
diff --git a/ee/spec/controllers/admin/application_settings_controller_spec.rb b/ee/spec/controllers/admin/application_settings_controller_spec.rb
index cabc7730b309e..a2a351b6fd33b 100644
--- a/ee/spec/controllers/admin/application_settings_controller_spec.rb
+++ b/ee/spec/controllers/admin/application_settings_controller_spec.rb
@@ -270,12 +270,16 @@
       let(:settings) { { pre_receive_secret_detection_enabled: true } }
       let(:feature) { :pre_receive_secret_detection }
 
+      before do
+        stub_application_setting(gitlab_dedicated_instance: true)
+      end
+
       it_behaves_like 'settings for licensed features'
 
-      context 'when secret_detection_application_setting feature flag is disabled' do
+      context 'when instance is not dedicated' do
         before do
           stub_licensed_features(feature => true)
-          stub_feature_flags(secret_detection_application_setting: false)
+          stub_application_setting(gitlab_dedicated_instance: false)
         end
 
         it 'does not update pre_receive_secret_detection_enabled setting' do
diff --git a/ee/spec/views/admin/application_settings/security_and_compliance.html.haml_spec.rb b/ee/spec/views/admin/application_settings/security_and_compliance.html.haml_spec.rb
new file mode 100644
index 0000000000000..f394bbbb2945a
--- /dev/null
+++ b/ee/spec/views/admin/application_settings/security_and_compliance.html.haml_spec.rb
@@ -0,0 +1,61 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe 'admin/application_settings/security_and_compliance.html.haml', feature_category: :software_composition_analysis do
+  using RSpec::Parameterized::TableSyntax
+
+  let_it_be(:user) { build_stubbed(:admin) }
+  let_it_be(:app_settings) { build(:application_setting) }
+
+  subject { rendered }
+
+  before do
+    assign(:application_setting, app_settings)
+    allow(view).to receive(:current_user).and_return(user)
+
+    stub_licensed_features(pre_receive_secret_detection: feature_available)
+  end
+
+  shared_examples 'renders pre receive secret detection setting' do
+    it do
+      render
+
+      expect(rendered).to have_css '#js-secret-detection-settings'
+    end
+  end
+
+  shared_examples 'does not render pre receive secret detection setting' do
+    it do
+      render
+
+      expect(rendered).not_to have_css '#js-secret-detection-settings'
+    end
+  end
+
+  context 'when instance is dedicated' do
+    before do
+      stub_application_setting(gitlab_dedicated_instance: true)
+    end
+
+    describe 'feature available' do
+      let(:feature_available) { true }
+
+      it_behaves_like 'renders pre receive secret detection setting'
+    end
+
+    describe 'feature not available' do
+      let(:feature_available) { false }
+
+      it_behaves_like 'does not render pre receive secret detection setting'
+    end
+  end
+
+  context 'when instance is not dedicated' do
+    let(:feature_available) { true }
+
+    describe 'feature available' do
+      it_behaves_like 'does not render pre receive secret detection setting'
+    end
+  end
+end
-- 
GitLab