refactor uploads manager
This commit is contained in:
		
							parent
							
								
									414939c97c
								
							
						
					
					
						commit
						3c31de7520
					
				|  | @ -1,12 +1,12 @@ | ||||||
| class UploadService | class UploadService | ||||||
|   def initialize(model, file, uploader_class = FileUploader) |   def initialize(model, file, uploader_class = FileUploader, **uploader_context) | ||||||
|     @model, @file, @uploader_class = model, file, uploader_class |     @model, @file, @uploader_class, @uploader_context = model, file, uploader_class, uploader_context | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|   def execute |   def execute | ||||||
|     return nil unless @file && @file.size <= max_attachment_size |     return nil unless @file && @file.size <= max_attachment_size | ||||||
| 
 | 
 | ||||||
|     uploader = @uploader_class.new(@model) |     uploader = @uploader_class.new(@model, nil, @uploader_context) | ||||||
|     uploader.store!(@file) |     uploader.store!(@file) | ||||||
| 
 | 
 | ||||||
|     uploader.to_h |     uploader.to_h | ||||||
|  |  | ||||||
|  | @ -29,10 +29,15 @@ module Gitlab | ||||||
|         Dir["#{uploads_export_path}/**/*"].each do |upload| |         Dir["#{uploads_export_path}/**/*"].each do |upload| | ||||||
|           next if File.directory?(upload) |           next if File.directory?(upload) | ||||||
| 
 | 
 | ||||||
|           UploadService.new(@project, File.open(upload, 'r'), FileUploader).execute |           secret, identifier = upload.split('/').last(2) | ||||||
|         end |  | ||||||
| 
 | 
 | ||||||
|         true |           uploader_context = { | ||||||
|  |             secret: secret, | ||||||
|  |             identifier: identifier | ||||||
|  |           } | ||||||
|  | 
 | ||||||
|  |           UploadService.new(@project, File.open(upload, 'r'), FileUploader, uploader_context).execute | ||||||
|  |         end | ||||||
|       rescue => e |       rescue => e | ||||||
|         @shared.error(e) |         @shared.error(e) | ||||||
|         false |         false | ||||||
|  |  | ||||||
|  | @ -48,7 +48,7 @@ describe Gitlab::ImportExport::UploadsManager do | ||||||
|         stub_uploads_object_storage(FileUploader) |         stub_uploads_object_storage(FileUploader) | ||||||
|       end |       end | ||||||
| 
 | 
 | ||||||
|       it 'downloads the file to include in an archive' do |       it 'saves the file' do | ||||||
|         fake_uri = double |         fake_uri = double | ||||||
| 
 | 
 | ||||||
|         expect(fake_uri).to receive(:open).and_return(StringIO.new('File content')) |         expect(fake_uri).to receive(:open).and_return(StringIO.new('File content')) | ||||||
|  | @ -70,7 +70,7 @@ describe Gitlab::ImportExport::UploadsManager do | ||||||
|           FileUtils.touch(File.join(shared.export_path, 'uploads/random', "dummy.txt")) |           FileUtils.touch(File.join(shared.export_path, 'uploads/random', "dummy.txt")) | ||||||
|         end |         end | ||||||
| 
 | 
 | ||||||
|         it 'downloads the file to include in an archive' do |         it 'restores the file' do | ||||||
|           manager.restore |           manager.restore | ||||||
| 
 | 
 | ||||||
|           expect(project.uploads.size).to eq(1) |           expect(project.uploads.size).to eq(1) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue