Commit cc370bc8 authored by Douwe Maan's avatar Douwe Maan Committed by Jarka Kadlecova

Merge branch 'zj-fix-import-gitlab-export-form' into 'master'

Update form to properly set the path

Closes #36519

See merge request !13722
parent 652817fb
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
= hidden_field_tag :namespace_id, value: current_user.namespace_id = hidden_field_tag :namespace_id, value: current_user.namespace_id
.form-group.col-xs-12.col-sm-6.project-path .form-group.col-xs-12.col-sm-6.project-path
= label_tag :path, 'Project name', class: 'label-light' = label_tag :path, 'Project name', class: 'label-light'
= text_field_tag :path, nil, placeholder: "my-awesome-project", class: "js-path-name form-control", tabindex: 2, autofocus: true, required: true = text_field_tag :path, @path, placeholder: "my-awesome-project", class: "js-path-name form-control", tabindex: 2, autofocus: true, required: true
.row .row
.form-group.col-md-12 .form-group.col-md-12
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
.row .row
.form-group.col-sm-12 .form-group.col-sm-12
= hidden_field_tag :namespace_id, @namespace.id = hidden_field_tag :namespace_id, @namespace.id
= hidden_field_tag :path, @path
= label_tag :file, 'GitLab project export', class: 'label-light' = label_tag :file, 'GitLab project export', class: 'label-light'
.form-group .form-group
= file_field_tag :file, class: '' = file_field_tag :file, class: ''
......
...@@ -10,10 +10,8 @@ end ...@@ -10,10 +10,8 @@ end
# #
module Gitlab module Gitlab
module StrongParameterScalars module StrongParameterScalars
GITLAB_PERMITTED_SCALAR_TYPES = [::UploadedFile].freeze
def permitted_scalar?(value) def permitted_scalar?(value)
super || GITLAB_PERMITTED_SCALAR_TYPES.any? { |type| value.is_a?(type) } super || value.is_a?(::UploadedFile)
end end
end end
end end
......
...@@ -3,11 +3,13 @@ require 'spec_helper' ...@@ -3,11 +3,13 @@ require 'spec_helper'
feature 'Import/Export - project import integration test', js: true do feature 'Import/Export - project import integration test', js: true do
include Select2Helper include Select2Helper
let(:user) { create(:user) }
let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') } let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') }
let(:export_path) { "#{Dir.tmpdir}/import_file_spec" } let(:export_path) { "#{Dir.tmpdir}/import_file_spec" }
background do background do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path) allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
gitlab_sign_in(user)
end end
after(:each) do after(:each) do
...@@ -18,57 +20,67 @@ feature 'Import/Export - project import integration test', js: true do ...@@ -18,57 +20,67 @@ feature 'Import/Export - project import integration test', js: true do
let(:user) { create(:admin) } let(:user) { create(:admin) }
let!(:namespace) { create(:namespace, name: "asd", owner: user) } let!(:namespace) { create(:namespace, name: "asd", owner: user) }
before do context 'prefilled the path' do
gitlab_sign_in(user) scenario 'user imports an exported project successfully' do
end visit new_project_path
scenario 'user imports an exported project successfully' do select2(namespace.id, from: '#project_namespace_id')
visit new_project_path fill_in :project_path, with: 'test-project-path', visible: true
click_link 'GitLab export'
select2(namespace.id, from: '#project_namespace_id') expect(page).to have_content('Import an exported GitLab project')
fill_in :project_path, with: 'test-project-path', visible: true expect(URI.parse(current_url).query).to eq("namespace_id=#{namespace.id}&path=test-project-path")
click_link 'GitLab export' expect(Gitlab::ImportExport).to receive(:import_upload_path).with(filename: /\A\h{32}_test-project-path\z/).and_call_original
expect(page).to have_content('Import an exported GitLab project') attach_file('file', file)
expect(URI.parse(current_url).query).to eq("namespace_id=#{namespace.id}&path=test-project-path")
expect(Gitlab::ImportExport).to receive(:import_upload_path).with(filename: /\A\h{32}_test-project-path\z/).and_call_original
attach_file('file', file) expect { click_on 'Import project' }.to change { Project.count }.by(1)
expect { click_on 'Import project' }.to change { Project.count }.from(0).to(1) project = Project.last
expect(project).not_to be_nil
project = Project.last expect(project.issues).not_to be_empty
expect(project).not_to be_nil expect(project.merge_requests).not_to be_empty
expect(project.issues).not_to be_empty expect(project_hook_exists?(project)).to be true
expect(project.merge_requests).not_to be_empty expect(wiki_exists?(project)).to be true
expect(project_hook_exists?(project)).to be true expect(project.import_status).to eq('finished')
expect(wiki_exists?(project)).to be true end
expect(project.import_status).to eq('finished')
end end
scenario 'invalid project' do context 'path is not prefilled' do
project = create(:project, namespace: namespace) scenario 'user imports an exported project successfully' do
visit new_project_path
click_link 'GitLab export'
visit new_project_path fill_in :path, with: 'test-project-path', visible: true
attach_file('file', file)
select2(namespace.id, from: '#project_namespace_id') expect { click_on 'Import project' }.to change { Project.count }.by(1)
fill_in :project_path, with: project.name, visible: true
click_link 'GitLab export'
attach_file('file', file)
click_on 'Import project'
page.within('.flash-container') do project = Project.last
expect(page).to have_content('Project could not be imported') expect(project).not_to be_nil
expect(page).to have_content("Project 'test-project-path' is being imported")
end end
end end
end end
context 'when limited to the default user namespace' do scenario 'invalid project' do
let(:user) { create(:user) } namespace = create(:namespace, name: "asd", owner: user)
before do project = create(:project, namespace: namespace)
gitlab_sign_in(user)
visit new_project_path
select2(namespace.id, from: '#project_namespace_id')
fill_in :project_path, with: project.name, visible: true
click_link 'GitLab export'
attach_file('file', file)
click_on 'Import project'
page.within('.flash-container') do
expect(page).to have_content('Project could not be imported')
end end
end
context 'when limited to the default user namespace' do
scenario 'passes correct namespace ID in the URL' do scenario 'passes correct namespace ID in the URL' do
visit new_project_path visit new_project_path
......
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