Commit 0745b989 authored by Stan Hu's avatar Stan Hu

Merge branch '267977_refactor_purchase_storage_link_helpers' into 'master'

Refactor purchase storage link helpers

See merge request gitlab-org/gitlab!45531
parents 2a97a6ab 8ef5b0ca
......@@ -46,13 +46,11 @@ module EE
end
end
def namespace_storage_purchase_link(namespace)
return unless ::Gitlab.dev_env_or_com?
return unless ::Gitlab::CurrentSettings.automatic_purchased_storage_allocation?
return unless ::Feature.enabled?(:buy_storage_link)
return unless ::Feature.enabled?(:additional_repo_storage_by_namespace, namespace)
EE::SUBSCRIPTIONS_MORE_STORAGE_URL
def can_purchase_storage_for_namespace?(namespace)
::Gitlab.dev_env_or_com? &&
::Gitlab::CurrentSettings.automatic_purchased_storage_allocation? &&
::Feature.enabled?(:buy_storage_link) &&
::Feature.enabled?(:additional_repo_storage_by_namespace, namespace)
end
def namespace_storage_usage_link(namespace)
......@@ -63,11 +61,13 @@ module EE
end
end
def purchase_storage_url
return unless ::Gitlab.dev_env_or_com?
return unless ::Gitlab::CurrentSettings.enforce_namespace_storage_limit?
return unless ::Feature.enabled?(:buy_storage_link)
def can_purchase_storage?
::Gitlab.dev_env_or_com? &&
::Gitlab::CurrentSettings.enforce_namespace_storage_limit? &&
::Feature.enabled?(:buy_storage_link)
end
def purchase_storage_url
EE::SUBSCRIPTIONS_MORE_STORAGE_URL
end
......
- page_title s_("UsageQuota|Usage")
- url_to_purchase_storage = purchase_storage_url if can_purchase_storage?
%h3.page-title
= s_('UsageQuota|Usage Quotas')
......@@ -20,5 +21,5 @@
= render "namespaces/pipelines_quota/list",
locals: { namespace: @group, projects: @projects }
.tab-pane#storage-quota-tab
#js-storage-counter-app{ data: { namespace_path: @group.full_path, help_page_path: help_page_path('user/group/index.md', anchor: 'storage-usage-quota'), purchase_storage_url: purchase_storage_url, is_temporary_storage_increase_visible: temporary_storage_increase_visible?(@group).to_s } }
#js-storage-counter-app{ data: { namespace_path: @group.full_path, help_page_path: help_page_path('user/group/index.md', anchor: 'storage-usage-quota'), purchase_storage_url: url_to_purchase_storage, is_temporary_storage_increase_visible: temporary_storage_increase_visible?(@group).to_s } }
- page_title s_("UsageQuota|Usage")
- @content_class = "limit-container-width" unless fluid_layout
- url_to_purchase_storage = purchase_storage_url if can_purchase_storage?
%h3.page-title
= s_('UsageQuota|Usage Quotas')
......@@ -21,4 +22,4 @@
= render "namespaces/pipelines_quota/list",
locals: { namespace: @namespace, projects: @projects }
.tab-pane#storage-quota-tab
#js-storage-counter-app{ data: { namespace_path: @namespace.full_path, help_page_path: help_page_path('user/group/index.md', anchor: 'storage-usage-quota'), purchase_storage_url: purchase_storage_url, is_temporary_storage_increase_visible: temporary_storage_increase_visible?(@namespace).to_s } }
#js-storage-counter-app{ data: { namespace_path: @namespace.full_path, help_page_path: help_page_path('user/group/index.md', anchor: 'storage-usage-quota'), purchase_storage_url: url_to_purchase_storage, is_temporary_storage_increase_visible: temporary_storage_increase_visible?(@namespace).to_s } }
......@@ -12,10 +12,9 @@
- style = namespace_storage_alert_style(alert_level)
- icon = namespace_storage_alert_icon(alert_level)
- purchase_link = namespace_storage_purchase_link(root_namespace)
- show_purchase_link = purchase_link && alert_level == :error
- purchase_link = purchase_storage_url if can_purchase_storage_for_namespace?(namespace) && alert_level == :error
- usage_link = namespace_storage_usage_link(root_namespace)
- show_storage_banner_actions = show_purchase_link || usage_link
- show_storage_banner_actions = purchase_link || usage_link
.gl-py-5
.gl-alert.js-namespace-storage-alert{ class: "gl-alert-#{style}", role: 'alert' }
......@@ -29,7 +28,7 @@
= payload[:explanation_message]
- if show_storage_banner_actions
.gl-alert-actions
- if show_purchase_link
- if purchase_link
= link_to(_('Purchase more storage'), purchase_link, class: "btn gl-alert-action btn-md gl-button btn-success")
- if usage_link
= link_to(_('Manage storage usage'), usage_link, class: "btn gl-alert-action btn-md gl-button btn-#{style}")
......@@ -32,18 +32,18 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
end
end
describe '#purchase_storage_url' do
subject { helper.purchase_storage_url }
describe '#can_purchase_storage?' do
subject { helper.can_purchase_storage? }
where(:is_dot_com, :enforcement_setting_enabled, :feature_enabled, :result) do
false | false | false | nil
false | false | true | nil
false | true | false | nil
true | false | false | nil
false | true | true | nil
true | true | false | nil
true | false | true | nil
true | true | true | EE::SUBSCRIPTIONS_MORE_STORAGE_URL
false | false | false | false
false | false | true | false
false | true | false | false
true | false | false | false
false | true | true | false
true | true | false | false
true | false | true | false
true | true | true | true
end
with_them do
......@@ -57,6 +57,12 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
end
end
describe '#purchase_storage_url' do
subject { helper.purchase_storage_url }
it { is_expected.to eq(EE::SUBSCRIPTIONS_MORE_STORAGE_URL) }
end
describe '#namespace_storage_alert' do
subject { helper.namespace_storage_alert(namespace) }
......@@ -157,28 +163,28 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
end
end
describe '#namespace_storage_purchase_link' do
subject { helper.namespace_storage_purchase_link(namespace) }
describe '#can_purchase_storage_for_namespace?' do
subject { helper.can_purchase_storage_for_namespace?(namespace) }
let(:namespace) { build(:namespace) }
where(:is_dev_or_com, :auto_storage_allocation_enabled, :buy_storage_link_enabled, :additional_storage_enabled, :result) do
true | true | true | true | EE::SUBSCRIPTIONS_MORE_STORAGE_URL
true | true | true | false | nil
true | true | false | true | nil
true | true | false | false | nil
true | false | true | true | nil
true | false | true | false | nil
true | false | false | true | nil
true | false | false | false | nil
false | true | true | true | nil
false | true | true | false | nil
false | true | false | true | nil
false | true | false | false | nil
false | false | true | true | nil
false | false | true | false | nil
false | false | false | true | nil
false | false | false | false | nil
true | true | true | true | true
true | true | true | false | false
true | true | false | true | false
true | true | false | false | false
true | false | true | true | false
true | false | true | false | false
true | false | false | true | false
true | false | false | false | false
false | true | true | true | false
false | true | true | false | false
false | true | false | true | false
false | true | false | false | false
false | false | true | true | false
false | false | true | false | false
false | false | false | true | false
false | false | false | false | false
end
with_them do
......
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