Commit d47d3773 authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch 'ce-37407-error-500-when-creating-a-project-createservice-returns-a-nil-object' into 'master'

Don't check license on namespace when it wasn't set yet.

Closes gitlab-ce#37407 and gitlab-com/support-forum#2409

See merge request !2854
parents d3ccb4d4 6ec35847
......@@ -515,7 +515,7 @@ module EE
def load_licensed_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 &&
(public? && namespace.public? || namespace.feature_available_in_plan?(feature))
else
......
......@@ -16,6 +16,6 @@ module Gitlab
end
def self.dev_env_or_com?
Rails.env.development? || com?
Rails.env.test? || Rails.env.development? || com?
end
end
......@@ -28,7 +28,7 @@ describe ApplicationSetting do
describe '#should_check_namespace_plan?' do
before do
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
subject { setting.should_check_namespace_plan? }
......
......@@ -79,6 +79,32 @@ describe Projects::CreateService, '#execute' do
expect(project.mirror_trigger_builds).to be true
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
context 'when unlicensed' do
......@@ -151,6 +177,31 @@ describe Projects::CreateService, '#execute' do
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)
described_class.new(user, opts).execute
end
......
......@@ -18,5 +18,10 @@ module EE
allow(License).to receive(:feature_available?).with(feature) { enabled }
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
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