Loading ee/app/models/ee/namespace.rb +2 −0 Original line number Diff line number Diff line Loading @@ -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? Loading ee/app/models/license.rb +7 −0 Original line number Diff line number Diff line Loading @@ -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. Loading ee/spec/models/namespace_spec.rb +22 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading ee/spec/models/project_spec.rb +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading ee/spec/services/projects/create_service_spec.rb +1 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
ee/app/models/ee/namespace.rb +2 −0 Original line number Diff line number Diff line Loading @@ -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? Loading
ee/app/models/license.rb +7 −0 Original line number Diff line number Diff line Loading @@ -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. Loading
ee/spec/models/namespace_spec.rb +22 −2 Original line number Diff line number Diff line Loading @@ -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 Loading Loading @@ -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 Loading
ee/spec/models/project_spec.rb +2 −0 Original line number Diff line number Diff line Loading @@ -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 Loading
ee/spec/services/projects/create_service_spec.rb +1 −0 Original line number Diff line number Diff line Loading @@ -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