Commit c9672994 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-feature-enabled-and-licensed-ee' into 'master'

[EE] Add `Feature.enabled_and_licensed?`

See merge request gitlab-org/gitlab-ee!7788
parents 87dac3d3 4cc1c629
...@@ -61,6 +61,9 @@ class ProjectFeature < ActiveRecord::Base ...@@ -61,6 +61,9 @@ class ProjectFeature < ActiveRecord::Base
end end
def feature_available?(feature, user) def feature_available?(feature, user)
# This feature might not be behind a feature flag at all, so default to true
return false unless ::Feature.enabled?(feature, user, default_enabled: true)
get_permission(user, access_level(feature)) get_permission(user, access_level(feature))
end end
......
...@@ -72,6 +72,9 @@ module EE ...@@ -72,6 +72,9 @@ module EE
# for a given Namespace plan. This method should consider ancestor groups # for a given Namespace plan. This method should consider ancestor groups
# being licensed. # being licensed.
def feature_available?(feature) def feature_available?(feature)
# This feature might not be behind a feature flag at all, so default to true
return false unless ::Feature.enabled?(feature, default_enabled: true)
available_features = strong_memoize(:feature_available) do available_features = strong_memoize(:feature_available) do
Hash.new do |h, feature| Hash.new do |h, feature|
h[feature] = load_feature_available(feature) h[feature] = load_feature_available(feature)
......
...@@ -293,6 +293,9 @@ class License < ActiveRecord::Base ...@@ -293,6 +293,9 @@ class License < ActiveRecord::Base
def feature_available?(feature) def feature_available?(feature)
return false if trial? && expired? return false if trial? && expired?
# This feature might not be behind a feature flag at all, so default to true
return false unless ::Feature.enabled?(feature, default_enabled: true)
features.include?(feature) features.include?(feature)
end end
......
...@@ -569,6 +569,26 @@ describe License do ...@@ -569,6 +569,26 @@ describe License do
end end
end end
end end
context 'when feature is disabled by a feature flag' do
it 'returns false' do
feature = license.features.first
stub_feature_flags(feature => false)
expect(license.features).not_to receive(:include?)
expect(license.feature_available?(feature)).to eq(false)
end
end
context 'when feature is enabled by a feature flag' do
it 'returns true' do
feature = license.features.first
stub_feature_flags(feature => true)
expect(license.feature_available?(feature)).to eq(true)
end
end
end end
def build_license_with_add_ons(add_ons, plan: nil) def build_license_with_add_ons(add_ons, plan: nil)
......
...@@ -218,6 +218,22 @@ describe Namespace do ...@@ -218,6 +218,22 @@ describe Namespace do
is_expected.to be_falsy is_expected.to be_falsy
end end
end end
context 'when feature is disabled by a feature flag' do
it 'returns false' do
stub_feature_flags(feature => false)
is_expected.to eq(false)
end
end
context 'when feature is enabled by a feature flag' do
it 'returns true' do
stub_feature_flags(feature => true)
is_expected.to eq(true)
end
end
end end
describe '#max_active_pipelines' do describe '#max_active_pipelines' do
......
...@@ -82,6 +82,22 @@ describe ProjectFeature do ...@@ -82,6 +82,22 @@ describe ProjectFeature do
end end
end end
end end
context 'when feature is disabled by a feature flag' do
it 'returns false' do
stub_feature_flags(issues: false)
expect(project.feature_available?(:issues, user)).to eq(false)
end
end
context 'when feature is enabled by a feature flag' do
it 'returns true' do
stub_feature_flags(issues: true)
expect(project.feature_available?(:issues, user)).to eq(true)
end
end
end end
context 'repository related features' do context 'repository related features' do
......
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