Commit 254ee988 authored by Douwe Maan's avatar Douwe Maan Committed by Filipa Lacerda
Browse files

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
parent 2ac2a07a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -87,6 +87,8 @@ def feature_available?(feature)
    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?
+7 −0
Original line number Diff line number Diff line
@@ -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.
+22 −2
Original line number Diff line number Diff line
@@ -195,12 +195,13 @@
  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 @@
        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
+2 −0
Original line number Diff line number Diff line
@@ -1096,6 +1096,8 @@

  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
+1 −0
Original line number Diff line number Diff line
@@ -115,6 +115,7 @@

      context 'with checks on the namespace' do
        before do
          stub_const('License::ANY_PLAN_FEATURES', [])
          enable_namespace_license_check!
        end

Loading