Skip to content

[WHIT-3020] Fix and backfill preview-token propagation for response forms and cropped images#11555

Open
TonyGDS wants to merge 3 commits into
mainfrom
whit-3020-backfill-cfe-auth-bypass
Open

[WHIT-3020] Fix and backfill preview-token propagation for response forms and cropped images#11555
TonyGDS wants to merge 3 commits into
mainfrom
whit-3020-backfill-cfe-auth-bypass

Conversation

@TonyGDS

@TonyGDS TonyGDS commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Part 1 of 3 for WHIT-3020 (opt-in preview tokens). Base of the stack#11543 and #11542 build on this.

What

This is the base of the preview-token stack. It fixes two pre-existing gaps where a draft edition's auth_bypass_id was never written to some of its assets in Asset Manager — so the preview link did not grant access to them — and then backfills existing drafts into a consistent state.

  1. Call for evidence response forms. When a preview link is generated/regenerated, the auth_bypass_id was propagated to attachment and image assets, and to consultation response forms, but not to call for evidence response form (or outcome attachment) assets. The fix adds the call for evidence branch to EditionAuthBypassUpdater, mirroring the existing consultation handling.

  2. Cropped images. Uploading via the create path already snapshots the token onto new image assets. But cropping/replacing an image builds a fresh ImageData and saves it before linking it to the image, so ImageData#auth_bypass_ids (which walks images to the edition) returns [] and the cropped asset is created token-less. Since single-usage and oversized images are forced through cropping, the displayed asset ended up without the token. The fix links the image before saving, mirroring the create path's existing workaround.

  3. Backfill. The fixes above only repair assets going forward. A data migration propagates each pre-publication edition's existing auth_bypass_id to its image assets, and — for call for evidence — its response form and outcome attachment assets.

Why the migration enqueues jobs directly

The migration enqueues AssetManagerUpdateAssetJob itself rather than reusing EditionAuthBypassUpdater. That service regenerates the token (set_auth_bypass_id) as part of its flow. Minting a new id would invalidate any preview link publishers have already shared, which is the opposite of what the backfill needs — we want to preserve the existing id and only repair the assets.

EditionAuthBypassUpdater pushed the edition's auth bypass id to file
attachments, images and consultation response forms and outcomes, but
not to call for evidence response forms or outcome attachments. As a
result, generating or regenerating a preview link on a call for evidence
never updated its response form asset in Asset Manager.

Add update_call_for_evidence_attachments, bringing call for evidence
into line with consultations.
When a publisher crops (or replaces the file of) an edition image, the
update action builds a fresh ImageData and saves it before linking it to
the image. At save time the new ImageData has no images, so
ImageData#auth_bypass_ids - which walks images to their edition - returns
an empty array, and the cropped asset is created in Asset Manager with no
auth_bypass_id. The edition's preview link therefore does not grant
access to the cropped image, even though the edition carries a token.

The create action already works around this by pushing the image onto the
new ImageData's images association before saving, so auth_bypass_ids is
discoverable. Do the same in the crop branch of the update action.
@TonyGDS TonyGDS force-pushed the whit-3020-backfill-cfe-auth-bypass branch from c6d23b1 to ce3d9c1 Compare June 12, 2026 15:08
@TonyGDS TonyGDS changed the title [WHIT-3020] Backfill auth bypass ids onto call for evidence response form assets [WHIT-3020] Fix and backfill preview-token propagation for response forms and cropped images Jun 12, 2026
@TonyGDS TonyGDS force-pushed the whit-3020-backfill-cfe-auth-bypass branch from ce3d9c1 to 4ccffe7 Compare June 12, 2026 15:18
The preceding commits fix auth bypass id propagation going forward for
call for evidence response forms and cropped images, but existing
pre-publication editions already carry an auth_bypass_id whose value was
never written to some of their assets in Asset Manager - cropped image
assets, and call for evidence response form (and outcome attachment)
assets. As a result the preview link for those drafts does not grant
access to the affected assets.

This data migration propagates each pre-publication edition's existing
auth_bypass_id to its image assets, and - for call for evidence - its
response form and outcome attachment assets, bringing them into a
consistent state before the rest of the preview token work is built on
top.

It enqueues AssetManagerUpdateAssetJob directly rather than reusing
EditionAuthBypassUpdater, because that service regenerates the token
(set_auth_bypass_id). Minting a new id would invalidate any preview link
publishers have already shared, which is the opposite of what the
backfill needs - we want to preserve the existing id and only repair the
assets.
@TonyGDS TonyGDS force-pushed the whit-3020-backfill-cfe-auth-bypass branch from 4ccffe7 to 51b99f2 Compare June 12, 2026 15:48
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.

1 participant