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