Skip to content

Fix parent_document_url not being sent to asset manager for consultation outcome attachments [WHIT-3466]#11469

Open
eYinka wants to merge 6 commits into
mainfrom
attachable-url-on-consultation-response
Open

Fix parent_document_url not being sent to asset manager for consultation outcome attachments [WHIT-3466]#11469
eYinka wants to merge 6 commits into
mainfrom
attachable-url-on-consultation-response

Conversation

@eYinka
Copy link
Copy Markdown
Contributor

@eYinka eYinka commented May 18, 2026

When a consultation or call for evidence is published, PublishAttachmentAssetJob updates each attachment's metadata in asset manager. For attachments belonging to a ConsultationOutcome, ConsultationPublicFeedback, or CallForEvidenceOutcome, parent_document_url was never sent because the job guards with respond_to?(:public_url), and neither ConsultationResponse nor CallForEvidenceResponse implemented that method.

Similarly, when we save a draft or update the metadata of an attachment, AssetManagerAttachmentMetadataJob calls attachable_url on AttachmentData to get the parent_document_url. This also returned nil for these types because attachable_url only handled Edition subclasses and Policy Group; neither ConsultationResponse nor CallForEvidenceResponse was covered.

We've made two fixes:

  1. Extended ConsultationResponse and CallForEvidenceResponse to delegate public_url to their parent_attachable, so PublishAttachmentAssetJob can use their parent document's public URL for parent_document_url.

  2. Extended attachable_url in AttachmentData to handle non-edition attachables that respond to parent_attachable, so AssetManagerAttachmentMetadataJob now correctly sets parent_document_url at every metadata update, including for draft consultations and calls for evidence.

Finally, I've added a backfill rake task (backfill_parent_document_url_for_non_editionable_attachables) which enqueues AssetManagerAttachmentMetadataJob for all existing attachment data records belonging to ConsultationResponse, CallForEvidenceResponse, and PolicyGroup, so that historically missing parent_document_url values are corrected in asset manager.

Issue was found through a support ticket: https://gov-uk.atlassian.net/browse/WHIT-3466


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

This application is owned by the Whitehall Experience team. Please let us know in #govuk-whitehall-experience-tech when you raise any PRs.

Follow these steps if you are doing a Rails upgrade.

Copy link
Copy Markdown
Contributor

@jamiestamp jamiestamp left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Copy Markdown
Contributor

@ChrisBAshton ChrisBAshton left a comment

Choose a reason for hiding this comment

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

Approach looks good 👍 nice one getting to the bottom of it.

In essence, parent_document_url is only reliably set at document publish time. Extending attachable_url to handle non-edition attachables with a public URL would be great as a follow-up work.

Interested in what that looks like. Care to write up a backlog item for it? 🙏


delegate :unpublishing, to: :parent_attachable

delegate :public_url, to: :parent_attachable
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please roll this out to CallForEvidence too - near-identical document type.

@eYinka eYinka force-pushed the attachable-url-on-consultation-response branch from 306219f to 2bdc282 Compare May 19, 2026 14:10
@lauraghiorghisor-tw
Copy link
Copy Markdown
Contributor

Had a quick chat with Ola - changed PR to draft and added a do not merge label to this as I think running the publish job would incorrectly publish draft assets. We'll be looking into using the Metadata updater.

@lauraghiorghisor-tw lauraghiorghisor-tw marked this pull request as draft May 19, 2026 16:18
@eYinka
Copy link
Copy Markdown
Contributor Author

eYinka commented May 20, 2026

Had a quick chat with Ola - changed PR to draft and added a do not merge label to this as I think running the publish job would incorrectly publish draft assets. We'll be looking into using the Metadata updater.

Just to clarify, the rake task isn't on this PR yet. My original intention was to make a separate PR after merging this update. Nonetheless, let's see if we can do a global fix for both cases in this PR. My rough thought for the known limitation would be adding something like:

  elsif significant_attachable.respond_to?(:public_url)
    significant_attachable.public_url
  end

to

def attachable_url(user = nil)
visible_edition = visible_edition_for(user)
if visible_edition.blank? && draft_edition
draft_edition.public_url(draft: true)
elsif visible_edition.present?
visible_edition.public_url
end
end

@lauraghiorghisor-tw lauraghiorghisor-tw force-pushed the attachable-url-on-consultation-response branch from 2bdc282 to cba8239 Compare May 20, 2026 13:19
end
end

def url_for(edition)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am certain this method exists elsewhere - more or less the same

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've checked for this but didn't find any instance.

eYinka and others added 4 commits May 20, 2026 18:15
…type attachments

When a consultation or call for evidence is published, `PublishAttachmentAssetJob` updates each attachment's metadata in asset manager. For attachments belonging to a ConsultationOutcome, ConsultationPublicFeedback, or CallForEvidenceOutcome, `parent_document_url` was never sent because the job guards with `respond_to?(:public_url)`, and neither ConsultationResponse nor CallForEvidenceResponse implemented that method.

I've extended ConsultationResponse and CallForEvidenceResponse, so the PublishAttachmentAssetJob can use their parent document's public URL for associated attachments' `parent_document_url`.

Known limitation: When saving a draft edition of a Consultation Outcome/Public Feedback or Call for Evidence Outcome, the `attachable_url` in AttachmentData is used to get the `parent_document_url` to be sent to Asset Manager. However, this will still return `nil`. This is because that method calls `visible_edition_for` which filters to Edition subclasses only, and neither ConsultationResponse nor CallForEvidenceResponse is an Edition. As a result, `parent_document_url` is only reliably set at publish time, not on every metadata update.

Extending `attachable_url` to handle non-edition attachables with a public URL would be great as a follow-up work.
@eYinka eYinka force-pushed the attachable-url-on-consultation-response branch from e4c0568 to 5ae5179 Compare May 20, 2026 17:33
The previous code did not work at all for policy groups, and consultation and call for evidence responses, which are not editions.

Since the access limitation restrictions should already kick in before this asset payload is constructed, there is no reason to check for visibility at this level. We have removed the calls to `visible_edition` in favour of just using the `significant_attachable`. This should correctly return either visible attachables or the draft attachable. This works correctly for all attachable types, including responses and policy groups.

In order to correctly construct the draft or live attachable URL, we need to determine if it is in draft state. Policy groups are immediately published, so this does not apply to them. For responses, we want to send the parent edition's URL, so we can check the parent state. I have made the `parent_attachable` method public, so we can identify response-like classes - this method is only defined on `ConsultationResponse` and `CallForEvidenceResponse` at the moment.

For context, the method was previously never called with a user argument to check the visibility for. The line `visible_edition.blank? && draft_edition` was particularly confusing, since the visible edition should also return the draft_edition, if called with a user. It also invalidated the whole point of ever checking for visibility, when falling back to the draft_edition anyway.
@eYinka eYinka force-pushed the attachable-url-on-consultation-response branch from 5ae5179 to 9af1987 Compare May 21, 2026 08:46
Because ConsultationResponse, CallForEvidenceResponse, and PolicyGroup are attachables that are not editionable, they don't have a parent document URL in Asset Manager. This task backfills the parent document URL for attachments associated with these attachables.

Run with `bundle exec rake backfill_parent_document_url_for_non_editionable_attachables`
@eYinka eYinka marked this pull request as ready for review May 21, 2026 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants