Commit bd861eb0 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'bvl-global-cicd-projects' into 'master'

Make `ci_cd_projects` globally available for .com

Closes #5283

See merge request gitlab-org/gitlab-ee!5036
parents 2cf80648 58545de8
......@@ -87,6 +87,8 @@ module EE
end
def feature_available_in_plan?(feature)
return true if ::License::ANY_PLAN_FEATURES.include?(feature)
available_features = strong_memoize(:features_available_in_plan) do
Hash.new do |h, feature|
h[feature] = (plans.map(&:name) & self.class.plans_with_feature(feature)).any?
......
......@@ -124,6 +124,13 @@ class License < ActiveRecord::Base
'GitLab_ServiceDesk' => :service_desk
}.freeze
# Features added here are available for all namespaces.
ANY_PLAN_FEATURES = %i[
ci_cd_projects
repository_mirrors
github_project_service_integration
].freeze
# Global features that cannot be restricted to only a subset of projects or namespaces.
# Use `License.feature_available?(:feature)` to check if these features are available.
# For all other features, use `project.feature_available?` or `namespace.feature_available?` when possible.
......
......@@ -195,12 +195,13 @@ describe Namespace do
describe '#feature_available?' do
let(:plan_license) { :bronze_plan }
let(:group) { create(:group, plan: plan_license) }
let(:feature) { :service_desk }
let(:licensed_feature) { :service_desk }
let(:feature) { licensed_feature }
subject { group.feature_available?(feature) }
before do
stub_licensed_features(feature => true)
stub_licensed_features(licensed_feature => true)
end
it 'uses the global setting when running on premise' do
......@@ -253,6 +254,25 @@ describe Namespace do
end
end
end
context 'when the feature is temporarily available on the entire instance' do
let(:license_plan) { :free_plan }
let(:feature) { :ci_cd_projects }
before do
stub_application_setting_on_object(group, should_check_namespace_plan: true)
end
it 'returns true when the feature is available globally' do
stub_licensed_features(feature => true)
is_expected.to be_truthy
end
it 'returns `false` when the feature is not included in the global license' do
is_expected.to be_falsy
end
end
end
describe '#max_active_pipelines' do
......
......@@ -1096,6 +1096,8 @@ describe Project do
shared_examples 'project with disabled services' do
it 'has some disabled services' do
stub_const('License::ANY_PLAN_FEATURES', [])
expect(project.disabled_services).to match_array(disabled_services)
end
end
......
......@@ -115,6 +115,7 @@ describe Projects::CreateService, '#execute' do
context 'with checks on the namespace' do
before do
stub_const('License::ANY_PLAN_FEATURES', [])
enable_namespace_license_check!
end
......
......@@ -74,6 +74,7 @@ describe UpdateAllMirrorsWorker do
stub_licensed_features(repository_mirrors: true)
stub_application_setting(check_namespace_plan: true)
allow(Gitlab).to receive_messages(com?: true)
stub_const('License::ANY_PLAN_FEATURES', [])
end
let!(:unlicensed_project1) { scheduled_mirror(at: 8.weeks.ago, licensed: false) }
......
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