Update form to properly set the path

Also includes a change in allowing uploaded files, as there was a
mismatch in object_id between classes, disallowing params[:file], which
is a UploadedFile, newly loaded. The params checked against the older
version.

Fixes gitlab-org/gitlab-ce#36519
This commit is contained in:
Zeger-Jan van de Weg 2017-08-21 17:50:34 +02:00
parent fa293df2b7
commit 539dee9673
No known key found for this signature in database
GPG key ID: 65F6A8D64A88ABAC
3 changed files with 55 additions and 46 deletions

View file

@ -25,7 +25,7 @@
= hidden_field_tag :namespace_id, value: current_user.namespace_id
.form-group.col-xs-12.col-sm-6.project-path
= 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
.form-group.col-md-12
@ -33,7 +33,6 @@
.row
.form-group.col-sm-12
= hidden_field_tag :namespace_id, @namespace.id
= hidden_field_tag :path, @path
= label_tag :file, 'GitLab project export', class: 'label-light'
.form-group
= file_field_tag :file, class: ''

View file

@ -10,10 +10,8 @@ end
#
module Gitlab
module StrongParameterScalars
GITLAB_PERMITTED_SCALAR_TYPES = [::UploadedFile].freeze
def permitted_scalar?(value)
super || GITLAB_PERMITTED_SCALAR_TYPES.any? { |type| value.is_a?(type) }
super || value.is_a?(::UploadedFile)
end
end
end

View file

@ -3,11 +3,13 @@ require 'spec_helper'
feature 'Import/Export - project import integration test', js: true do
include Select2Helper
let(:user) { create(:user) }
let(:file) { File.join(Rails.root, 'spec', 'features', 'projects', 'import_export', 'test_project_export.tar.gz') }
let(:export_path) { "#{Dir.tmpdir}/import_file_spec" }
background do
allow_any_instance_of(Gitlab::ImportExport).to receive(:storage_path).and_return(export_path)
gitlab_sign_in(user)
end
after do
@ -18,10 +20,7 @@ feature 'Import/Export - project import integration test', js: true do
let(:user) { create(:admin) }
let!(:namespace) { create(:namespace, name: "asd", owner: user) }
before do
gitlab_sign_in(user)
end
context 'prefilled the path' do
scenario 'user imports an exported project successfully' do
visit new_project_path
@ -35,7 +34,7 @@ feature 'Import/Export - project import integration test', js: true do
attach_file('file', file)
expect { click_on 'Import project' }.to change { Project.count }.from(0).to(1)
expect { click_on 'Import project' }.to change { Project.count }.by(1)
project = Project.last
expect(project).not_to be_nil
@ -45,8 +44,27 @@ feature 'Import/Export - project import integration test', js: true do
expect(wiki_exists?(project)).to be true
expect(project.import_status).to eq('finished')
end
end
context 'path is not prefilled' do
scenario 'user imports an exported project successfully' do
visit new_project_path
click_link 'GitLab export'
fill_in :path, with: 'test-project-path', visible: true
attach_file('file', file)
expect { click_on 'Import project' }.to change { Project.count }.by(1)
project = Project.last
expect(project).not_to be_nil
expect(page).to have_content("Project 'test-project-path' is being imported")
end
end
end
scenario 'invalid project' do
namespace = create(:namespace, name: "asd", owner: user)
project = create(:project, namespace: namespace)
visit new_project_path
@ -61,14 +79,8 @@ feature 'Import/Export - project import integration test', js: true do
expect(page).to have_content('Project could not be imported')
end
end
end
context 'when limited to the default user namespace' do
let(:user) { create(:user) }
before do
gitlab_sign_in(user)
end
scenario 'passes correct namespace ID in the URL' do
visit new_project_path