Commit 4df2d156 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch 'ee-5320-fix-gitlab-features-env-var' into 'master'

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

See merge request gitlab-org/gitlab-ee!5242
parents 7d869c8b dda678cb
...@@ -615,7 +615,7 @@ module Ci ...@@ -615,7 +615,7 @@ module Ci
Gitlab::Ci::Variables::Collection.new.tap do |variables| Gitlab::Ci::Variables::Collection.new.tap do |variables|
variables.append(key: 'CI', value: 'true') variables.append(key: 'CI', value: 'true')
variables.append(key: 'GITLAB_CI', value: 'true') variables.append(key: 'GITLAB_CI', value: 'true')
variables.append(key: 'GITLAB_FEATURES', value: project.namespace.features.join(',')) variables.append(key: 'GITLAB_FEATURES', value: project.licensed_features.join(','))
variables.append(key: 'CI_SERVER_NAME', value: 'GitLab') variables.append(key: 'CI_SERVER_NAME', value: 'GitLab')
variables.append(key: 'CI_SERVER_VERSION', value: Gitlab::VERSION) variables.append(key: 'CI_SERVER_VERSION', value: Gitlab::VERSION)
variables.append(key: 'CI_SERVER_REVISION', value: Gitlab::REVISION) variables.append(key: 'CI_SERVER_REVISION', value: Gitlab::REVISION)
......
...@@ -258,10 +258,6 @@ class Namespace < ActiveRecord::Base ...@@ -258,10 +258,6 @@ class Namespace < ActiveRecord::Base
all_projects.with_storage_feature(:repository).find_each(&:remove_exports) all_projects.with_storage_feature(:repository).find_each(&:remove_exports)
end end
def features
[]
end
def refresh_project_authorizations def refresh_project_authorizations
owner.refresh_authorized_projects owner.refresh_authorized_projects
end end
......
...@@ -1885,6 +1885,10 @@ class Project < ActiveRecord::Base ...@@ -1885,6 +1885,10 @@ class Project < ActiveRecord::Base
memoized_results[cache_key] memoized_results[cache_key]
end end
def licensed_features
[]
end
private private
def storage def storage
......
...@@ -64,15 +64,6 @@ module EE ...@@ -64,15 +64,6 @@ module EE
succeeded succeeded
end 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 # Checks features (i.e. https://about.gitlab.com/products/) availabily
# for a given Namespace plan. This method should consider ancestor groups # for a given Namespace plan. This method should consider ancestor groups
# being licensed. # being licensed.
......
...@@ -495,6 +495,15 @@ module EE ...@@ -495,6 +495,15 @@ module EE
.external_authorization_service_default_label .external_authorization_service_default_label
end 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 private
def set_override_pull_mirror_available def set_override_pull_mirror_available
......
---
title: Fix GITLAB_FEATURES CI/CD env var for public projects
merge_request: 5242
author:
type: fixed
...@@ -122,76 +122,6 @@ describe Namespace do ...@@ -122,76 +122,6 @@ describe Namespace do
end end
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 describe '#feature_available?' do
let(:plan_license) { :bronze_plan } let(:plan_license) { :bronze_plan }
let(:group) { create(:group, plan: plan_license) } let(:group) { create(:group, plan: plan_license) }
......
...@@ -1364,4 +1364,84 @@ describe Project do ...@@ -1364,4 +1364,84 @@ describe Project do
end end
end 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 end
...@@ -1492,7 +1492,7 @@ describe Ci::Build do ...@@ -1492,7 +1492,7 @@ describe Ci::Build do
{ key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false }, { key: 'CI_REPOSITORY_URL', value: build.repo_url, public: false },
{ key: 'CI', value: 'true', public: true }, { key: 'CI', value: 'true', public: true },
{ key: 'GITLAB_CI', value: 'true', public: true }, { key: 'GITLAB_CI', value: 'true', public: true },
{ key: 'GITLAB_FEATURES', value: project.namespace.features.join(','), public: true }, { key: 'GITLAB_FEATURES', value: project.licensed_features.join(','), public: true },
{ key: 'CI_SERVER_NAME', value: 'GitLab', public: true }, { key: 'CI_SERVER_NAME', value: 'GitLab', public: true },
{ key: 'CI_SERVER_VERSION', value: Gitlab::VERSION, public: true }, { key: 'CI_SERVER_VERSION', value: Gitlab::VERSION, public: true },
{ key: 'CI_SERVER_REVISION', value: Gitlab::REVISION, public: true }, { key: 'CI_SERVER_REVISION', value: Gitlab::REVISION, public: true },
......
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