From f7b2b4ef94434865642b97a3f7b3694b52edf4ac Mon Sep 17 00:00:00 2001 From: Sheldon Led Date: Fri, 5 Dec 2025 16:09:16 -0300 Subject: [PATCH 1/5] Conditionally display user data on GitLab Credits Dashboard --- .../usage_billing/components/app.vue | 8 ++++- .../users_controller.rb | 6 +++- .../gitlab_credits_dashboard_controller.rb | 3 ++ .../gitlab_duo/usage/users_controller.rb | 3 +- .../settings/gitlab_duo/usage_controller.rb | 3 ++ .../usage_billing/components/app_spec.js | 12 ++++++++ .../users_controller_spec.rb | 12 ++++++++ ...itlab_credits_dashboard_controller_spec.rb | 12 ++++++++ .../gitlab_duo/usage/users_controller_spec.rb | 15 +++++++++- .../gitlab_duo/usage_controller_spec.rb | 12 ++++++++ lib/gitlab/gon_helper.rb | 6 ++++ locale/gitlab.pot | 3 ++ spec/lib/gitlab/gon_helper_spec.rb | 30 +++++++++++++++++++ 13 files changed, 121 insertions(+), 4 deletions(-) diff --git a/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue b/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue index 1b6815f9c20954..8effdb9ca0ad33 100644 --- a/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue +++ b/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue @@ -65,6 +65,9 @@ export default { isUsageBillingDisabled() { return this.subscriptionUsage?.enabled === false; }, + shouldDisplayUserData() { + return gon.display_gitlab_credits_user_data; + }, subscriptionsUrl() { return gon.subscriptions_url; }, @@ -249,7 +252,10 @@ export default { /> - + + + {{ s__('UsageBilling|Displaying user data is currently disabled.') }} + diff --git a/ee/app/controllers/admin/gitlab_credits_dashboard/users_controller.rb b/ee/app/controllers/admin/gitlab_credits_dashboard/users_controller.rb index 2e17371c63edd3..769998a3e9e25f 100644 --- a/ee/app/controllers/admin/gitlab_credits_dashboard/users_controller.rb +++ b/ee/app/controllers/admin/gitlab_credits_dashboard/users_controller.rb @@ -7,6 +7,9 @@ class UsersController < Admin::ApplicationController urgency :low before_action :ensure_feature_available! + before_action do + push_application_setting(:display_gitlab_credits_user_data) + end def show @username = params.permit(:username)[:username] @@ -17,8 +20,9 @@ def show def ensure_feature_available! return render_404 unless Feature.enabled?(:usage_billing_dev, :instance) return render_404 unless License.feature_available?(:usage_billing) + return render_404 if Gitlab::Saas.feature_available?(:gitlab_com_subscriptions) - render_404 if Gitlab::Saas.feature_available?(:gitlab_com_subscriptions) + render_404 unless ::Gitlab::CurrentSettings.display_gitlab_credits_user_data end end end diff --git a/ee/app/controllers/admin/gitlab_credits_dashboard_controller.rb b/ee/app/controllers/admin/gitlab_credits_dashboard_controller.rb index 96fe7e42fbe5cb..9c6457b1b72b7a 100644 --- a/ee/app/controllers/admin/gitlab_credits_dashboard_controller.rb +++ b/ee/app/controllers/admin/gitlab_credits_dashboard_controller.rb @@ -6,6 +6,9 @@ class GitlabCreditsDashboardController < Admin::ApplicationController urgency :low before_action :ensure_feature_available! + before_action do + push_application_setting(:display_gitlab_credits_user_data) + end private diff --git a/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb b/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb index 09ff1358dc0da9..b95183bb9942b3 100644 --- a/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb +++ b/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb @@ -19,8 +19,9 @@ def show def ensure_feature_available! return render_404 unless Feature.enabled?(:usage_billing_dev, @group) return render_404 unless Gitlab::Saas.feature_available?(:gitlab_com_subscriptions) + return render_404 unless @group&.namespace_settings.respond_to?(:display_gitlab_credits_user_data) - render_404 unless @group.licensed_feature_available?(:group_usage_billing) + render_404 unless @group.namespace_settings.display_gitlab_credits_user_data end end end diff --git a/ee/app/controllers/groups/settings/gitlab_duo/usage_controller.rb b/ee/app/controllers/groups/settings/gitlab_duo/usage_controller.rb index 8c7b3842d5da0c..e1bce20119eada 100644 --- a/ee/app/controllers/groups/settings/gitlab_duo/usage_controller.rb +++ b/ee/app/controllers/groups/settings/gitlab_duo/usage_controller.rb @@ -6,6 +6,9 @@ module GitlabDuo class UsageController < Groups::ApplicationController before_action :authorize_read_usage_quotas! before_action :ensure_feature_available! + before_action do + push_namespace_setting(:display_gitlab_credits_user_data, @group) + end feature_category :consumables_cost_management diff --git a/ee/spec/frontend/usage_quotas/usage_billing/components/app_spec.js b/ee/spec/frontend/usage_quotas/usage_billing/components/app_spec.js index 18ef76824fbcbb..19c73ee1b51e73 100644 --- a/ee/spec/frontend/usage_quotas/usage_billing/components/app_spec.js +++ b/ee/spec/frontend/usage_quotas/usage_billing/components/app_spec.js @@ -63,6 +63,10 @@ describe('UsageBillingApp', () => { const findOutdatedClientAlert = () => wrapper.findByTestId('outdated-client-alert'); const findDisabledStateAlert = () => wrapper.findByTestId('usage-billing-disabled-alert'); + beforeEach(() => { + window.gon = { display_gitlab_credits_user_data: true }; + }); + describe('loading state', () => { beforeEach(() => { const loadingQueryHandler = jest.fn().mockImplementation(() => new Promise(() => {})); @@ -428,6 +432,14 @@ describe('UsageBillingApp', () => { it('renders UsageByUserTab component', () => { expect(findUsageByUserTab().exists()).toBe(true); }); + + it('does not render UsageByUserTab component if display_gitlab_credits_user_data is false', async () => { + window.gon = { display_gitlab_credits_user_data: false }; + createComponent(); + await waitForPromises(); + + expect(findUsageByUserTab().exists()).toBe(false); + }); }); }); diff --git a/ee/spec/requests/admin/gitlab_credits_dashboard/users_controller_spec.rb b/ee/spec/requests/admin/gitlab_credits_dashboard/users_controller_spec.rb index e9b10fe40774a0..be03d7e3bdab21 100644 --- a/ee/spec/requests/admin/gitlab_credits_dashboard/users_controller_spec.rb +++ b/ee/spec/requests/admin/gitlab_credits_dashboard/users_controller_spec.rb @@ -7,10 +7,12 @@ let(:admin) { create(:admin) } let(:user) { create(:user) } let(:usage_billing_dev_enabled) { true } + let(:display_gitlab_credits_user_data) { true } before do sign_in(admin) stub_feature_flags(usage_billing_dev: usage_billing_dev_enabled) + stub_application_setting(display_gitlab_credits_user_data: display_gitlab_credits_user_data) end describe 'GET /admin/gitlab_credits_dashboard/users' do @@ -44,5 +46,15 @@ expect(response).to have_gitlab_http_status(:not_found) end end + + context 'when display_gitlab_credits_user_data is false' do + let(:display_gitlab_credits_user_data) { false } + + it 'renders 404' do + request + + expect(response).to have_gitlab_http_status(:not_found) + end + end end end diff --git a/ee/spec/requests/admin/gitlab_credits_dashboard_controller_spec.rb b/ee/spec/requests/admin/gitlab_credits_dashboard_controller_spec.rb index 9b0d2c7cf150d5..175b41c13315c2 100644 --- a/ee/spec/requests/admin/gitlab_credits_dashboard_controller_spec.rb +++ b/ee/spec/requests/admin/gitlab_credits_dashboard_controller_spec.rb @@ -42,5 +42,17 @@ expect(response).to have_gitlab_http_status(:not_found) end end + + context 'for display_gitlab_credits_user_data' do + before do + stub_application_setting(display_gitlab_credits_user_data: true) + end + + it 'pushes the setting to the frontend' do + request + + expect(response.body).to include('gon.display_gitlab_credits_user_data=true') + end + end end end diff --git a/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb b/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb index bf44c7b7a60f36..ad0dcb8308921f 100644 --- a/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb +++ b/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb @@ -4,10 +4,13 @@ RSpec.describe Groups::Settings::GitlabDuo::Usage::UsersController, feature_category: :consumables_cost_management do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group) } + let_it_be_with_reload(:group) { create(:group) } + let(:usage_billing_dev_enabled) { true } + let(:display_gitlab_credits_user_data) { true } before do + group.namespace_settings.update!(display_gitlab_credits_user_data: display_gitlab_credits_user_data) sign_in(user) stub_feature_flags(usage_billing_dev: usage_billing_dev_enabled) end @@ -56,6 +59,16 @@ end end end + + context 'when display_gitlab_credits_user_data is false' do + let(:display_gitlab_credits_user_data) { false } + + it 'renders 404' do + request + + expect(response).to have_gitlab_http_status(:not_found) + end + end end context 'when in Self-Managed' do diff --git a/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb b/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb index 615e4a97d2d299..6843c6c5705a85 100644 --- a/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb +++ b/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb @@ -56,6 +56,18 @@ end end end + + context 'for display_gitlab_credits_user_data' do + before do + group.namespace_settings.update!(display_gitlab_credits_user_data: true) + end + + it 'pushes the setting to the frontend' do + request + + expect(response.body).to include('gon.display_gitlab_credits_user_data=true') + end + end end context 'when in Self-Managed' do diff --git a/lib/gitlab/gon_helper.rb b/lib/gitlab/gon_helper.rb index 8aba0213ad359e..ff4b60d2c0a13b 100644 --- a/lib/gitlab/gon_helper.rb +++ b/lib/gitlab/gon_helper.rb @@ -145,6 +145,12 @@ def push_force_frontend_feature_flag(name, enabled) push_to_gon_attributes(:features, name, enabled) end + def push_application_setting(key) + return unless Gitlab::CurrentSettings.respond_to?(key) + + gon.push({ key => Gitlab::CurrentSettings.public_send(key) }) # rubocop:disable GitlabSecurity/PublicSend + end + def push_namespace_setting(key, object) return unless object&.namespace_settings.respond_to?(key) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 9d1307399db059..f2d007e635adf1 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -72052,6 +72052,9 @@ msgstr "" msgid "UsageBilling|Date/Time" msgstr "" +msgid "UsageBilling|Displaying user data is currently disabled." +msgstr "" + msgid "UsageBilling|Enable on-demand billing to keep GitLab Duo features active when monthly GitLab Credits run out. Without these terms, users lose GitLab Duo access after exhausting their included GitLab Credits. Learn about %{linkStart}overage billing%{linkEnd}." msgstr "" diff --git a/spec/lib/gitlab/gon_helper_spec.rb b/spec/lib/gitlab/gon_helper_spec.rb index 57b471b05c49f0..d2cad7dc2eaba1 100644 --- a/spec/lib/gitlab/gon_helper_spec.rb +++ b/spec/lib/gitlab/gon_helper_spec.rb @@ -237,6 +237,36 @@ end end + describe '#push_application_setting' do + it 'pushes an application setting to the frontend' do + stub_application_setting(signup_enabled: true) + + gon = class_double('Gon') + allow(helper) + .to receive(:gon) + .and_return(gon) + + expect(gon) + .to receive(:push) + .with({ signup_enabled: true }) + + helper.push_application_setting(:signup_enabled) + end + + it 'does not push if missing application setting entry' do + gon = class_double('Gon') + allow(helper) + .to receive(:gon) + .and_return(gon) + + expect(gon) + .not_to receive(:push) + .with({ non_existent_application_setting: true }) + + helper.push_application_setting(:non_existent_application_setting) + end + end + describe '#default_avatar_url' do it 'returns an absolute URL' do url = helper.default_avatar_url -- GitLab From a5cd2d8c339f86144a7acac7b32425a5cc91abe3 Mon Sep 17 00:00:00 2001 From: Ammar Alakkad Date: Thu, 11 Dec 2025 10:13:42 +0300 Subject: [PATCH 2/5] Adjust copy in main usage billing app --- .../javascripts/usage_quotas/usage_billing/components/app.vue | 2 +- locale/gitlab.pot | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue b/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue index 8effdb9ca0ad33..be0aded0dbf73b 100644 --- a/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue +++ b/ee/app/assets/javascripts/usage_quotas/usage_billing/components/app.vue @@ -254,7 +254,7 @@ export default { - {{ s__('UsageBilling|Displaying user data is currently disabled.') }} + {{ s__('UsageBilling|Displaying user data is disabled.') }} diff --git a/locale/gitlab.pot b/locale/gitlab.pot index f2d007e635adf1..433daac9366945 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -72052,7 +72052,7 @@ msgstr "" msgid "UsageBilling|Date/Time" msgstr "" -msgid "UsageBilling|Displaying user data is currently disabled." +msgid "UsageBilling|Displaying user data is disabled." msgstr "" msgid "UsageBilling|Enable on-demand billing to keep GitLab Duo features active when monthly GitLab Credits run out. Without these terms, users lose GitLab Duo access after exhausting their included GitLab Credits. Learn about %{linkStart}overage billing%{linkEnd}." -- GitLab From 92e1d9583cb43a4bb92aa833ead4f21809dfa1cd Mon Sep 17 00:00:00 2001 From: Ammar Alakkad Date: Thu, 11 Dec 2025 12:04:08 +0300 Subject: [PATCH 3/5] Fix group users controller spec --- .../groups/settings/gitlab_duo/usage/users_controller.rb | 1 + .../settings/gitlab_duo/usage/users_controller_spec.rb | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb b/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb index b95183bb9942b3..d473578c8c946d 100644 --- a/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb +++ b/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb @@ -19,6 +19,7 @@ def show def ensure_feature_available! return render_404 unless Feature.enabled?(:usage_billing_dev, @group) return render_404 unless Gitlab::Saas.feature_available?(:gitlab_com_subscriptions) + return render_404 unless @group.licensed_feature_available?(:group_usage_billing) return render_404 unless @group&.namespace_settings.respond_to?(:display_gitlab_credits_user_data) render_404 unless @group.namespace_settings.display_gitlab_credits_user_data diff --git a/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb b/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb index ad0dcb8308921f..2f9b3ba3e3da35 100644 --- a/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb +++ b/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb @@ -10,7 +10,6 @@ let(:display_gitlab_credits_user_data) { true } before do - group.namespace_settings.update!(display_gitlab_credits_user_data: display_gitlab_credits_user_data) sign_in(user) stub_feature_flags(usage_billing_dev: usage_billing_dev_enabled) end @@ -43,6 +42,10 @@ paid_group.add_owner(user) end + before do + paid_group.namespace_settings.update!(display_gitlab_credits_user_data: display_gitlab_credits_user_data) + end + it 'returns 200' do request @@ -90,6 +93,7 @@ end before do + paid_group.namespace_settings.update!(display_gitlab_credits_user_data: display_gitlab_credits_user_data) stub_ee_application_setting(should_check_namespace_plan: true) end -- GitLab From 6c11588b7c9a6920da753302e004d49e5d4f6cef Mon Sep 17 00:00:00 2001 From: Ammar Alakkad Date: Sat, 13 Dec 2025 09:29:28 +0300 Subject: [PATCH 4/5] Fix spec in usage_controller_spec.rb --- .../gitlab_duo/usage/users_controller_spec.rb | 12 ++++++------ .../settings/gitlab_duo/usage_controller_spec.rb | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb b/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb index 2f9b3ba3e3da35..84447551f1e00a 100644 --- a/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb +++ b/ee/spec/requests/groups/settings/gitlab_duo/usage/users_controller_spec.rb @@ -61,15 +61,15 @@ expect(response).to have_gitlab_http_status(:not_found) end end - end - context 'when display_gitlab_credits_user_data is false' do - let(:display_gitlab_credits_user_data) { false } + context 'when display_gitlab_credits_user_data is false' do + let(:display_gitlab_credits_user_data) { false } - it 'renders 404' do - request + it 'renders 404' do + request - expect(response).to have_gitlab_http_status(:not_found) + expect(response).to have_gitlab_http_status(:not_found) + end end end end diff --git a/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb b/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb index 6843c6c5705a85..b3608c8e3b68bc 100644 --- a/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb +++ b/ee/spec/requests/groups/settings/gitlab_duo/usage_controller_spec.rb @@ -55,17 +55,17 @@ expect(response).to have_gitlab_http_status(:not_found) end end - end - context 'for display_gitlab_credits_user_data' do - before do - group.namespace_settings.update!(display_gitlab_credits_user_data: true) - end + context 'for display_gitlab_credits_user_data' do + before do + paid_group.namespace_settings.update!(display_gitlab_credits_user_data: true) + end - it 'pushes the setting to the frontend' do - request + it 'pushes the setting to the frontend' do + request - expect(response.body).to include('gon.display_gitlab_credits_user_data=true') + expect(response.body).to include('gon.display_gitlab_credits_user_data=true') + end end end end -- GitLab From 1eb25fd291c2422ca1b91936b6bddd1b32a77a43 Mon Sep 17 00:00:00 2001 From: Suraj Tripathi Date: Mon, 15 Dec 2025 14:32:22 +0530 Subject: [PATCH 5/5] Remove unwanted check --- .../groups/settings/gitlab_duo/usage/users_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb b/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb index d473578c8c946d..0726a65f82d47c 100644 --- a/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb +++ b/ee/app/controllers/groups/settings/gitlab_duo/usage/users_controller.rb @@ -20,7 +20,6 @@ def ensure_feature_available! return render_404 unless Feature.enabled?(:usage_billing_dev, @group) return render_404 unless Gitlab::Saas.feature_available?(:gitlab_com_subscriptions) return render_404 unless @group.licensed_feature_available?(:group_usage_billing) - return render_404 unless @group&.namespace_settings.respond_to?(:display_gitlab_credits_user_data) render_404 unless @group.namespace_settings.display_gitlab_credits_user_data end -- GitLab