Commit bdecacbd authored by Diana Zubova's avatar Diana Zubova Committed by Vitaly Slobodin

Reroute storage to GitLab flow

parent e8ed8549
......@@ -90,7 +90,6 @@ export default {
isAdditionalStorageFlagEnabled() {
return this.glFeatures.additionalRepoStorageByNamespace;
},
formattedNamespaceLimit() {
return formatUsageSize(this.namespace.limit);
},
......
<script>
import { GlButton } from '@gitlab/ui';
import glFeatureFlagsMixin from '~/vue_shared/mixins/gl_feature_flags_mixin';
import { helpPagePath } from '~/helpers/help_page_helper';
import { s__ } from '~/locale';
import { formatUsageSize } from '../utils';
......@@ -10,6 +11,7 @@ export default {
GlButton,
UsageStatisticsCard,
},
mixins: [glFeatureFlagsMixin()],
props: {
rootStorageStatistics: {
required: true,
......@@ -66,6 +68,7 @@ export default {
link: {
text: s__('UsageQuota|Purchase more storage'),
url: this.purchaseStorageUrl,
target: this.glFeatures.newRouteStoragePurchase ? '_self' : '_blank',
},
}
: null;
......@@ -119,7 +122,7 @@ export default {
>
<template #footer="{ link }">
<gl-button
target="_blank"
:target="link.target"
:href="link.url"
class="mb-0"
variant="confirm"
......
......@@ -5,6 +5,10 @@ class Groups::UsageQuotasController < Groups::ApplicationController
before_action :verify_usage_quotas_enabled!
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'
feature_category :purchase
......
......@@ -40,19 +40,29 @@ module EE
end
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)
end
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
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)
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
- 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?
= render 'product_purchase_success_alert', product_name: params[:purchased_product]
......
......@@ -10,7 +10,7 @@
- root_namespace = payload[:root_namespace]
- style = namespace_storage_alert_style(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')
- show_storage_banner_actions = purchase_link || usage_link
......
......@@ -7,7 +7,7 @@ import { withRootStorageStatistics } from '../mock_data';
describe('Usage Statistics component', () => {
let wrapper;
const createComponent = (props = {}) => {
const createComponent = ({ props = {}, newRouteStoragePurchase = false } = {}) => {
wrapper = shallowMount(UsageStatistics, {
propsData: {
rootStorageStatistics: {
......@@ -18,6 +18,11 @@ describe('Usage Statistics component', () => {
},
...props,
},
provide: {
glFeatures: {
newRouteStoragePurchase,
},
},
stubs: {
UsageStatisticsCard,
GlSprintf,
......@@ -26,20 +31,42 @@ describe('Usage Statistics component', () => {
});
};
afterEach(() => {
wrapper.destroy();
});
const getStatisticsCards = () => wrapper.findAll(UsageStatisticsCard);
const getStatisticsCard = (testId) => wrapper.find(`[data-testid="${testId}"]`);
const findGlLinkInCard = (cardName) =>
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(() => {
createComponent({
purchaseStorageUrl: 'some-fancy-url',
props: {
purchaseStorageUrl: 'some-fancy-url',
},
newRouteStoragePurchase: true,
});
});
afterEach(() => {
wrapper.destroy();
it('renders button in purchased usage card footer with correct link', () => {
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', () => {
......@@ -58,22 +85,23 @@ describe('Usage Statistics component', () => {
expect(url.attributes('href')).toBe('/help/user/usage_quotas#excess-storage-usage');
});
it('renders button in purchased usage card footer', () => {
expect(getStatisticsCard('purchased-usage').find(GlButton).exists()).toBe(true);
it('renders button in purchased usage card footer with correct link', () => {
expect(findPurchasedUsageButton().attributes()).toMatchObject({
href: 'some-fancy-url',
target: '_blank',
});
});
});
describe('with no purchaseStorageUrl', () => {
beforeEach(() => {
createComponent({
purchaseStorageUrl: null,
props: {
purchaseStorageUrl: null,
},
});
});
afterEach(() => {
wrapper.destroy();
});
it('does not render purchased usage card if purchaseStorageUrl is not provided', () => {
expect(getStatisticsCard('purchased-usage').exists()).toBe(false);
});
......
......@@ -175,7 +175,9 @@ RSpec.describe EE::NamespacesHelper do
describe '#buy_additional_minutes_path' do
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 'when is disabled' do
......@@ -183,16 +185,11 @@ RSpec.describe EE::NamespacesHelper do
stub_feature_flags(new_route_ci_minutes_purchase: false)
end
it { is_expected.to be EE::SUBSCRIPTIONS_MORE_MINUTES_URL }
it { is_expected.to eq EE::SUBSCRIPTIONS_MORE_MINUTES_URL }
end
context 'when is enabled' do
it { is_expected.to eq buy_minutes_subscriptions_path(selected_group: namespace.id) }
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) }
context 'when new_route_ci_minutes_purchase is enabled only for a specific namespace' do
let(:enabled_namespace) { build_stubbed(:group) }
before do
stub_feature_flags(new_route_ci_minutes_purchase: false)
......@@ -200,7 +197,7 @@ RSpec.describe EE::NamespacesHelper do
end
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
it 'returns GitLab purchase path for the disabled namespace' do
......@@ -209,11 +206,55 @@ RSpec.describe EE::NamespacesHelper do
end
context 'when called for a personal namespace' do
let_it_be(:user) { create(:user) }
let_it_be(:personal_namespace) { user.namespace }
let(:user) { create(:user) }
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
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
......@@ -222,7 +263,7 @@ RSpec.describe EE::NamespacesHelper do
describe '#buy_additional_minutes_target' do
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 'when is disabled' do
......@@ -230,7 +271,7 @@ RSpec.describe EE::NamespacesHelper do
stub_feature_flags(new_route_ci_minutes_purchase: false)
end
it { is_expected.to be '_blank' }
it { is_expected.to eq '_blank' }
end
context 'when is enabled' do
......@@ -238,8 +279,7 @@ RSpec.describe EE::NamespacesHelper do
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) }
let(:enabled_namespace) { build_stubbed(:group) }
before do
stub_feature_flags(new_route_ci_minutes_purchase: false)
......@@ -247,7 +287,7 @@ RSpec.describe EE::NamespacesHelper do
end
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
it 'returns _self for the disabled namespace' do
......@@ -256,11 +296,11 @@ RSpec.describe EE::NamespacesHelper do
end
context 'when called for a personal namespace' do
let_it_be(:user) { create(:user) }
let_it_be(:personal_namespace) { user.namespace }
let(:user) { create(:user) }
let(:personal_namespace) { build_stubbed(:user_namespace) }
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
......
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