Commit 92d2572f authored by Vitaly Slobodin's avatar Vitaly Slobodin

Merge branch 'dz/327886-reroute-storage-purchase' into 'master'

Reroute storage to GitLab flow

See merge request gitlab-org/gitlab!74929
parents a70874fe bdecacbd
...@@ -90,7 +90,6 @@ export default { ...@@ -90,7 +90,6 @@ export default {
isAdditionalStorageFlagEnabled() { isAdditionalStorageFlagEnabled() {
return this.glFeatures.additionalRepoStorageByNamespace; return this.glFeatures.additionalRepoStorageByNamespace;
}, },
formattedNamespaceLimit() { formattedNamespaceLimit() {
return formatUsageSize(this.namespace.limit); return formatUsageSize(this.namespace.limit);
}, },
......
<script> <script>
import { GlButton } from '@gitlab/ui'; import { GlButton } from '@gitlab/ui';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { helpPagePath } from '~/helpers/help_page_helper'; import { helpPagePath } from '~/helpers/help_page_helper';
import { s__ } from '~/locale'; import { s__ } from '~/locale';
import { formatUsageSize } from '../utils'; import { formatUsageSize } from '../utils';
...@@ -10,6 +11,7 @@ export default { ...@@ -10,6 +11,7 @@ export default {
GlButton, GlButton,
UsageStatisticsCard, UsageStatisticsCard,
}, },
mixins: [glFeatureFlagsMixin()],
props: { props: {
rootStorageStatistics: { rootStorageStatistics: {
required: true, required: true,
...@@ -66,6 +68,7 @@ export default { ...@@ -66,6 +68,7 @@ export default {
link: { link: {
text: s__('UsageQuota|Purchase more storage'), text: s__('UsageQuota|Purchase more storage'),
url: this.purchaseStorageUrl, url: this.purchaseStorageUrl,
target: this.glFeatures.newRouteStoragePurchase ? '_self' : '_blank',
}, },
} }
: null; : null;
...@@ -119,7 +122,7 @@ export default { ...@@ -119,7 +122,7 @@ export default {
> >
<template #footer="{ link }"> <template #footer="{ link }">
<gl-button <gl-button
target="_blank" :target="link.target"
:href="link.url" :href="link.url"
class="mb-0" class="mb-0"
variant="confirm" variant="confirm"
......
...@@ -5,6 +5,10 @@ class Groups::UsageQuotasController < Groups::ApplicationController ...@@ -5,6 +5,10 @@ class Groups::UsageQuotasController < Groups::ApplicationController
before_action :verify_usage_quotas_enabled! before_action :verify_usage_quotas_enabled!
before_action :push_additional_repo_storage_by_namespace_feature, only: :index before_action :push_additional_repo_storage_by_namespace_feature, only: :index
before_action do
push_frontend_feature_flag(:new_route_storage_purchase, @group, default_enabled: :yaml)
end
layout 'group_settings' layout 'group_settings'
feature_category :purchase feature_category :purchase
......
...@@ -40,19 +40,29 @@ module EE ...@@ -40,19 +40,29 @@ module EE
end end
def buy_additional_minutes_path(namespace) def buy_additional_minutes_path(namespace)
return EE::SUBSCRIPTIONS_MORE_MINUTES_URL if use_customers_dot_path?(namespace) return EE::SUBSCRIPTIONS_MORE_MINUTES_URL if use_customers_dot_for_minutes_path?(namespace)
buy_minutes_subscriptions_path(selected_group: namespace.id) buy_minutes_subscriptions_path(selected_group: namespace.id)
end end
def buy_additional_minutes_target(namespace) def buy_additional_minutes_target(namespace)
use_customers_dot_path?(namespace) ? '_blank' : '_self' use_customers_dot_for_minutes_path?(namespace) ? '_blank' : '_self'
end
def buy_storage_path(namespace)
return EE::SUBSCRIPTIONS_MORE_STORAGE_URL if use_customers_dot_for_storage_path?(namespace)
buy_storage_subscriptions_path(selected_group: namespace.id)
end end
private private
def use_customers_dot_path?(namespace) def use_customers_dot_for_minutes_path?(namespace)
namespace.user_namespace? || ::Feature.disabled?(:new_route_ci_minutes_purchase, namespace, default_enabled: :yaml) namespace.user_namespace? || ::Feature.disabled?(:new_route_ci_minutes_purchase, namespace, default_enabled: :yaml)
end end
def use_customers_dot_for_storage_path?(namespace)
namespace.user_namespace? || ::Feature.disabled?(:new_route_storage_purchase, namespace, default_enabled: :yaml)
end
end end
end end
- page_title s_("UsageQuota|Usage") - page_title s_("UsageQuota|Usage")
- url_to_purchase_storage = purchase_storage_url if purchase_storage_link_enabled?(@group) - url_to_purchase_storage = buy_storage_path(@group) if purchase_storage_link_enabled?(@group)
- if show_product_purchase_success_alert? - if show_product_purchase_success_alert?
= render 'product_purchase_success_alert', product_name: params[:purchased_product] = render 'product_purchase_success_alert', product_name: params[:purchased_product]
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- root_namespace = payload[:root_namespace] - root_namespace = payload[:root_namespace]
- style = namespace_storage_alert_style(alert_level) - style = namespace_storage_alert_style(alert_level)
- icon = namespace_storage_alert_icon(alert_level) - icon = namespace_storage_alert_icon(alert_level)
- purchase_link = purchase_storage_url if purchase_storage_link_enabled?(namespace) - purchase_link = buy_storage_path(namespace) if purchase_storage_link_enabled?(namespace)
- usage_link = usage_quotas_path(root_namespace, anchor: 'storage-quota-tab') - usage_link = usage_quotas_path(root_namespace, anchor: 'storage-quota-tab')
- show_storage_banner_actions = purchase_link || usage_link - show_storage_banner_actions = purchase_link || usage_link
......
...@@ -7,7 +7,7 @@ import { withRootStorageStatistics } from '../mock_data'; ...@@ -7,7 +7,7 @@ import { withRootStorageStatistics } from '../mock_data';
describe('Usage Statistics component', () => { describe('Usage Statistics component', () => {
let wrapper; let wrapper;
const createComponent = (props = {}) => { const createComponent = ({ props = {}, newRouteStoragePurchase = false } = {}) => {
wrapper = shallowMount(UsageStatistics, { wrapper = shallowMount(UsageStatistics, {
propsData: { propsData: {
rootStorageStatistics: { rootStorageStatistics: {
...@@ -18,6 +18,11 @@ describe('Usage Statistics component', () => { ...@@ -18,6 +18,11 @@ describe('Usage Statistics component', () => {
}, },
...props, ...props,
}, },
provide: {
glFeatures: {
newRouteStoragePurchase,
},
},
stubs: { stubs: {
UsageStatisticsCard, UsageStatisticsCard,
GlSprintf, GlSprintf,
...@@ -26,20 +31,42 @@ describe('Usage Statistics component', () => { ...@@ -26,20 +31,42 @@ describe('Usage Statistics component', () => {
}); });
}; };
afterEach(() => {
wrapper.destroy();
});
const getStatisticsCards = () => wrapper.findAll(UsageStatisticsCard); const getStatisticsCards = () => wrapper.findAll(UsageStatisticsCard);
const getStatisticsCard = (testId) => wrapper.find(`[data-testid="${testId}"]`); const getStatisticsCard = (testId) => wrapper.find(`[data-testid="${testId}"]`);
const findGlLinkInCard = (cardName) => const findGlLinkInCard = (cardName) =>
getStatisticsCard(cardName).find('[data-testid="statistics-card-footer"]').find(GlLink); getStatisticsCard(cardName).find('[data-testid="statistics-card-footer"]').find(GlLink);
const findPurchasedUsageButton = () =>
getStatisticsCard('purchased-usage').findComponent(GlButton);
describe('with purchaseStorageUrl passed', () => { describe('with purchaseStorageUrl passed and newRouteStoragePurchase flag enabled', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
purchaseStorageUrl: 'some-fancy-url', props: {
purchaseStorageUrl: 'some-fancy-url',
},
newRouteStoragePurchase: true,
}); });
}); });
afterEach(() => { it('renders button in purchased usage card footer with correct link', () => {
wrapper.destroy(); expect(findPurchasedUsageButton().attributes()).toMatchObject({
href: 'some-fancy-url',
target: '_self',
});
});
});
describe('with purchaseStorageUrl passed', () => {
beforeEach(() => {
createComponent({
props: {
purchaseStorageUrl: 'some-fancy-url',
},
});
}); });
it('renders three statistics cards', () => { it('renders three statistics cards', () => {
...@@ -58,22 +85,23 @@ describe('Usage Statistics component', () => { ...@@ -58,22 +85,23 @@ describe('Usage Statistics component', () => {
expect(url.attributes('href')).toBe('/help/user/usage_quotas#excess-storage-usage'); expect(url.attributes('href')).toBe('/help/user/usage_quotas#excess-storage-usage');
}); });
it('renders button in purchased usage card footer', () => { it('renders button in purchased usage card footer with correct link', () => {
expect(getStatisticsCard('purchased-usage').find(GlButton).exists()).toBe(true); expect(findPurchasedUsageButton().attributes()).toMatchObject({
href: 'some-fancy-url',
target: '_blank',
});
}); });
}); });
describe('with no purchaseStorageUrl', () => { describe('with no purchaseStorageUrl', () => {
beforeEach(() => { beforeEach(() => {
createComponent({ createComponent({
purchaseStorageUrl: null, props: {
purchaseStorageUrl: null,
},
}); });
}); });
afterEach(() => {
wrapper.destroy();
});
it('does not render purchased usage card if purchaseStorageUrl is not provided', () => { it('does not render purchased usage card if purchaseStorageUrl is not provided', () => {
expect(getStatisticsCard('purchased-usage').exists()).toBe(false); expect(getStatisticsCard('purchased-usage').exists()).toBe(false);
}); });
......
...@@ -175,7 +175,9 @@ RSpec.describe EE::NamespacesHelper do ...@@ -175,7 +175,9 @@ RSpec.describe EE::NamespacesHelper do
describe '#buy_additional_minutes_path' do describe '#buy_additional_minutes_path' do
subject { helper.buy_additional_minutes_path(namespace) } subject { helper.buy_additional_minutes_path(namespace) }
let_it_be(:namespace) { create(:group) } let(:namespace) { build_stubbed(:group) }
it { is_expected.to eq buy_minutes_subscriptions_path(selected_group: namespace.id) }
context 'new_route_ci_minutes_purchase' do context 'new_route_ci_minutes_purchase' do
context 'when is disabled' do context 'when is disabled' do
...@@ -183,16 +185,11 @@ RSpec.describe EE::NamespacesHelper do ...@@ -183,16 +185,11 @@ RSpec.describe EE::NamespacesHelper do
stub_feature_flags(new_route_ci_minutes_purchase: false) stub_feature_flags(new_route_ci_minutes_purchase: false)
end end
it { is_expected.to be EE::SUBSCRIPTIONS_MORE_MINUTES_URL } it { is_expected.to eq EE::SUBSCRIPTIONS_MORE_MINUTES_URL }
end end
context 'when is enabled' do context 'when new_route_ci_minutes_purchase is enabled only for a specific namespace' do
it { is_expected.to eq buy_minutes_subscriptions_path(selected_group: namespace.id) } let(:enabled_namespace) { build_stubbed(:group) }
end
context 'when is enabled only for a specific namespace' do
let_it_be(:enabled_namespace) { create(:group) }
let_it_be(:disabled_namespace) { create(:group) }
before do before do
stub_feature_flags(new_route_ci_minutes_purchase: false) stub_feature_flags(new_route_ci_minutes_purchase: false)
...@@ -200,7 +197,7 @@ RSpec.describe EE::NamespacesHelper do ...@@ -200,7 +197,7 @@ RSpec.describe EE::NamespacesHelper do
end end
it 'returns the default purchase path for the disabled namespace' do it 'returns the default purchase path for the disabled namespace' do
expect(helper.buy_additional_minutes_path(disabled_namespace)).to be EE::SUBSCRIPTIONS_MORE_MINUTES_URL expect(helper.buy_additional_minutes_path(namespace)).to eq EE::SUBSCRIPTIONS_MORE_MINUTES_URL
end end
it 'returns GitLab purchase path for the disabled namespace' do it 'returns GitLab purchase path for the disabled namespace' do
...@@ -209,11 +206,55 @@ RSpec.describe EE::NamespacesHelper do ...@@ -209,11 +206,55 @@ RSpec.describe EE::NamespacesHelper do
end end
context 'when called for a personal namespace' do context 'when called for a personal namespace' do
let_it_be(:user) { create(:user) } let(:user) { create(:user) }
let_it_be(:personal_namespace) { user.namespace } let(:personal_namespace) { build_stubbed(:user_namespace) }
it 'returns the default purchase' do
expect(helper.buy_additional_minutes_path(personal_namespace)).to eq EE::SUBSCRIPTIONS_MORE_MINUTES_URL
end
end
end
end
describe '#buy_storage_path' do
subject { helper.buy_storage_path(namespace) }
let(:namespace) { build_stubbed(:group) }
it { is_expected.to eq buy_storage_subscriptions_path(selected_group: namespace.id) }
context 'new_route_storage_purchase' do
context 'when is disabled' do
before do
stub_feature_flags(new_route_storage_purchase: false)
end
it { is_expected.to eq EE::SUBSCRIPTIONS_MORE_STORAGE_URL }
end
context 'when new_route_storage_purchase is enabled only for a specific namespace' do
let(:enabled_namespace) { build_stubbed(:group) }
before do
stub_feature_flags(new_route_storage_purchase: false)
stub_feature_flags(new_route_storage_purchase: enabled_namespace)
end
it 'returns the default purchase path for the disabled namespace' do
expect(helper.buy_storage_path(namespace)).to eq EE::SUBSCRIPTIONS_MORE_STORAGE_URL
end
it 'returns GitLab purchase path for the disabled namespace' do
expect(helper.buy_storage_path(enabled_namespace)).to eq buy_storage_subscriptions_path(selected_group: enabled_namespace.id)
end
end
context 'when called for a personal namespace' do
let(:user) { create(:user) }
let(:personal_namespace) { build_stubbed(:user_namespace) }
it 'returns the default purchase' do it 'returns the default purchase' do
expect(helper.buy_additional_minutes_path(personal_namespace)).to be EE::SUBSCRIPTIONS_MORE_MINUTES_URL expect(helper.buy_storage_path(personal_namespace)).to eq EE::SUBSCRIPTIONS_MORE_STORAGE_URL
end end
end end
end end
...@@ -222,7 +263,7 @@ RSpec.describe EE::NamespacesHelper do ...@@ -222,7 +263,7 @@ RSpec.describe EE::NamespacesHelper do
describe '#buy_additional_minutes_target' do describe '#buy_additional_minutes_target' do
subject { helper.buy_additional_minutes_target(namespace) } subject { helper.buy_additional_minutes_target(namespace) }
let_it_be(:namespace) { create(:group) } let(:namespace) { create(:group) }
context 'new_route_ci_minutes_purchase' do context 'new_route_ci_minutes_purchase' do
context 'when is disabled' do context 'when is disabled' do
...@@ -230,7 +271,7 @@ RSpec.describe EE::NamespacesHelper do ...@@ -230,7 +271,7 @@ RSpec.describe EE::NamespacesHelper do
stub_feature_flags(new_route_ci_minutes_purchase: false) stub_feature_flags(new_route_ci_minutes_purchase: false)
end end
it { is_expected.to be '_blank' } it { is_expected.to eq '_blank' }
end end
context 'when is enabled' do context 'when is enabled' do
...@@ -238,8 +279,7 @@ RSpec.describe EE::NamespacesHelper do ...@@ -238,8 +279,7 @@ RSpec.describe EE::NamespacesHelper do
end end
context 'when is enabled only for a specific namespace' do context 'when is enabled only for a specific namespace' do
let_it_be(:enabled_namespace) { create(:group) } let(:enabled_namespace) { build_stubbed(:group) }
let_it_be(:disabled_namespace) { create(:group) }
before do before do
stub_feature_flags(new_route_ci_minutes_purchase: false) stub_feature_flags(new_route_ci_minutes_purchase: false)
...@@ -247,7 +287,7 @@ RSpec.describe EE::NamespacesHelper do ...@@ -247,7 +287,7 @@ RSpec.describe EE::NamespacesHelper do
end end
it 'returns _blank for the disabled namespace' do it 'returns _blank for the disabled namespace' do
expect(helper.buy_additional_minutes_target(disabled_namespace)).to be '_blank' expect(helper.buy_additional_minutes_target(namespace)).to eq '_blank'
end end
it 'returns _self for the disabled namespace' do it 'returns _self for the disabled namespace' do
...@@ -256,11 +296,11 @@ RSpec.describe EE::NamespacesHelper do ...@@ -256,11 +296,11 @@ RSpec.describe EE::NamespacesHelper do
end end
context 'when called for a personal namespace' do context 'when called for a personal namespace' do
let_it_be(:user) { create(:user) } let(:user) { create(:user) }
let_it_be(:personal_namespace) { user.namespace } let(:personal_namespace) { build_stubbed(:user_namespace) }
it 'returns _blank' do it 'returns _blank' do
expect(helper.buy_additional_minutes_target(personal_namespace)).to be '_blank' expect(helper.buy_additional_minutes_target(personal_namespace)).to eq '_blank'
end end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment