Commit 41ea3080 authored by Avielle Wolfe's avatar Avielle Wolfe

Keep shared runner UI after model change

Even though we are now counting minutes when shared runners are
disabled, we don't want to show that information in the UI, since it may
be confusing to users to see minutes being counted after they have
disabled shared runners. Avoiding changes to the UI involves re-adding a
check for Namespace#any_project_with_shared_runners_enabled? in some
places.
parent c1841246
...@@ -25,7 +25,7 @@ module Ci ...@@ -25,7 +25,7 @@ module Ci
end end
def monthly_percent_used def monthly_percent_used
return 0 unless enabled? return 0 unless enabled? && any_project_enabled?
return 0 if monthly_minutes == 0 return 0 if monthly_minutes == 0
100 * monthly_minutes_used.to_i / monthly_minutes 100 * monthly_minutes_used.to_i / monthly_minutes
...@@ -81,6 +81,12 @@ module Ci ...@@ -81,6 +81,12 @@ module Ci
private private
def any_project_enabled?
strong_memoize(:any_project_enabled) do
namespace.any_project_with_shared_runners_enabled?
end
end
# TODO: rename to `enabled?` # TODO: rename to `enabled?`
# https://gitlab.com/gitlab-org/gitlab/-/issues/332933 # https://gitlab.com/gitlab-org/gitlab/-/issues/332933
def limit_enabled? def limit_enabled?
...@@ -90,9 +96,9 @@ module Ci ...@@ -90,9 +96,9 @@ module Ci
end end
def minutes_limit def minutes_limit
return monthly_minutes if enabled? return monthly_minutes if enabled? && any_project_enabled?
if namespace_eligible? if namespace_eligible? && any_project_enabled?
_('Unlimited') _('Unlimited')
else else
_('Not supported') _('Not supported')
......
- namespace = local_assigns.fetch(:namespace) - namespace = local_assigns.fetch(:namespace)
- minutes_quota = namespace.ci_minutes_quota - minutes_quota = namespace.ci_minutes_quota
- if minutes_quota.namespace_eligible? - if namespace.any_project_with_shared_runners_enabled?
%li %li
%span.light= _('Pipeline minutes quota:') %span.light= _('Pipeline minutes quota:')
%strong %strong
......
...@@ -63,6 +63,7 @@ RSpec.describe EE::NamespacesHelper do ...@@ -63,6 +63,7 @@ RSpec.describe EE::NamespacesHelper do
context 'and the namespace is eligible for unlimited' do context 'and the namespace is eligible for unlimited' do
before do before do
allow(quota).to receive(:namespace_eligible?).and_return(true) allow(quota).to receive(:namespace_eligible?).and_return(true)
allow(user_group).to receive(:any_project_with_shared_runners_enabled?).and_return(true)
end end
it 'returns Unlimited for the limit section' do it 'returns Unlimited for the limit section' do
......
...@@ -68,6 +68,7 @@ RSpec.describe Ci::Minutes::Quota do ...@@ -68,6 +68,7 @@ RSpec.describe Ci::Minutes::Quota do
before do before do
allow(quota).to receive(:enabled?).and_return(false) allow(quota).to receive(:enabled?).and_return(false)
allow(quota).to receive(:namespace_eligible?).and_return(namespace_eligible) allow(quota).to receive(:namespace_eligible?).and_return(namespace_eligible)
allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true)
end end
context 'when the namespace is not eligible' do context 'when the namespace is not eligible' do
...@@ -114,6 +115,7 @@ RSpec.describe Ci::Minutes::Quota do ...@@ -114,6 +115,7 @@ RSpec.describe Ci::Minutes::Quota do
context 'when limited' do context 'when limited' do
before do before do
allow(quota).to receive(:enabled?).and_return(true) allow(quota).to receive(:enabled?).and_return(true)
allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true)
namespace.shared_runners_minutes_limit = 100 namespace.shared_runners_minutes_limit = 100
end end
...@@ -257,6 +259,7 @@ RSpec.describe Ci::Minutes::Quota do ...@@ -257,6 +259,7 @@ RSpec.describe Ci::Minutes::Quota do
with_them do with_them do
before do before do
allow(quota).to receive(:enabled?).and_return(limit_enabled) allow(quota).to receive(:enabled?).and_return(limit_enabled)
allow(namespace).to receive(:any_project_with_shared_runners_enabled?).and_return(true)
namespace.shared_runners_minutes_limit = monthly_limit namespace.shared_runners_minutes_limit = monthly_limit
namespace.extra_shared_runners_minutes_limit = purchased_limit namespace.extra_shared_runners_minutes_limit = purchased_limit
namespace.namespace_statistics.shared_runners_seconds = minutes_used.minutes namespace.namespace_statistics.shared_runners_seconds = minutes_used.minutes
......
...@@ -202,7 +202,7 @@ RSpec.describe PipelineSerializer do ...@@ -202,7 +202,7 @@ RSpec.describe PipelineSerializer do
# Existing numbers are high and require performance optimization # Existing numbers are high and require performance optimization
# Ongoing issue: # Ongoing issue:
# https://gitlab.com/gitlab-org/gitlab/-/issues/225156 # https://gitlab.com/gitlab-org/gitlab/-/issues/225156
expected_queries = Gitlab.ee? ? 77 : 70 expected_queries = Gitlab.ee? ? 74 : 70
expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0) expect(recorded.cached_count).to eq(0)
......
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