Skip to content

Commit ce3d9c1

Browse files
committed
Backfill auth bypass ids onto existing draft edition assets
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.
1 parent 7ec3011 commit ce3d9c1

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
editions = Edition
2+
.where(state: Edition::PRE_PUBLICATION_STATES)
3+
.where.not(auth_bypass_id: nil)
4+
5+
asset_count = 0
6+
7+
editions.find_each do |edition|
8+
new_attributes = { "auth_bypass_ids" => [edition.auth_bypass_id] }
9+
10+
if edition.respond_to?(:images)
11+
edition.images.each do |image|
12+
AssetManagerUpdateAssetJob.perform_async_in_queue(
13+
"asset_manager_updater",
14+
"ImageData",
15+
image.image_data.id,
16+
new_attributes,
17+
)
18+
asset_count += 1
19+
end
20+
end
21+
22+
next unless edition.is_a?(CallForEvidence)
23+
24+
response_form = edition.call_for_evidence_participation&.call_for_evidence_response_form
25+
if response_form&.call_for_evidence_response_form_data.present?
26+
AssetManagerUpdateAssetJob.perform_async_in_queue(
27+
"asset_manager_updater",
28+
"CallForEvidenceResponseFormData",
29+
response_form.call_for_evidence_response_form_data.id,
30+
new_attributes,
31+
)
32+
asset_count += 1
33+
end
34+
35+
next if edition.outcome.blank?
36+
37+
edition.outcome.attachments.files.each do |file_attachment|
38+
AssetManagerUpdateAssetJob.perform_async_in_queue(
39+
"asset_manager_updater",
40+
"AttachmentData",
41+
file_attachment.attachment_data.id,
42+
new_attributes,
43+
)
44+
asset_count += 1
45+
end
46+
end
47+
48+
puts "Enqueued auth bypass propagation for #{asset_count} draft edition assets"

0 commit comments

Comments
 (0)