FIX: Ensure that multisite s3 uploads are tombstoned correctly (#6769)

* FIX: Ensure that multisite uploads are tombstoned into the correct paths

* Move multisite specs to spec/multisite/s3_store_spec.rb
This commit is contained in:
Rishabh
2018-12-19 11:02:32 +05:30
committed by Guo Xiang Tan
parent 41e06efb94
commit cae5ba7356
3 changed files with 102 additions and 14 deletions

View File

@@ -12,7 +12,9 @@ module FileStore
attr_reader :s3_helper
def initialize(s3_helper = nil)
@s3_helper = s3_helper || S3Helper.new(s3_bucket, TOMBSTONE_PREFIX)
@s3_helper = s3_helper || S3Helper.new(s3_bucket,
Rails.configuration.multisite ? multisite_tombstone_prefix : TOMBSTONE_PREFIX
)
end
def store_upload(file, upload, content_type = nil)
@@ -87,6 +89,10 @@ module FileStore
@s3_helper.update_tombstone_lifecycle(grace_period)
end
def multisite_tombstone_prefix
File.join("uploads", "tombstone", RailsMultisite::ConnectionManagement.current_db, "/")
end
def path_for(upload)
url = upload.try(:url)
FileStore::LocalStore.new.path_for(upload) if url && url[/^\/[^\/]/]

View File

@@ -39,14 +39,27 @@ class S3Helper
end
# delete the file
s3_filename.prepend(multisite_upload_path) if Rails.configuration.multisite
s3_bucket.object(get_path_for_s3_upload(s3_filename)).delete
rescue Aws::S3::Errors::NoSuchKey
end
def copy(source, destination, options: {})
if !Rails.configuration.multisite
options[:copy_source] = File.join(@s3_bucket_name, source)
else
if @s3_bucket_folder_path
bucket_folder, filename = begin
source.split("/".freeze, 2)
end
options[:copy_source] = File.join(@s3_bucket_name, bucket_folder, multisite_upload_path, filename)
else
options[:copy_source] = File.join(@s3_bucket_name, multisite_upload_path, source)
end
end
s3_bucket
.object(destination)
.copy_from(options.merge(copy_source: File.join(@s3_bucket_name, source)))
.copy_from(options)
end
# make sure we have a cors config for assets
@@ -194,6 +207,10 @@ class S3Helper
path
end
def multisite_upload_path
File.join("uploads", RailsMultisite::ConnectionManagement.current_db, "/")
end
def s3_resource
Aws::S3::Resource.new(@s3_options)
end