Commit dbceae97 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'ce-to-ee-2018-08-02-import-templates-fix' into 'ce-to-ee-2018-08-02'

Fix project templates failures

See merge request gitlab-org/gitlab-ee!6780
parents ec662fcf 9e858cb4
...@@ -22,7 +22,6 @@ module EE ...@@ -22,7 +22,6 @@ module EE
if custom_template if custom_template
params[:import_type] = 'gitlab_custom_project_template' params[:import_type] = 'gitlab_custom_project_template'
params[:import_source] = custom_template.id
end end
end end
......
...@@ -8,8 +8,12 @@ module EE ...@@ -8,8 +8,12 @@ module EE
validates :export_into_project_id, presence: true validates :export_into_project_id, presence: true
attr_reader :params
def initialize(export_into_project_id:) def initialize(export_into_project_id:)
super super
@params = {}
end end
protected protected
...@@ -17,7 +21,7 @@ module EE ...@@ -17,7 +21,7 @@ module EE
def strategy_execute def strategy_execute
return unless export_into_project_exists? return unless export_into_project_exists?
prepare_template_environment(export_file_path) prepare_template_environment(export_file)
set_import_attributes set_import_attributes
...@@ -26,18 +30,18 @@ module EE ...@@ -26,18 +30,18 @@ module EE
project.remove_exported_project_file project.remove_exported_project_file
end end
def export_file_path def export_file
strong_memoize(:export_file_path) do strong_memoize(:export_file) do
if object_storage? if object_storage?
project.import_export_upload.export_file.path project.import_export_upload.export_file&.file
else else
project.export_project_path File.open(project.export_project_path)
end end
end end
end end
def set_import_attributes def set_import_attributes
::Project.update(export_into_project_id, import_source: import_upload_path) ::Project.update(export_into_project_id, params)
end end
def export_into_project_exists? def export_into_project_exists?
......
...@@ -71,6 +71,26 @@ describe ProjectsController do ...@@ -71,6 +71,26 @@ describe ProjectsController do
stub_ee_application_setting(custom_project_templates_group_id: group.id) stub_ee_application_setting(custom_project_templates_group_id: group.id)
end end
context 'old upload' do
before do
stub_feature_flags(import_export_object_storage: false)
end
it 'creates the project from project template' do
post :create, project: templates_params
created_project = Project.find_by_path('foo')
expect(flash[:notice]).to eq "Project 'foo' was successfully created."
expect(created_project.repository.empty?).to be false
end
end
context 'object storage' do
before do
stub_feature_flags(import_export_object_storage: true)
stub_uploads_object_storage(FileUploader)
end
it 'creates the project from project template' do it 'creates the project from project template' do
post :create, project: templates_params post :create, project: templates_params
...@@ -79,6 +99,7 @@ describe ProjectsController do ...@@ -79,6 +99,7 @@ describe ProjectsController do
expect(created_project.repository.empty?).to be false expect(created_project.repository.empty?).to be false
end end
end end
end
context 'when unlicensed' do context 'when unlicensed' do
before do before do
......
...@@ -23,12 +23,14 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm ...@@ -23,12 +23,14 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
describe '#execute' do describe '#execute' do
it 'updates the project import_source with the path to import' do it 'updates the project import_source with the path to import' do
allow(subject).to receive(:import_upload_path).and_return('path') path = Tempfile.new.path
expect(Project).to receive(:update).with(project.id, import_source: 'path').and_call_original
allow(subject).to receive(:import_upload_path).and_return(path)
expect(Project).to receive(:update).with(project.id, import_source: path).and_call_original
subject.execute(user, project_template) subject.execute(user, project_template)
expect(project.reload.import_source).to eq 'path' expect(project.reload.import_source).to eq path
end end
it 'imports repository' do it 'imports repository' do
...@@ -45,18 +47,16 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm ...@@ -45,18 +47,16 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
subject.execute(user, project_template) subject.execute(user, project_template)
end end
describe 'export_file_path' do describe 'export_file' do
before do before do
allow(subject).to receive(:project).and_return(project_template) allow(subject).to receive(:project).and_return(project_template)
end end
after do
subject.send(:export_file_path)
end
context 'without object storage' do context 'without object storage' do
it 'returns the local path' do it 'returns the local path' do
expect(project_template).to receive(:export_project_path) subject.execute(user, project_template)
expect(subject.send(:export_file)).not_to be_nil
end end
end end
...@@ -64,7 +64,9 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm ...@@ -64,7 +64,9 @@ describe EE::Gitlab::ImportExport::AfterExportStrategies::CustomTemplateExportIm
let(:project_template) { create(:project, :with_object_export) } let(:project_template) { create(:project, :with_object_export) }
it 'returns the path from object storage' do it 'returns the path from object storage' do
expect(project_template.import_export_upload.export_file).to receive(:path) subject.execute(user, project_template)
expect(subject.send(:export_file)).not_to be_nil
end end
end end
end end
......
...@@ -3,7 +3,7 @@ module Gitlab ...@@ -3,7 +3,7 @@ module Gitlab
include Gitlab::Utils::StrongMemoize include Gitlab::Utils::StrongMemoize
def prepare_template_environment(file) def prepare_template_environment(file)
return unless file&.path.present? return unless file
if Gitlab::ImportExport.object_storage? if Gitlab::ImportExport.object_storage?
params[:import_export_upload] = ImportExportUpload.new(import_file: file) params[:import_export_upload] = ImportExportUpload.new(import_file: file)
......
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