Commit e97a9e23 authored by Doug Stull's avatar Doug Stull

Fix broken project creation without import sources

- should not require import sources if import url is not
  present

Changelog: fixed
parent 108a1a40
......@@ -181,9 +181,10 @@ module API
def filter_attributes_using_license!(attrs)
end
def validate_git_import_url!(import_url, import_enabled: true)
def validate_git_import_url!(import_url)
return if import_url.blank?
return unless import_enabled
yield if block_given?
result = Import::ValidateRemoteGitEndpointService.new(url: import_url).execute # network call
......
......@@ -270,7 +270,7 @@ module API
attrs = translate_params_for_compatibility(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
......
......@@ -1160,6 +1160,15 @@ RSpec.describe API::Projects do
expect(response).to have_gitlab_http_status(:forbidden)
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
url = 'http://example.com'
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