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