diff --git a/app/views/admin/application_settings/_visibility_and_access.html.haml b/app/views/admin/application_settings/_visibility_and_access.html.haml index 8a11688ce237164facd516d65f593405e22e3dfb..38313c997140fff77e96f40ec109867c1fa56f77 100644 --- a/app/views/admin/application_settings/_visibility_and_access.html.haml +++ b/app/views/admin/application_settings/_visibility_and_access.html.haml @@ -53,6 +53,8 @@ = render_if_exists 'admin/application_settings/globally_allowed_ips', form: f + = render_if_exists 'admin/application_settings/display_gitlab_credits_user_data', form: f + -# This is added for Jihu edition in https://jihulab.com/gitlab-cn/gitlab/-/merge_requests/1112 = render_if_exists 'admin/application_settings/disable_download_button', f: f diff --git a/ee/app/helpers/ee/application_settings_helper.rb b/ee/app/helpers/ee/application_settings_helper.rb index ab88d2bd79f8e186240799be173012c49e1089b0..de3c63dbe96bb7d9ea82268b80c605bcef9ab9c0 100644 --- a/ee/app/helpers/ee/application_settings_helper.rb +++ b/ee/app/helpers/ee/application_settings_helper.rb @@ -111,7 +111,8 @@ def visible_attributes :global_search_epics_enabled, :global_search_limited_indexing_enabled, :elastic_migration_worker_enabled, - :enforce_pipl_compliance + :enforce_pipl_compliance, + :display_gitlab_credits_user_data ].tap do |settings| settings.concat(identity_verification_attributes) settings.concat(enable_promotion_management_attributes) diff --git a/ee/app/views/admin/application_settings/_display_gitlab_credits_user_data.html.haml b/ee/app/views/admin/application_settings/_display_gitlab_credits_user_data.html.haml new file mode 100644 index 0000000000000000000000000000000000000000..d1e019f7320fd71c454ce45ecba6eb3b713542bf --- /dev/null +++ b/ee/app/views/admin/application_settings/_display_gitlab_credits_user_data.html.haml @@ -0,0 +1,10 @@ +- return unless Feature.enabled?(:usage_billing_dev, :instance) +- return unless License.feature_available?(:usage_billing) +- return if ::Gitlab::Saas.feature_available?(:gitlab_com_subscriptions) + +- f = local_assigns.fetch(:form) + +.form-group + %h5= s_('AdminSettingsUsageBilling|GitLab Credits dashboard') + = f.gitlab_ui_checkbox_component :display_gitlab_credits_user_data, s_('AdminSettingsUsageBilling|Display user data'), + help_text: s_('AdminSettingsUsageBilling|If selected, individual usernames and their credit usage are visible on the GitLab Credits dashboard. If your organization needs to restrict access to individual user activity for compliance or privacy reasons, clear this checkbox.') diff --git a/ee/spec/requests/admin/application_settings_controller_spec.rb b/ee/spec/requests/admin/application_settings_controller_spec.rb index 7548f95a75a17663e93561c592738334d822846a..7d59da7b17405f780236fd8d9245828d2eba6e4a 100644 --- a/ee/spec/requests/admin/application_settings_controller_spec.rb +++ b/ee/spec/requests/admin/application_settings_controller_spec.rb @@ -80,5 +80,133 @@ get general_admin_application_settings_path end + + context 'for display_gitlab_credits_user_data', feature_category: :consumables_cost_management do + it 'does not show the checkbox in saas', :saas_gitlab_com_subscriptions do + stub_feature_flags(usage_billing_dev: true) + stub_licensed_features(usage_billing: true) + + get general_admin_application_settings_path + + expect(response.body).not_to include('GitLab Credits dashboard') + expect(response.body).not_to include('Display user data') + end + + it 'hides checkbox when usage_billing_dev is disabled' do + stub_feature_flags(usage_billing_dev: false) + stub_licensed_features(usage_billing: true) + + get general_admin_application_settings_path + + expect(response.body).not_to include('GitLab Credits dashboard') + expect(response.body).not_to include('Display user data') + end + + it 'hides checkbox when license does not have usage billing feature' do + stub_feature_flags(usage_billing_dev: true) + stub_licensed_features(usage_billing: false) + + get general_admin_application_settings_path + + expect(response.body).not_to include('GitLab Credits dashboard') + expect(response.body).not_to include('Display user data') + end + + it 'shows the checkbox when both feature flag and license feature are enabled' do + stub_feature_flags(usage_billing_dev: true) + stub_licensed_features(usage_billing: true) + + get general_admin_application_settings_path + + expect(response.body).to include('GitLab Credits dashboard') + expect(response.body).to include('Display user data') + end + + it 'shows checkbox as checked when setting is true' do + stub_feature_flags(usage_billing_dev: true) + stub_licensed_features(usage_billing: true) + ::Gitlab::CurrentSettings.update!(display_gitlab_credits_user_data: true) + + get general_admin_application_settings_path + + expect(response.body).to include('display_gitlab_credits_user_data') + expect(response.body) + .to include('checked="checked" name="application_setting[display_gitlab_credits_user_data]"') + end + + it 'shows checkbox as unchecked when setting is false' do + stub_feature_flags(usage_billing_dev: true) + stub_licensed_features(usage_billing: true) + ::Gitlab::CurrentSettings.update!(display_gitlab_credits_user_data: false) + + get general_admin_application_settings_path + + expect(response.body).to include('display_gitlab_credits_user_data') + expect(response.body) + .not_to include('checked="checked" name="application_setting[display_gitlab_credits_user_data]"') + end + end + end + + describe 'PATCH #update' do + before do + sign_in(admin) + end + + context 'for display_gitlab_credits_user_data', feature_category: :consumables_cost_management do + let(:params) do + { application_setting: { display_gitlab_credits_user_data: display_gitlab_credits_user_data } } + end + + context 'when updating to true' do + let(:display_gitlab_credits_user_data) { true } + + it 'updates the setting successfully' do + patch general_admin_application_settings_path, params: params + + expect(response).to have_gitlab_http_status(:redirect) + expect(::Gitlab::CurrentSettings.display_gitlab_credits_user_data).to be true + end + + it 'shows success message' do + patch general_admin_application_settings_path, params: params + + expect(flash[:notice]).to eq('Application settings saved successfully') + end + end + + context 'when updating to false' do + let(:display_gitlab_credits_user_data) { false } + + before do + ::Gitlab::CurrentSettings.update!(display_gitlab_credits_user_data: true) + end + + it 'updates the setting successfully' do + patch general_admin_application_settings_path, params: params + + expect(response).to have_gitlab_http_status(:redirect) + expect(::Gitlab::CurrentSettings.display_gitlab_credits_user_data).to be false + end + end + + context 'when updating with invalid value' do + let(:display_gitlab_credits_user_data) { nil } + + it 'does not update the setting' do + original_value = ::Gitlab::CurrentSettings.display_gitlab_credits_user_data + + patch general_admin_application_settings_path, params: params + + expect(::Gitlab::CurrentSettings.reload.display_gitlab_credits_user_data).to eq(original_value) + end + + it 'shows error message' do + patch general_admin_application_settings_path, params: params + + expect(response.body).to include('must be a boolean value') + end + end + end end end diff --git a/locale/gitlab.pot b/locale/gitlab.pot index bd9737348a13d5df096dfd12272076a60582a2ca..822527ebaff6d8cf674bc96d67fd5fa3fdc19d79 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -5452,6 +5452,15 @@ msgstr "" msgid "AdminSelfHostedModels|Your self-hosted model was successfully deleted." msgstr "" +msgid "AdminSettingsUsageBilling|Display user data" +msgstr "" + +msgid "AdminSettingsUsageBilling|GitLab Credits dashboard" +msgstr "" + +msgid "AdminSettingsUsageBilling|If selected, individual usernames and their credit usage are visible on the GitLab Credits dashboard. If your organization needs to restrict access to individual user activity for compliance or privacy reasons, clear this checkbox." +msgstr "" + msgid "AdminSettings|%{generate_manually_link_start}Generate%{generate_manually_link_end} Service Ping to preview and download service usage data payload." msgstr ""