From 44f6e171e8fa4785bf1790e09871809480da22fb Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Fri, 21 Sep 2018 15:43:24 -0500 Subject: Add ProjectFeature check for feature flag 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)`. --- app/models/project_feature.rb | 3 +++ spec/models/project_feature_spec.rb | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) 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 -- cgit v1.2.1