Commit 3b7d0e5b authored by Ragnar Hardarson's avatar Ragnar Hardarson Committed by Mark Chao

Ensure no duplicate storage alert on usaga quota page

Since there is an inline alert on the usage quota page,
it is overwhelming if the global storage alert
is also rendered on this page.
parent 1173347f
......@@ -9,8 +9,8 @@ module EE
@display_namespace_storage_limit_alert = true
end
def display_namespace_storage_limit_alert?
@display_namespace_storage_limit_alert
def display_namespace_storage_limit_alert?(namespace)
@display_namespace_storage_limit_alert && !usage_quota_page?(namespace)
end
def namespace_storage_alert(namespace)
......@@ -73,6 +73,10 @@ module EE
private
def usage_quota_page?(namespace)
current_page?(group_usage_quotas_path(namespace)) || current_page?(profile_usage_quotas_path)
end
def check_storage_size_service(namespace)
if namespace.additional_repo_storage_by_namespace_enabled?
::Namespaces::CheckExcessStorageSizeService.new(namespace, current_user)
......
- return unless current_user
- return unless display_namespace_storage_limit_alert?
- namespace = @project&.namespace || @group
- return unless namespace.present?
- return unless display_namespace_storage_limit_alert?(namespace)
- payload = namespace_storage_alert(namespace)
- return if payload.empty?
......
......@@ -16,6 +16,46 @@ RSpec.describe EE::NamespaceStorageLimitAlertHelper do
end
end
describe '#display_namespace_storage_limit_alert?' do
let_it_be(:namespace) { build_stubbed(:namespace) }
before do
assign(:display_namespace_storage_limit_alert, display_namespace_storage_limit_alert)
end
context 'when display_namespace_storage_limit_alert is true' do
let(:display_namespace_storage_limit_alert) { true }
it 'returns false when in profile usage quota path' do
allow(@request).to receive(:path) { profile_usage_quotas_path }
expect(helper.display_namespace_storage_limit_alert?(namespace)).to eq(false)
end
it 'returns false when in namespace usage quota path' do
allow(@request).to receive(:path) { group_usage_quotas_path(namespace) }
expect(helper.display_namespace_storage_limit_alert?(namespace)).to eq(false)
end
it 'returns true when in other namespace path' do
allow(@request).to receive(:path) { group_path(namespace) }
expect(helper.display_namespace_storage_limit_alert?(namespace)).to eq(true)
end
end
context 'when display_namespace_storage_limit_alert is false' do
let(:display_namespace_storage_limit_alert) { false }
it 'returns false' do
allow(@request).to receive(:path) { group_path(namespace) }
expect(helper.display_namespace_storage_limit_alert?(namespace)).to eq(false)
end
end
end
describe '#namespace_storage_usage_link' do
subject { helper.namespace_storage_usage_link(namespace) }
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'view usage quotas' do
describe 'GET /groups/:group/-/usage_quotas' do
let_it_be(:group) { create(:group) }
let_it_be(:user) { create(:user) }
before_all do
group.add_owner(user)
end
before do
login_as(user)
end
context 'when storage size is over limit' do
let(:usage_message) { FFaker::Lorem.sentence }
before do
allow_next_instance_of(Namespaces::CheckStorageSizeService) do |service|
allow(service).to receive(:execute).and_return(
ServiceResponse.success(
payload: {
alert_level: :info,
usage_message: usage_message,
explanation_message: "Explanation",
root_namespace: group
}
)
)
end
end
it 'does not display storage alert' do
send_request
expect(response).to have_gitlab_http_status(:ok)
expect(response.body).not_to include(usage_message)
end
end
def send_request
get group_usage_quotas_path(group)
end
end
end
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