Commit 6ec35847 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Don't validate namespace license when there's no namespace

During creation, it's possible for a project not to have a namespace
temporarily. In this case we'll fall back on global availability since
we can't check the namespace yet.
parent c4fb85c0
...@@ -515,7 +515,7 @@ module EE ...@@ -515,7 +515,7 @@ module EE
def load_licensed_feature_available(feature) def load_licensed_feature_available(feature)
globally_available = License.feature_available?(feature) globally_available = License.feature_available?(feature)
if current_application_settings.should_check_namespace_plan? if namespace && current_application_settings.should_check_namespace_plan?
globally_available && globally_available &&
(public? && namespace.public? || namespace.feature_available_in_plan?(feature)) (public? && namespace.public? || namespace.feature_available_in_plan?(feature))
else else
......
...@@ -16,6 +16,6 @@ module Gitlab ...@@ -16,6 +16,6 @@ module Gitlab
end end
def self.dev_env_or_com? def self.dev_env_or_com?
Rails.env.development? || com? Rails.env.test? || Rails.env.development? || com?
end end
end end
...@@ -28,7 +28,7 @@ describe ApplicationSetting do ...@@ -28,7 +28,7 @@ describe ApplicationSetting do
describe '#should_check_namespace_plan?' do describe '#should_check_namespace_plan?' do
before do before do
stub_application_setting(check_namespace_plan: check_namespace_plan_column) stub_application_setting(check_namespace_plan: check_namespace_plan_column)
allow(::Gitlab).to receive(:com?) { gl_com } allow(::Gitlab).to receive(:dev_env_or_com?) { gl_com }
end end
subject { setting.should_check_namespace_plan? } subject { setting.should_check_namespace_plan? }
......
...@@ -79,6 +79,32 @@ describe Projects::CreateService, '#execute' do ...@@ -79,6 +79,32 @@ describe Projects::CreateService, '#execute' do
expect(project.mirror_trigger_builds).to be true expect(project.mirror_trigger_builds).to be true
end end
end end
context 'with checks on the namespace' do
before do
enable_namespace_license_check!
end
context 'when not licensed on a namespace' do
it 'does not allow enabeling mirrors' do
project = create_project(user, opts)
expect(project).to be_persisted
expect(project.mirror).to be_falsey
end
end
context 'when licensed on a namespace' do
it 'allows enabling mirrors' do
user.namespace.update!(plan: Plan.find_by(name: 'gold'))
project = create_project(user, opts)
expect(project).to be_persisted
expect(project.mirror).to be_truthy
end
end
end
end end
context 'when unlicensed' do context 'when unlicensed' do
...@@ -151,6 +177,31 @@ describe Projects::CreateService, '#execute' do ...@@ -151,6 +177,31 @@ describe Projects::CreateService, '#execute' do
end end
end end
context 'when importing Project by repo URL' do
context 'and check namespace plan is enabled' do
before do
allow_any_instance_of(EE::Project).to receive(:add_import_job)
enable_namespace_license_check!
end
it 'creates the project' do
opts = {
name: 'GitLab',
import_url: 'https://www.gitlab.com/gitlab-org/gitlab-ce',
visibility_level: Gitlab::VisibilityLevel::PRIVATE,
namespace_id: user.namespace.id,
mirror: true,
mirror_user_id: user.id,
mirror_trigger_builds: true
}
project = create_project(user, opts)
expect(project).to be_persisted
end
end
end
def create_project(user, opts) def create_project(user, opts)
described_class.new(user, opts).execute described_class.new(user, opts).execute
end end
......
...@@ -18,5 +18,10 @@ module EE ...@@ -18,5 +18,10 @@ module EE
allow(License).to receive(:feature_available?).with(feature) { enabled } allow(License).to receive(:feature_available?).with(feature) { enabled }
end end
end end
def enable_namespace_license_check!
stub_env('IN_MEMORY_APPLICATION_SETTINGS', 'false')
current_application_settings.update!(check_namespace_plan: true)
end
end 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