diff --git a/ee/app/helpers/ee/groups_helper.rb b/ee/app/helpers/ee/groups_helper.rb index 5ed7621f8c66e6516fa0c370708732e64f90febf..e6e8f8720ce2a4b9c277d59a0c46fd2fa0ff63dd 100644 --- a/ee/app/helpers/ee/groups_helper.rb +++ b/ee/app/helpers/ee/groups_helper.rb @@ -3,6 +3,7 @@ module EE module GroupsHelper extend ::Gitlab::Utils::Override + include ::Gitlab::Utils::StrongMemoize include ::GitlabSubscriptions::CodeSuggestionsHelper include ::Subscriptions::HandRaiseLeadsHelper include ::Nav::GitlabDuoUsageSettingsPage @@ -115,7 +116,22 @@ def code_suggestions_usage_app_data(group) hand_raise_lead: code_suggestions_usage_app_hand_raise_lead_data, is_free_namespace: group.has_free_or_no_subscription?.to_s, buy_subscription_path: group_billings_path(group) - }.merge(duo_pro_trial_link(group), active_duo_pro_trial_data(group)) + }.merge(duo_pro_trial_link(group), active_duo_pro_trial_data(group), active_subscription_data(group)) + end + + def active_subscription_data(group) + return {} unless group_gitlab_subscription(group) + + { + subscription_start_date: group_gitlab_subscription(group).start_date, + subscription_end_date: group_gitlab_subscription(group).end_date + } + end + + def group_gitlab_subscription(group) + strong_memoize(:group_gitlab_subscription) do + group.gitlab_subscription + end end def active_duo_pro_trial_data(group) diff --git a/ee/spec/helpers/ee/groups_helper_spec.rb b/ee/spec/helpers/ee/groups_helper_spec.rb index 3f44e8740f275933e5aa207071a6295d46a09283..436cb8728dea93b8fe8bf761aeb7b79aa67be4e8 100644 --- a/ee/spec/helpers/ee/groups_helper_spec.rb +++ b/ee/spec/helpers/ee/groups_helper_spec.rb @@ -499,6 +499,29 @@ end end + describe '#active_subscription_data' do + context 'when there is a current subscription', :saas do + let(:subscription) { create(:gitlab_subscription, namespace: group) } + + before do + group.gitlab_subscription = subscription + end + + it 'returns the subscription start date and end date' do + expect(helper.active_subscription_data(group)).to eq({ + subscription_start_date: subscription.start_date, + subscription_end_date: subscription.end_date + }) + end + end + + context 'when there is no current subscription' do + it 'returns empty' do + expect(helper.active_subscription_data(group)).to eq({}) + end + end + end + describe '#active_duo_pro_trial_data' do context 'when an active duo pro trial exists' do let(:trial_add_on) { create(:gitlab_subscription_add_on_purchase, :gitlab_duo_pro, :trial, namespace: group) }