debian-mirror-gitlab/app/helpers/storage_helper.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
3.6 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
module StorageHelper
def storage_counter(size_in_bytes)
2019-09-04 21:01:54 +05:30
return s_('StorageSize|Unknown') unless size_in_bytes
2017-08-17 22:00:37 +05:30
precision = size_in_bytes < 1.megabyte ? 0 : 1
number_to_human_size(size_in_bytes, delimiter: ',', precision: precision, significant: false)
end
2019-07-31 22:56:46 +05:30
def storage_counters_details(statistics)
counters = {
counter_repositories: storage_counter(statistics.repository_size),
2019-09-04 21:01:54 +05:30
counter_wikis: storage_counter(statistics.wiki_size),
2019-07-31 22:56:46 +05:30
counter_build_artifacts: storage_counter(statistics.build_artifacts_size),
2021-12-11 22:18:48 +05:30
counter_pipeline_artifacts: storage_counter(statistics.pipeline_artifacts_size),
2020-07-28 23:09:34 +05:30
counter_lfs_objects: storage_counter(statistics.lfs_objects_size),
2021-02-22 17:27:13 +05:30
counter_snippets: storage_counter(statistics.snippets_size),
counter_packages: storage_counter(statistics.packages_size),
counter_uploads: storage_counter(statistics.uploads_size)
2019-07-31 22:56:46 +05:30
}
2021-12-11 22:18:48 +05:30
_("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
2019-07-31 22:56:46 +05:30
end
2022-04-04 11:22:00 +05:30
def storage_enforcement_banner_info(namespace)
2022-05-07 20:08:51 +05:30
return unless can?(current_user, :admin_namespace, namespace)
2022-04-04 11:22:00 +05:30
return if namespace.paid?
return unless namespace.storage_enforcement_date && namespace.storage_enforcement_date >= Date.today
return if user_dismissed_storage_enforcement_banner?(namespace)
{
text: html_escape_once(s_("UsageQuota|From %{storage_enforcement_date} storage limits will apply to this namespace. " \
2022-07-16 23:28:13 +05:30
"You are currently using %{used_storage} of namespace storage. " \
"View and manage your usage from %{strong_start}%{namespace_type} settings &gt; Usage quotas%{strong_end}.")).html_safe %
{ storage_enforcement_date: namespace.storage_enforcement_date, used_storage: storage_counter(namespace.root_storage_statistics&.storage_size || 0), strong_start: "<strong>".html_safe, strong_end: "</strong>".html_safe, namespace_type: namespace.type },
2022-04-04 11:22:00 +05:30
variant: 'warning',
2022-05-07 20:08:51 +05:30
callouts_path: namespace.user_namespace? ? callouts_path : group_callouts_path,
2022-04-04 11:22:00 +05:30
callouts_feature_name: storage_enforcement_banner_user_callouts_feature_name(namespace),
learn_more_link: link_to(_('Learn more.'), help_page_path('/'), rel: 'noopener noreferrer', target: '_blank') # TBD: https://gitlab.com/gitlab-org/gitlab/-/issues/350632
}
end
private
def storage_enforcement_banner_user_callouts_feature_name(namespace)
"storage_enforcement_banner_#{storage_enforcement_banner_threshold(namespace)}_enforcement_threshold"
end
def storage_enforcement_banner_threshold(namespace)
days_to_enforcement_date = (namespace.storage_enforcement_date - Date.today)
return :first if days_to_enforcement_date > 30
return :second if days_to_enforcement_date > 15 && days_to_enforcement_date <= 30
return :third if days_to_enforcement_date > 7 && days_to_enforcement_date <= 15
2022-05-07 20:08:51 +05:30
return :fourth if days_to_enforcement_date >= 0 && days_to_enforcement_date <= 7
2022-04-04 11:22:00 +05:30
end
def user_dismissed_storage_enforcement_banner?(namespace)
return false unless current_user
2022-05-07 20:08:51 +05:30
if namespace.user_namespace?
current_user.dismissed_callout?(feature_name: storage_enforcement_banner_user_callouts_feature_name(namespace))
else
current_user.dismissed_callout_for_group?(feature_name: storage_enforcement_banner_user_callouts_feature_name(namespace),
group: namespace)
end
2022-04-04 11:22:00 +05:30
end
2017-08-17 22:00:37 +05:30
end