Commit 322bf064 authored by Kerri Miller's avatar Kerri Miller

Merge branch '270584-fix-project-create-without-import-sources-and-import-url' into 'master'

Fix broken project creation without import sources

See merge request gitlab-org/gitlab!75121
parents f290a6b5 e97a9e23
...@@ -181,9 +181,10 @@ module API ...@@ -181,9 +181,10 @@ module API
def filter_attributes_using_license!(attrs) def filter_attributes_using_license!(attrs)
end end
def validate_git_import_url!(import_url, import_enabled: true) def validate_git_import_url!(import_url)
return if import_url.blank? return if import_url.blank?
return unless import_enabled
yield if block_given?
result = Import::ValidateRemoteGitEndpointService.new(url: import_url).execute # network call result = Import::ValidateRemoteGitEndpointService.new(url: import_url).execute # network call
......
...@@ -270,7 +270,7 @@ module API ...@@ -270,7 +270,7 @@ module API
attrs = translate_params_for_compatibility(attrs) attrs = translate_params_for_compatibility(attrs)
filter_attributes_using_license!(attrs) filter_attributes_using_license!(attrs)
validate_git_import_url!(params[:import_url], import_enabled: check_import_by_url_is_enabled) validate_git_import_url!(params[:import_url]) { check_import_by_url_is_enabled }
project = ::Projects::CreateService.new(current_user, attrs).execute project = ::Projects::CreateService.new(current_user, attrs).execute
......
...@@ -1160,6 +1160,15 @@ RSpec.describe API::Projects do ...@@ -1160,6 +1160,15 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:forbidden) expect(response).to have_gitlab_http_status(:forbidden)
end end
it 'allows creating a project without an import_url when git import source is disabled', :aggregate_failures do
stub_application_setting(import_sources: nil)
project_params = { path: 'path-project-Foo' }
expect { post api('/projects', user), params: project_params }.to change { Project.count }.by(1)
expect(response).to have_gitlab_http_status(:created)
end
it 'disallows creating a project with an import_url that is not reachable', :aggregate_failures do it 'disallows creating a project with an import_url that is not reachable', :aggregate_failures do
url = 'http://example.com' url = 'http://example.com'
endpoint_url = "#{url}/info/refs?service=git-upload-pack" endpoint_url = "#{url}/info/refs?service=git-upload-pack"
......
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