diff options
author | James Lopez <james@gitlab.com> | 2018-09-17 13:52:49 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-09-17 13:52:49 +0300 |
commit | e72aeccdae4cdb35c3ab4941bcf3b4f0dd22d41b (patch) | |
tree | d06cf884ca34caed2fba77743b931ea6f521e14c | |
parent | 78b3eea7d248c6d3c48b615c9df24a95cb5fd1d8 (diff) |
Resolve "Unable to import repository: undefined method `import_file' for nil:NilClass"
5 files changed, 15 insertions, 4 deletions
diff --git a/app/controllers/import/gitlab_projects_controller.rb b/app/controllers/import/gitlab_projects_controller.rb index f22df992fe9..f21c38a4c27 100644 --- a/app/controllers/import/gitlab_projects_controller.rb +++ b/app/controllers/import/gitlab_projects_controller.rb @@ -11,7 +11,7 @@ class Import::GitlabProjectsController < Import::BaseController def create unless file_is_valid? - return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive." }) + return redirect_back_or_default(options: { alert: "You need to upload a GitLab project export archive (ending in .gz)." }) end @project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute @@ -29,7 +29,11 @@ class Import::GitlabProjectsController < Import::BaseController private def file_is_valid? - project_params[:file] && project_params[:file].respond_to?(:read) + return false unless project_params[:file] && project_params[:file].respond_to?(:read) + + filename = project_params[:file].original_filename + + ImportExportUploader::EXTENSION_WHITELIST.include?(File.extname(filename).delete('.')) end def verify_gitlab_project_import_enabled diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e2f9d501c4b..64d9b16a041 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -196,7 +196,7 @@ class ProjectsController < Projects::ApplicationController def download_export if @project.export_file_exists? - send_upload(@project.export_file) + send_upload(@project.export_file, attachment: @project.export_file.filename) else redirect_to( edit_project_path(@project, anchor: 'js-export-project'), diff --git a/changelogs/unreleased/50944-unable-to-import-repository-undefined-method-import_file-for-nil-nilclass.yml b/changelogs/unreleased/50944-unable-to-import-repository-undefined-method-import_file-for-nil-nilclass.yml new file mode 100644 index 00000000000..ac18565090a --- /dev/null +++ b/changelogs/unreleased/50944-unable-to-import-repository-undefined-method-import_file-for-nil-nilclass.yml @@ -0,0 +1,5 @@ +--- +title: Fix import error when archive does not have the correct extension +merge_request: 21765 +author: +type: fixed diff --git a/spec/controllers/import/gitlab_projects_controller_spec.rb b/spec/controllers/import/gitlab_projects_controller_spec.rb index d624659bce9..cbd1a112602 100644 --- a/spec/controllers/import/gitlab_projects_controller_spec.rb +++ b/spec/controllers/import/gitlab_projects_controller_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe Import::GitlabProjectsController do set(:namespace) { create(:namespace) } set(:user) { namespace.owner } - let(:file) { fixture_file_upload('spec/fixtures/doc_sample.txt', 'text/plain') } + let(:file) { fixture_file_upload('spec/fixtures/project_export.tar.gz', 'text/plain') } before do sign_in(user) diff --git a/spec/features/projects/import_export/export_file_spec.rb b/spec/features/projects/import_export/export_file_spec.rb index 8a418356541..a2b96514d64 100644 --- a/spec/features/projects/import_export/export_file_spec.rb +++ b/spec/features/projects/import_export/export_file_spec.rb @@ -49,6 +49,8 @@ describe 'Import/Export - project export integration test', :js do expect(file_permissions(project.export_path)).to eq(0700) + expect(project.export_file.path).to include('tar.gz') + in_directory_with_expanded_export(project) do |exit_status, tmpdir| expect(exit_status).to eq(0) |