Fix generated URLs for native files in subdirectories

Our handling of uploaded files (see FilesController#show_protected_upload) checks for the full file name including the file path. However, URLs generated by CarrierWave didn't contain any path information resulting in invalid URLs. The wrong behavior was only visible when serving native files was disabled in Rails (or by using the x_sendfile_header).
This commit is contained in:
Sebastian Serth
2023-01-20 22:56:30 +01:00
parent 234a4fe02b
commit e8983a28d9

View File

@ -6,4 +6,14 @@ class FileUploader < CarrierWave::Uploader::Base
def store_dir def store_dir
"uploads/files/#{model.id}" "uploads/files/#{model.id}"
end end
def url(*args)
if model.path?
desired = encode_path("uploads/files/#{model.id}/#{model.path}")
generated = encode_path(store_dir)
super&.sub(generated, desired)
else
super
end
end
end end