diff --git a/app/views/profiles/preferences/show.html.haml b/app/views/profiles/preferences/show.html.haml
index a573b46c7448c222fc9115263d066146e9805529..fb70a53809e011a37e11e48e9475f14429f82f9e 100644
--- a/app/views/profiles/preferences/show.html.haml
+++ b/app/views/profiles/preferences/show.html.haml
@@ -13,6 +13,7 @@
= stylesheet_link_tag "themes/#{theme.css_filename}" if theme.css_filename
= gitlab_ui_form_for @user, url: profile_preferences_path, remote: true, method: :put, html: { id: "profile-preferences-form" } do |f|
+ = render_if_exists 'profiles/preferences/code_suggestions_settings_self_assignment'
.settings-section.js-preferences-form.js-search-settings-section.application-theme#navigation-theme
.settings-sticky-header
.settings-sticky-header-inner
diff --git a/ee/app/helpers/ee/preferences_helper.rb b/ee/app/helpers/ee/preferences_helper.rb
index 97e86e21efb650351a16fde9471570589bcb2b0a..1746d6342b50acba356b2bca9122210857cc6b8a 100644
--- a/ee/app/helpers/ee/preferences_helper.rb
+++ b/ee/app/helpers/ee/preferences_helper.rb
@@ -24,6 +24,10 @@ def group_overview_content_preference?
group_view_choices.size > 1
end
+ def should_show_code_suggestions_preferences?(user)
+ ::Feature.enabled?(:enable_hamilton_in_user_preferences, user)
+ end
+
private
def group_view_security_dashboard_enabled?
diff --git a/ee/app/views/profiles/preferences/_code_suggestions_settings_self_assignment.html.haml b/ee/app/views/profiles/preferences/_code_suggestions_settings_self_assignment.html.haml
new file mode 100644
index 0000000000000000000000000000000000000000..6933edaf08610d3bace79e04b2fba84b4b55b909
--- /dev/null
+++ b/ee/app/views/profiles/preferences/_code_suggestions_settings_self_assignment.html.haml
@@ -0,0 +1,15 @@
+- return unless should_show_code_suggestions_preferences?(@user)
+
+- link_start = ''.html_safe % { url: help_page_path('user/project/repository/code_suggestions.md') }
+- link_end = ''.html_safe
+- br_tag = '
'.html_safe
+
+.settings-section.js-preferences-form.js-search-settings-section#code-suggestions
+ .settings-sticky-header
+ .settings-sticky-header-inner
+ %h4.gl-my-0
+ = s_('Preferences|Code Suggestions')
+ %p.gl-text-secondary
+ = s_('Preferences|Enable %{link_start}Code Suggestions%{link_end} for the following groups.%{br_tag}Only groups that have purchased the Code Suggestion add-on and have available seats are listed here.%{br_tag} If you were expecting to see a group and it is missing from the list, please contact the group owner.').html_safe % { link_start: link_start, link_end: link_end, br_tag: br_tag }
+ .form-group
+ #js-profile-preferences-code-suggestions
diff --git a/ee/config/feature_flags/development/enable_hamilton_in_user_preferences.yml b/ee/config/feature_flags/development/enable_hamilton_in_user_preferences.yml
new file mode 100644
index 0000000000000000000000000000000000000000..5443ab520b5cfe829e9976ce85511326af8a356a
--- /dev/null
+++ b/ee/config/feature_flags/development/enable_hamilton_in_user_preferences.yml
@@ -0,0 +1,8 @@
+---
+name: enable_hamilton_in_user_preferences
+introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/127881
+rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/419821
+milestone: '16.3'
+type: development
+group: group::purchase
+default_enabled: false
diff --git a/ee/spec/helpers/preferences_helper_spec.rb b/ee/spec/helpers/preferences_helper_spec.rb
index 7943db797fa674661b7eb1b0a613e2370ff54655..d51db4a2a56646ee13232564d9251da19f7f46eb 100644
--- a/ee/spec/helpers/preferences_helper_spec.rb
+++ b/ee/spec/helpers/preferences_helper_spec.rb
@@ -62,4 +62,20 @@
it { is_expected.to eq(false) }
end
end
+
+ describe '#should_show_code_suggestions_preferences?' do
+ subject { helper.should_show_code_suggestions_preferences?(user) }
+
+ let(:user) { create_default(:user) }
+
+ context 'when the feature flag is disabled' do
+ before do
+ stub_feature_flags(enable_hamilton_in_user_preferences: false)
+ end
+
+ it { is_expected.to eq(false) }
+ end
+
+ it { is_expected.to eq(true) }
+ end
end
diff --git a/ee/spec/views/profiles/preferences/show.html.haml_spec.rb b/ee/spec/views/profiles/preferences/show.html.haml_spec.rb
index 5464db26b01ddf33e56bed80827272651ca7d76f..229ae638fec5736ea0c582336ed7a8ffa42c63de 100644
--- a/ee/spec/views/profiles/preferences/show.html.haml_spec.rb
+++ b/ee/spec/views/profiles/preferences/show.html.haml_spec.rb
@@ -6,6 +6,7 @@
before do
assign(:user, user)
allow(controller).to receive(:current_user).and_return(user)
+ stub_feature_flags(enable_hamilton_in_user_preferences: false)
end
let(:user) { create_default(:user) }
@@ -59,4 +60,30 @@
end
end
end
+
+ context 'Code Suggestions self-assignment', :saas, feature_category: :code_suggestions do
+ context 'when the feature is available' do
+ before do
+ stub_feature_flags(enable_hamilton_in_user_preferences: user)
+ end
+
+ it 'renders the code suggestions preference' do
+ render
+
+ expect(rendered).to render_template('profiles/preferences/_code_suggestions_settings_self_assignment')
+ field_text = s_('Preferences|Code Suggestions')
+ expect(rendered).to have_content(field_text)
+ end
+ end
+
+ context 'when the feature is not available' do
+ it 'does not render the code suggestions preference' do
+ render
+
+ expect(rendered).to render_template('profiles/preferences/_code_suggestions_settings_self_assignment')
+ field_text = s_('Preferences|Code Suggestions')
+ expect(rendered).not_to have_content(field_text)
+ end
+ end
+ end
end
diff --git a/locale/gitlab.pot b/locale/gitlab.pot
index 0615ec61cf4d59ff9697869a59a2b0fcd5755d7e..0036b85a98afadfa90b352d203ba168d9636c964 100644
--- a/locale/gitlab.pot
+++ b/locale/gitlab.pot
@@ -34951,6 +34951,9 @@ msgstr ""
msgid "Preferences|Choose what content you want to see on a project’s overview page."
msgstr ""
+msgid "Preferences|Code Suggestions"
+msgstr ""
+
msgid "Preferences|Color for added lines"
msgstr ""
@@ -34987,6 +34990,9 @@ msgstr ""
msgid "Preferences|Diff colors"
msgstr ""
+msgid "Preferences|Enable %{link_start}Code Suggestions%{link_end} for the following groups.%{br_tag}Only groups that have purchased the Code Suggestion add-on and have available seats are listed here.%{br_tag} If you were expecting to see a group and it is missing from the list, please contact the group owner."
+msgstr ""
+
msgid "Preferences|Enable Gitpod integration"
msgstr ""