Merge branch 'rs-feature-enabled-and-licensed' into 'master'
Add `Feature.enabled_and_licensed?` See merge request gitlab-org/gitlab-ce!21687
This commit is contained in:
commit
81641e592a
2 changed files with 19 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue