Commit b67a5b5a authored by Stan Hu's avatar Stan Hu

Fix import/export not checking upload result

Previously if a project export were not saved or uploaded,
a user would receive notification that the export was successful.

We now check the return result of the service and notify the
user properly.

Relates to https://gitlab.com/gitlab-org/gitlab/-/issues/349425

Changelog: fixed
parent bbb673bf
...@@ -47,8 +47,7 @@ module Projects ...@@ -47,8 +47,7 @@ module Projects
end end
def save_all! def save_all!
if save_exporters if save_exporters && save_export_archive
Gitlab::ImportExport::Saver.save(exportable: project, shared: shared)
notify_success notify_success
else else
notify_error! notify_error!
...@@ -59,6 +58,10 @@ module Projects ...@@ -59,6 +58,10 @@ module Projects
exporters.all?(&:save) exporters.all?(&:save)
end end
def save_export_archive
Gitlab::ImportExport::Saver.save(exportable: project, shared: shared)
end
def exporters def exporters
[ [
version_saver, avatar_saver, project_tree_saver, uploads_saver, version_saver, avatar_saver, project_tree_saver, uploads_saver,
......
...@@ -20,7 +20,7 @@ RSpec.describe Projects::ImportExport::ExportService do ...@@ -20,7 +20,7 @@ RSpec.describe Projects::ImportExport::ExportService do
end end
it 'succeeds' do it 'succeeds' do
expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project_template, shared: shared) expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project_template, shared: shared).and_return(true)
subject subject
end end
...@@ -32,7 +32,7 @@ RSpec.describe Projects::ImportExport::ExportService do ...@@ -32,7 +32,7 @@ RSpec.describe Projects::ImportExport::ExportService do
end end
it 'succeeds' do it 'succeeds' do
expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project_template, shared: shared) expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project_template, shared: shared).and_return(true)
subject subject
end end
......
...@@ -54,6 +54,8 @@ module Gitlab ...@@ -54,6 +54,8 @@ module Gitlab
File.open(archive_file) { |file| upload.export_file = file } File.open(archive_file) { |file| upload.export_file = file }
upload.save! upload.save!
true
end end
def error_message def error_message
......
...@@ -93,11 +93,23 @@ RSpec.describe Projects::ImportExport::ExportService do ...@@ -93,11 +93,23 @@ RSpec.describe Projects::ImportExport::ExportService do
end end
it 'saves the project in the file system' do it 'saves the project in the file system' do
expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project, shared: shared) expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project, shared: shared).and_return(true)
service.execute service.execute
end end
context 'when the upload fails' do
before do
expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project, shared: shared).and_return(false)
end
it 'notifies the user of an error' do
expect(service).to receive(:notify_error).and_call_original
expect { service.execute }.to raise_error(Gitlab::ImportExport::Error)
end
end
it 'calls the after export strategy' do it 'calls the after export strategy' do
expect(after_export_strategy).to receive(:execute) expect(after_export_strategy).to receive(:execute)
...@@ -107,6 +119,7 @@ RSpec.describe Projects::ImportExport::ExportService do ...@@ -107,6 +119,7 @@ RSpec.describe Projects::ImportExport::ExportService do
context 'when after export strategy fails' do context 'when after export strategy fails' do
before do before do
allow(after_export_strategy).to receive(:execute).and_return(false) allow(after_export_strategy).to receive(:execute).and_return(false)
expect(Gitlab::ImportExport::Saver).to receive(:save).with(exportable: project, shared: shared).and_return(true)
end end
after do after do
......
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