Commit 22f959a5 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by ayufanpl

Change feature flag to shared_runner_minutes_on_subnamespace and update code...

Change feature flag to shared_runner_minutes_on_subnamespace and update code to verify if shared_runner_minutes can be used
parent 33651e72
...@@ -500,8 +500,8 @@ class Project < ActiveRecord::Base ...@@ -500,8 +500,8 @@ class Project < ActiveRecord::Base
.base_and_ancestors(upto: top) .base_and_ancestors(upto: top)
end end
def top_level_ancestor def root_namespace
@top_level_ancestor ||= ancestors_upto.last @root_namespace ||= Gitlab::GroupHierarchy.new(Namespace.where(id: namespace_id)).roots.take
end end
def lfs_enabled? def lfs_enabled?
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
%td %td
.avatar-container.s20.hidden-xs .avatar-container.s20.hidden-xs
= project_icon(project, alt: '', class: 'avatar project-avatar s20') = project_icon(project, alt: '', class: 'avatar project-avatar s20')
%strong= link_to project.name, project %strong= link_to project.full_name, project
%td %td
= project.shared_runners_minutes = project.shared_runners_minutes
- if projects.blank? - if projects.blank?
......
class Groups::PipelineQuotaController < Groups::ApplicationController class Groups::PipelineQuotaController < Groups::ApplicationController
before_action :authorize_admin_group! before_action :authorize_admin_group!
before_action :validate_shared_runner_minutes_support!
layout 'group_settings' layout 'group_settings'
...@@ -10,10 +11,14 @@ class Groups::PipelineQuotaController < Groups::ApplicationController ...@@ -10,10 +11,14 @@ class Groups::PipelineQuotaController < Groups::ApplicationController
private private
def all_projects def all_projects
if Feature.enabled?(:account_on_namespace) if Feature.enabled?(:shared_runner_minutes_on_subnamespace)
@group.all_projects
else
@group.projects @group.projects
else
@group.all_projects
end end
end end
def validate_shared_runner_minutes_support!
render_404 unless @group.shared_runner_minutes_supported?
end
end end
...@@ -34,6 +34,7 @@ module EE ...@@ -34,6 +34,7 @@ module EE
to: :namespace_statistics, allow_nil: true to: :namespace_statistics, allow_nil: true
validate :validate_plan_name validate :validate_plan_name
validate :validate_shared_runner_minutes_support
end end
module ClassMethods module ClassMethods
...@@ -96,13 +97,22 @@ module EE ...@@ -96,13 +97,22 @@ module EE
actual_plan&.name || FREE_PLAN actual_plan&.name || FREE_PLAN
end end
def shared_runner_minutes_supported?
if parent_id
Feature.enabled?(:shared_runner_minutes_on_subnamespace)
else
true
end
end
def actual_shared_runners_minutes_limit def actual_shared_runners_minutes_limit
shared_runners_minutes_limit || shared_runners_minutes_limit ||
current_application_settings.shared_runners_minutes current_application_settings.shared_runners_minutes
end end
def shared_runners_minutes_limit_enabled? def shared_runners_minutes_limit_enabled?
shared_runners_enabled? && shared_runner_minutes_supported? &&
shared_runners_enabled? &&
actual_shared_runners_minutes_limit.nonzero? actual_shared_runners_minutes_limit.nonzero?
end end
...@@ -140,6 +150,14 @@ module EE ...@@ -140,6 +150,14 @@ module EE
end end
end end
def validate_shared_runner_minutes_support
return if shared_runner_minutes_supported?
if shared_runners_minutes_limit_changed?
errors.add(:shared_runners_minutes_limit, 'is not supported for this namespace')
end
end
def load_feature_available(feature) def load_feature_available(feature)
globally_available = License.feature_available?(feature) globally_available = License.feature_available?(feature)
......
...@@ -83,10 +83,10 @@ module EE ...@@ -83,10 +83,10 @@ module EE
end end
def shared_runners_limit_namespace def shared_runners_limit_namespace
if Feature.enabled?(:account_on_namespace) if Feature.enabled?(:shared_runner_minutes_on_subnamespace)
top_level_ancestor
else
namespace namespace
else
root_namespace
end end
end end
......
...@@ -26,13 +26,13 @@ module EE ...@@ -26,13 +26,13 @@ module EE
end end
def all_namespaces def all_namespaces
if Feature.enabled?(:account_on_namespace) namespaces = ::Namespace.reorder(nil).where('namespaces.id = projects.namespace_id')
::Gitlab::GroupHierarchy.new(::Namespace.where('namespaces.id = projects.namespace_id'))
.roots unless Feature.enabled?(:shared_runner_minutes_on_subnamespace)
else namespaces = ::Gitlab::GroupHierarchy.new(namespaces).roots
::Namespace.reorder(nil)
.where('namespaces.id = projects.namespace_id')
end end
namespaces
end end
def application_shared_runners_minutes def application_shared_runners_minutes
......
...@@ -22,10 +22,6 @@ class UpdateBuildMinutesService < BaseService ...@@ -22,10 +22,6 @@ class UpdateBuildMinutesService < BaseService
end end
def namespace def namespace
if Feature.enabled(:account_on_top_level) project.shared_runners_limit_namespace
project.namespace.top_level_parent
else
project.namespace
end
end 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