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

Previews check content type #4544

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

KludgeKML
Copy link
Contributor

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

What

Return a 404 instead of the current broken page if a preview link is requested for a non-csv atttachment.

Why

Although we don't offer preview links to non-csv pages in gov.uk, some are in google search. We should return 404 so that they don't get into search / behave correctly when queried.

https://trello.com/c/bOxuUfBN/51-previews-for-non-csv-files

How

Add a check for content_type after getting the attachment metadata, then return a cacheable_404 if the content_type isn't "text/csv"

Screenshots

Before

Screenshot 2024-12-18 at 16 35 19

- We're only ever interested in the first found value, so use #find instead of #select, check for nil? rather than empty?, and then we can remove all the #first calls in the templates.
- search engines contain some links to preview paths for assets that aren't previewable. Since we only allow previews for text/csv, we check the content_type of the attachment and return 404 if it doesn't match.
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