summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2018-09-21 15:43:24 -0500
committerRobert Speicher <rspeicher@gmail.com>2018-09-21 15:43:24 -0500
commit44f6e171e8fa4785bf1790e09871809480da22fb (patch)
tree9a90c573a8728839f4e8f0be970f123251b2a202
parenta9aa98a23a7f52b4c0dbe48793ac3ed0b1f6d609 (diff)
downloadgitlab-ce-rs-feature-enabled-and-licensed.tar.gz
Add ProjectFeature check for feature flagrs-feature-enabled-and-licensed
This will allow an explicitly-disabled feature flag to override a feature being available for a project. As an extreme example, we could quickly disable issues across all projects at runtime by running `Feature.disable(:issues)`.
-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 d74cb2506ba..346db2847d8 100644
--- a/app/models/project_feature.rb
+++ b/app/models/project_feature.rb
@@ -59,6 +59,9 @@ class ProjectFeature < ActiveRecord::Base
after_update :update_site_statistics
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 10617edec0f..6311a9fd756 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