Commit 8ad1598f authored by Dylan Griffith's avatar Dylan Griffith

EE Part: Get GITLAB_FEATURES from Project#licensed_features instead of Namespace#features (#5320)

parent 597b0a70
......@@ -64,15 +64,6 @@ module EE
succeeded
end
override :features
def features
return super unless License.current
License.current.features.select do |feature|
License.global_feature?(feature) || feature_available?(feature)
end
end
# Checks features (i.e. https://about.gitlab.com/products/) availabily
# for a given Namespace plan. This method should consider ancestor groups
# being licensed.
......
......@@ -495,6 +495,15 @@ module EE
.external_authorization_service_default_label
end
override :licensed_features
def licensed_features
return super unless License.current
License.current.features.select do |feature|
License.global_feature?(feature) || licensed_feature_available?(feature)
end
end
private
def set_override_pull_mirror_available
......
......@@ -122,76 +122,6 @@ describe Namespace do
end
end
describe '#features' do
let(:plan_license) { :free_plan }
let(:group) { create(:group, plan: plan_license) }
let(:global_license) { create(:license) }
before do
allow(License).to receive(:current).and_return(global_license)
allow(global_license).to receive(:features).and_return([
:epics, # Gold only
:service_desk, # Silver and up
:audit_events, # Bronze and up
:geo, # Global feature, should not be checked at namespace level
])
end
subject { group.features }
context 'when the namespace should be checked' do
before do
enable_namespace_license_check!
end
context 'when bronze' do
let(:plan_license) { :bronze_plan }
it 'filters for bronze features' do
is_expected.to contain_exactly(:audit_events, :geo)
end
end
context 'when silver' do
let(:plan_license) { :silver_plan }
it 'filters for silver features' do
is_expected.to contain_exactly(:service_desk, :audit_events, :geo)
end
end
context 'when gold' do
let(:plan_license) { :gold_plan }
it 'filters for gold features' do
is_expected.to contain_exactly(:epics, :service_desk, :audit_events, :geo)
end
end
context 'when free plan' do
let(:plan_license) { :free_plan }
it 'filters out paid features' do
is_expected.to contain_exactly(:geo)
end
end
end
context 'when namespace should not be checked' do
it 'includes all features in global license' do
is_expected.to contain_exactly(:epics, :service_desk, :audit_events, :geo)
end
end
context 'when there is no license' do
before do
allow(License).to receive(:current).and_return(nil)
end
it { is_expected.to be_empty }
end
end
describe '#feature_available?' do
let(:plan_license) { :bronze_plan }
let(:group) { create(:group, plan: plan_license) }
......
......@@ -1364,4 +1364,84 @@ describe Project do
end
end
end
describe '#licensed_features' do
let(:plan_license) { :free_plan }
let(:global_license) { create(:license) }
let(:group) { create(:group, plan: plan_license) }
let(:project) { create(:project, group: group) }
before do
allow(License).to receive(:current).and_return(global_license)
allow(global_license).to receive(:features).and_return([
:epics, # Gold only
:service_desk, # Silver and up
:audit_events, # Bronze and up
:geo, # Global feature, should not be checked at namespace level
])
end
subject { project.licensed_features }
context 'when the namespace should be checked' do
before do
enable_namespace_license_check!
end
context 'when bronze' do
let(:plan_license) { :bronze_plan }
it 'filters for bronze features' do
is_expected.to contain_exactly(:audit_events, :geo)
end
end
context 'when silver' do
let(:plan_license) { :silver_plan }
it 'filters for silver features' do
is_expected.to contain_exactly(:service_desk, :audit_events, :geo)
end
end
context 'when gold' do
let(:plan_license) { :gold_plan }
it 'filters for gold features' do
is_expected.to contain_exactly(:epics, :service_desk, :audit_events, :geo)
end
end
context 'when free plan' do
let(:plan_license) { :free_plan }
it 'filters out paid features' do
is_expected.to contain_exactly(:geo)
end
context 'when public project and namespace' do
let(:group) { create(:group, :public, plan: plan_license) }
let(:project) { create(:project, :public, group: group) }
it 'includes all features in global license' do
is_expected.to contain_exactly(:epics, :service_desk, :audit_events, :geo)
end
end
end
end
context 'when namespace should not be checked' do
it 'includes all features in global license' do
is_expected.to contain_exactly(:epics, :service_desk, :audit_events, :geo)
end
end
context 'when there is no license' do
before do
allow(License).to receive(:current).and_return(nil)
end
it { is_expected.to be_empty }
end
end
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