Commit c81d2244 authored by Robert Speicher's avatar Robert Speicher

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)`.
parent 8160cfe7
...@@ -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
......
...@@ -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