Enable storage purchase link

What does this MR do?

Adds a link to EE::SUBSCRIPTIONS_MORE_STORAGE_URL for the big ol' green "Purchase more storage" button.

Since EE::SUBSCRIPTIONS_MORE_STORAGE_URL is optionally provided based on the buy_storage_link feature flag, we also conditionally render the UsageStatisticsCard containing the big ol' green button.

Note that in almost all cases the buy_storage_link feature flag will be on here.

  • No changelog as this is behind the disabled additional_repo_storage_by_namespace feature flag

Screenshots (strongly suggested)

buy_storage_link disabled buy_storage_link enabled
Screenshot_2020-10-27_at_16.40.52 Screenshot_2020-10-27_at_16.42.31

Testing this locally

Requires EE edition

Paste the following in your Rails console

# Match the 10GB limit on GitLab.com, enable application setting
ApplicationSettings::UpdateService.new(Gitlab::CurrentSettings.current_application_settings, nil, { repository_size_limit: 10240, enforce_namespace_storage_limit: true }).execute

Feature.enable(:additional_repo_storage_by_namespace)
Feature.enable(:buy_storage_link)

ACCESS_LEVEL_OWNER = 50
PACKAGE_SIZE_IN_MIB = 10240

def create_group_with_usage_and_additional_storage(owner, group_name, nr_of_packs_purchased, usage)
  group = Group.create(name: group_name, path: group_name, type: 'Group')
  GroupMember.add_user(group, owner, ACCESS_LEVEL_OWNER)
  project = ::Projects::CreateService.new(owner, { namespace_id: group.id, name: 'project-' + group_name, path: 'project-' + group_name }).execute

  group.additional_purchased_storage_size = nr_of_packs_purchased * PACKAGE_SIZE_IN_MIB
  group.save!

  project.statistics&.destroy!

  project_statistics = ProjectStatistics.new(
    project_id: project.id,
    namespace_id: group.id,
    commit_count: 12,
    repository_size: usage * 3 / 5,
    lfs_objects_size: usage * 2 / 5
  )

  project_statistics.save!
end

root_user = User.where(username: 'root').first

create_group_with_usage_and_additional_storage(root_user, 'over-free-limit', 0, 20.gigabytes)
create_group_with_usage_and_additional_storage(root_user, 'under-free-limit-no-purchase', 0, 8.gigabytes)
create_group_with_usage_and_additional_storage(root_user, 'over-purchased-limit', 1, 30.gigabytes)
create_group_with_usage_and_additional_storage(root_user, 'warning-with-purchase', 1, 17.gigabytes)
create_group_with_usage_and_additional_storage(root_user, 'under-free-limit-with-purchase', 1, 5.gigabytes)

Go to http://localhost:3000/groups/over-purchased-limit/-/usage_quotas#storage-quota-tab

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team
Edited by Ragnar Hardarson

Merge request reports

Loading