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

Add attachment_data_id to file attachments #9641

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

richardTowers
Copy link
Contributor

This needs to follow on from alphagov/publishing-api#2994

As described there, the lack of attachment_data_id in the data for file asset attachments in content store makes it hard to request the attachments on the server side. Instead, we have to redirect users to the assets, which has led to ugly workarounds like CSV previews being rendered by frontend but served on assets.publishing.service.gov.uk.

Adding attachment_data_id should allow the frontends to request attachments directly, using the API client:

GdsApi.asset_manager.media(attachment_data_id, filename)

This should make it much more convenient to preview assets, or use them for other rendering purposes (e.g. showing a CSV as a line graph).

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

This needs to follow on from alphagov/publishing-api#2994

As described there, the lack of attachment_data_id in the data for file asset attachments in content store makes it hard to request the attachments on the server side. Instead, we have to redirect users to the assets, which has led to ugly workarounds like CSV previews being rendered by frontend but served on assets.publishing.service.gov.uk.

Adding attachment_data_id should allow the frontends to request attachments directly, using the API client:

    GdsApi.asset_manager.media(attachment_data_id, filename)

This should make it much more convenient to preview assets, or use them for other rendering purposes (e.g. showing a CSV as a line graph).
def attachment_data_id
return unless csv? && attachable.is_a?(Edition) && attachment_data.all_asset_variants_uploaded?

attachment_data.id
Copy link
Contributor

@catalinailie catalinailie Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure attachment_data.id is the ID we want. GdsApi.asset_manager expects the asset's ID, and that one, in whitehall, is Asset.asset_manager_id.

I think this is the reason why we have this scenario with preview_url formed in whitehall using attachment_data.id and then overwritten in government-frontend with the URL that has this asset_manager_id in it (formed here I think, but I might be wrong).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants