Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for csv preview with legacy_url_path #3781

Merged
merged 1 commit into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/controllers/csv_preview_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"] == asset_filename
end

original_error = nil
row_sep = :auto
download_file = params[:legacy] ? whitehall_media_download : media_download
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions test/integration/csv_preview_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
},
Expand All @@ -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",
Expand All @@ -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",
},
Expand Down