summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2018-10-05 08:32:00 +0000
committerDouwe Maan <douwe@gitlab.com>2018-10-05 08:32:00 +0000
commit81641e592a954e98c29d862148c1104b87f30745 (patch)
treefde24d3129395e8198b6a0f92f17e8cf45175438
parent1e9003f4a42fa75b25045701fec5e9aa32cae71a (diff)
parent939467885851eb0f3fc5bcbaab6cb585bb85710d (diff)
downloadgitlab-ce-81641e592a954e98c29d862148c1104b87f30745.tar.gz
Merge branch 'rs-feature-enabled-and-licensed' into 'master'
Add `Feature.enabled_and_licensed?` See merge request gitlab-org/gitlab-ce!21687
-rw-r--r--app/models/project_feature.rb3
-rw-r--r--spec/models/project_feature_spec.rb16
2 files changed, 19 insertions, 0 deletions
diff --git a/app/models/project_feature.rb b/app/models/project_feature.rb
index 4a0324e8b5c..754c2461d23 100644
--- a/app/models/project_feature.rb
+++ b/app/models/project_feature.rb
@@ -55,6 +55,9 @@ class ProjectFeature < ActiveRecord::Base
default_value_for :repository_access_level, value: ENABLED, allows_nil: false
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))
end
diff --git a/spec/models/project_feature_spec.rb b/spec/models/project_feature_spec.rb
index cd7f77024da..2a193864e46 100644
--- a/spec/models/project_feature_spec.rb
+++ b/spec/models/project_feature_spec.rb
@@ -73,6 +73,22 @@ describe ProjectFeature do
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
context 'repository related features' do