diff --git a/app/controllers/csv_preview_controller.rb b/app/controllers/csv_preview_controller.rb index aac85218ca..52bce40474 100644 --- a/app/controllers/csv_preview_controller.rb +++ b/app/controllers/csv_preview_controller.rb @@ -16,10 +16,10 @@ def show parent_document_path = URI(@asset["parent_document_url"]).request_uri @content_item = GdsApi.content_store.content_item(parent_document_path).to_hash - @attachment_metadata = @content_item.dig("details", "attachments").select do |attachment| - attachment["url"] =~ /#{Regexp.escape(asset_path)}$/ + attachment["filename"] == filename end + original_error = nil row_sep = :auto download_file = params[:legacy] ? whitehall_media_download : media_download @@ -58,6 +58,10 @@ def asset_path request.path.sub("/preview", "").sub(/^\//, "") end + def asset_filename + asset_path.split("/").last + end + def whitehall_media_download GdsApi.asset_manager.whitehall_media(asset_path).body end diff --git a/test/integration/csv_preview_test.rb b/test/integration/csv_preview_test.rb index e95d1c06a9..db983d2713 100644 --- a/test/integration/csv_preview_test.rb +++ b/test/integration/csv_preview_test.rb @@ -243,6 +243,7 @@ def setup_asset_manager(legacy_url_path, parent_document_url, asset_manager_id = end def setup_content_item_legacy(legacy_url_path, parent_document_base_path) + filename = legacy_url_path.split("/").last content_item = { base_path: parent_document_base_path, document_type: "guidance", @@ -251,11 +252,13 @@ def setup_content_item_legacy(legacy_url_path, parent_document_base_path) attachments: [ { title: "Attachment 1", - url: "https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/5678/filename.csv", + filename: "file.csv", + url: "https://www.gov.uk/government/uploads/system/uploads/attachment_data/file/5678/file.csv", file_size: "1024", }, { title: "Attachment 2", + filename:, url: "https://www.gov.uk/#{legacy_url_path}", file_size: "2048", }, @@ -280,6 +283,7 @@ def setup_content_item_legacy(legacy_url_path, parent_document_base_path) end def setup_content_item_non_legacy(non_legacy_url_path, parent_document_base_path) + filename = non_legacy_url_path.split("/").last content_item = { base_path: parent_document_base_path, document_type: "guidance", @@ -288,11 +292,13 @@ def setup_content_item_non_legacy(non_legacy_url_path, parent_document_base_path attachments: [ { title: "Attachment 1", - url: "https://www.gov.uk/media/5678/filename.csv", + filename: "file.csv", + url: "https://www.gov.uk/media/5678/file.csv", file_size: "1024", }, { title: "Attachment 2", + filename:, url: "https://www.gov.uk/#{non_legacy_url_path}", file_size: "2048", },