Commit dd0f3b90 authored by Douwe Maan's avatar Douwe Maan

Merge branch...

Merge branch '50944-unable-to-import-repository-undefined-method-import_file-for-nil-nilclass' into 'master'

Resolve "Unable to import repository:  undefined method `import_file' for nil:NilClass"

Closes #50944

See merge request gitlab-org/gitlab-ce!21765
parents 78b3eea7 e72aeccd
...@@ -11,7 +11,7 @@ class Import::GitlabProjectsController < Import::BaseController ...@@ -11,7 +11,7 @@ class Import::GitlabProjectsController < Import::BaseController
def create def create
unless file_is_valid? 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 end
@project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute @project = ::Projects::GitlabProjectsImportService.new(current_user, project_params).execute
...@@ -29,7 +29,11 @@ class Import::GitlabProjectsController < Import::BaseController ...@@ -29,7 +29,11 @@ class Import::GitlabProjectsController < Import::BaseController
private private
def file_is_valid? 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 end
def verify_gitlab_project_import_enabled def verify_gitlab_project_import_enabled
......
...@@ -196,7 +196,7 @@ class ProjectsController < Projects::ApplicationController ...@@ -196,7 +196,7 @@ class ProjectsController < Projects::ApplicationController
def download_export def download_export
if @project.export_file_exists? if @project.export_file_exists?
send_upload(@project.export_file) send_upload(@project.export_file, attachment: @project.export_file.filename)
else else
redirect_to( redirect_to(
edit_project_path(@project, anchor: 'js-export-project'), edit_project_path(@project, anchor: 'js-export-project'),
......
---
title: Fix import error when archive does not have the correct extension
merge_request: 21765
author:
type: fixed
...@@ -3,7 +3,7 @@ require 'spec_helper' ...@@ -3,7 +3,7 @@ require 'spec_helper'
describe Import::GitlabProjectsController do describe Import::GitlabProjectsController do
set(:namespace) { create(:namespace) } set(:namespace) { create(:namespace) }
set(:user) { namespace.owner } 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 before do
sign_in(user) sign_in(user)
......
...@@ -49,6 +49,8 @@ describe 'Import/Export - project export integration test', :js do ...@@ -49,6 +49,8 @@ describe 'Import/Export - project export integration test', :js do
expect(file_permissions(project.export_path)).to eq(0700) 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| in_directory_with_expanded_export(project) do |exit_status, tmpdir|
expect(exit_status).to eq(0) expect(exit_status).to eq(0)
......
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