Commit ca43579b authored by Bob Van Landuyt's avatar Bob Van Landuyt Committed by Bob Van Landuyt

Check the global availability inside `Namespace#feature_available?`

parent 3461e5c1
......@@ -33,11 +33,13 @@ module EE
# for a given Namespace plan. This method should consider ancestor groups
# being licensed.
def feature_available?(feature)
@features_available ||= Hash.new do |h, feature|
h[feature] = plans.any? { |plan| License.plan_includes_feature?(EE_PLANS[plan], feature) }
end
globally_available = License.feature_available?(feature)
@features_available[feature]
if current_application_settings.should_check_namespace_plan?
globally_available && feature_available_in_plan?(feature)
else
globally_available
end
end
def actual_shared_runners_minutes_limit
......@@ -65,5 +67,13 @@ module EE
[plan]
end
end
def feature_available_in_plan?(feature)
@features_available_in_plan ||= Hash.new do |h, feature|
h[feature] = plans.any? { |plan| License.plan_includes_feature?(EE_PLANS[plan], feature) }
end
@features_available_in_plan[feature]
end
end
end
......@@ -43,37 +43,58 @@ describe Namespace, models: true do
end
describe '#feature_available?' do
let(:plan_license) { Namespace::BRONZE_PLAN }
let(:group) { create(:group, plan: plan_license) }
let(:feature) { :service_desk }
subject { group.feature_available?(feature) }
context 'when feature available' do
let(:feature) { :deploy_board }
let(:plan_license) { Namespace::GOLD_PLAN }
before do
stub_licensed_features(feature => true)
end
context 'when feature available for current group' do
it 'returns false' do
is_expected.to eq(true)
end
it 'uses the global setting when running on premise' do
stub_application_setting_on_object(group, should_check_namespace_plan: false)
is_expected.to be_truthy
end
context 'when checking namespace plan' do
before do
stub_application_setting_on_object(group, should_check_namespace_plan: true)
end
it 'combines the global setting with the group setting when not running on premise' do
is_expected.to be_falsy
end
if Group.supports_nested_groups?
context 'when license is applied to parent group' do
let(:child_group) { create :group, parent: group }
context 'when feature available on the plan' do
let(:plan_license) { Namespace::GOLD_PLAN }
context 'when feature available for current group' do
it 'returns true' do
is_expected.to be_truthy
end
end
if Group.supports_nested_groups?
context 'when license is applied to parent group' do
let(:child_group) { create :group, parent: group }
it 'child group has feature available' do
expect(child_group.feature_available?(feature)).to eq(true)
it 'child group has feature available' do
expect(child_group.feature_available?(feature)).to be_truthy
end
end
end
end
end
context 'when feature not available' do
let(:feature) { :deploy_board }
let(:plan_license) { Namespace::BRONZE_PLAN }
context 'when feature not available in the plan' do
let(:feature) { :deploy_board }
let(:plan_license) { Namespace::BRONZE_PLAN }
it 'returns false' do
is_expected.to eq(false)
it 'returns false' do
is_expected.to be_falsy
end
end
end
end
......
......@@ -22,7 +22,7 @@ describe Project, models: true do
before do
stub_application_setting('check_namespace_plan?' => check_namespace_plan)
allow(Gitlab).to receive(:com?) { true }
expect(License).to receive(:feature_available?).with(feature) { allowed_on_global_license }
stub_licensed_features(feature => allowed_on_global_license)
allow(namespace).to receive(:plan) { plan_license }
end
......
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