diff options
Diffstat (limited to 'app/helpers/storage_helper.rb')
-rw-r--r-- | app/helpers/storage_helper.rb | 86 |
1 files changed, 73 insertions, 13 deletions
diff --git a/app/helpers/storage_helper.rb b/app/helpers/storage_helper.rb index ca81d5af4af..9e516d726c1 100644 --- a/app/helpers/storage_helper.rb +++ b/app/helpers/storage_helper.rb @@ -24,29 +24,89 @@ module StorageHelper _("Repository: %{counter_repositories} / Wikis: %{counter_wikis} / Build Artifacts: %{counter_build_artifacts} / Pipeline Artifacts: %{counter_pipeline_artifacts} / LFS: %{counter_lfs_objects} / Snippets: %{counter_snippets} / Packages: %{counter_packages} / Uploads: %{counter_uploads}") % counters end - def storage_enforcement_banner_info(namespace) - root_ancestor = namespace.root_ancestor + def storage_enforcement_banner_info(context) + root_ancestor = context.root_ancestor - return unless can?(current_user, :maintain_namespace, root_ancestor) - return if root_ancestor.paid? - return unless future_enforcement_date?(root_ancestor) - return if user_dismissed_storage_enforcement_banner?(root_ancestor) - return unless ::Feature.enabled?(:namespace_storage_limit_show_preenforcement_banner, root_ancestor) + return unless should_show_storage_enforcement_banner?(context, current_user, root_ancestor) + + text_args = storage_enforcement_banner_text_args(root_ancestor, context) + + text_paragraph_2 = if root_ancestor.user_namespace? + html_escape_once(s_("UsageQuota|The namespace is currently using %{strong_start}%{used_storage}%{strong_end} of namespace storage. " \ + "View and manage your usage from %{strong_start}User settings > Usage quotas%{strong_end}. %{docs_link_start}Learn more%{link_end} " \ + "about how to reduce your storage.")).html_safe % text_args[:p2] + else + html_escape_once(s_("UsageQuota|The namespace is currently using %{strong_start}%{used_storage}%{strong_end} of namespace storage. " \ + "Group owners can view namespace storage usage and purchase more from %{strong_start}Group settings > Usage quotas%{strong_end}. %{docs_link_start}Learn more.%{link_end}" \ + )).html_safe % text_args[:p2] + end { - text: html_escape_once(s_("UsageQuota|From %{storage_enforcement_date} storage limits will apply to this namespace. " \ - "You are currently using %{used_storage} of namespace storage. " \ - "View and manage your usage from %{strong_start}%{namespace_type} settings > Usage quotas%{strong_end}.")).html_safe % - { storage_enforcement_date: root_ancestor.storage_enforcement_date, used_storage: storage_counter(root_ancestor.root_storage_statistics&.storage_size || 0), strong_start: "<strong>".html_safe, strong_end: "</strong>".html_safe, namespace_type: root_ancestor.type }, + text_paragraph_1: html_escape_once(s_("UsageQuota|Effective %{storage_enforcement_date}, namespace storage limits will apply " \ + "to the %{strong_start}%{namespace_name}%{strong_end} namespace. %{extra_message}" \ + "View the %{rollout_link_start}rollout schedule for this change%{link_end}.")).html_safe % text_args[:p1], + text_paragraph_2: text_paragraph_2, + text_paragraph_3: html_escape_once(s_("UsageQuota|See our %{faq_link_start}FAQ%{link_end} for more information.")).html_safe % text_args[:p3], variant: 'warning', + namespace_id: root_ancestor.id, callouts_path: root_ancestor.user_namespace? ? callouts_path : group_callouts_path, - callouts_feature_name: storage_enforcement_banner_user_callouts_feature_name(root_ancestor), - learn_more_link: link_to(_('Learn more.'), help_page_path('/'), rel: 'noopener noreferrer', target: '_blank') + callouts_feature_name: storage_enforcement_banner_user_callouts_feature_name(root_ancestor) } end private + def should_show_storage_enforcement_banner?(context, current_user, root_ancestor) + return false unless user_allowed_storage_enforcement_banner?(context, current_user, root_ancestor) + return false if root_ancestor.paid? + return false unless future_enforcement_date?(root_ancestor) + return false if user_dismissed_storage_enforcement_banner?(root_ancestor) + + ::Feature.enabled?(:namespace_storage_limit_show_preenforcement_banner, root_ancestor) + end + + def user_allowed_storage_enforcement_banner?(context, current_user, root_ancestor) + return can?(current_user, :maintainer_access, context) unless context.respond_to?(:user_namespace?) && context.user_namespace? + + can?(current_user, :owner_access, context) + end + + def storage_enforcement_banner_text_args(root_ancestor, context) + strong_tags = { + strong_start: "<strong>".html_safe, + strong_end: "</strong>".html_safe + } + + extra_message = if context.is_a?(Project) + html_escape_once(s_("UsageQuota|The %{strong_start}%{context_name}%{strong_end} project will be affected by this. ")) + .html_safe % strong_tags.merge(context_name: context.name) + elsif !context.root? + html_escape_once(s_("UsageQuota|The %{strong_start}%{context_name}%{strong_end} group will be affected by this. ")) + .html_safe % strong_tags.merge(context_name: context.name) + else + '' + end + + { + p1: { + storage_enforcement_date: root_ancestor.storage_enforcement_date, + namespace_name: root_ancestor.name, + extra_message: extra_message, + rollout_link_start: '<a href="%{url}" >'.html_safe % { url: help_page_path('user/usage_quotas', anchor: 'namespace-storage-limit-enforcement-schedule') }, + link_end: "</a>".html_safe + }.merge(strong_tags), + p2: { + used_storage: storage_counter(root_ancestor.root_storage_statistics&.storage_size || 0), + docs_link_start: '<a href="%{url}" >'.html_safe % { url: help_page_path('user/usage_quotas', anchor: 'manage-your-storage-usage') }, + link_end: "</a>".html_safe + }.merge(strong_tags), + p3: { + faq_link_start: '<a href="%{url}" >'.html_safe % { url: "#{Gitlab::Saas.about_pricing_url}faq-efficient-free-tier/#storage-limits-on-gitlab-saas-free-tier" }, + link_end: "</a>".html_safe + } + } + end + def storage_enforcement_banner_user_callouts_feature_name(namespace) "storage_enforcement_banner_#{storage_enforcement_banner_threshold(namespace)}_enforcement_threshold" end |