Skip to content

Commit 306219f

Browse files
committed
Fix parent_document_url not being sent to asset manager for consultation outcome attachments
When a consultation is published, PublishAttachmentAssetJob updates each attachment's metadata in asset manager. For attachments belonging to a Consultation Outcome, `parent_document_url` was never sent because the job guards with `respond_to?(:public_url)` and Consultation Response did not implement that method. I've extended ConsultationResponse, so the parent consultation's public URL is used as `parent_document_url`. Known limitation: `attachable_url` in AttachmentData is used by `AssetManagerAttachmentMetadataJob` when an attachment is saved or updated on a draft consultation. The `parent_document_url` sent to asset manager will still be `nil` in such case. This is because `visible_edition_for` filters to Edition subclasses only, and ConsultationResponse is not an Edition. 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.
1 parent e028374 commit 306219f

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

app/models/consultation_response.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ def access_limited_object
3333

3434
delegate :unpublishing, to: :parent_attachable
3535

36+
delegate :public_url, to: :parent_attachable
37+
3638
def can_order_attachments?
3739
true
3840
end

test/unit/app/sidekiq/publish_attachment_asset_job_test.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,26 @@ class PublishAttachmentAssetJobTest < ActiveSupport::TestCase
5959
job.perform(attachment_data.id)
6060
end
6161
end
62+
63+
context "attachment belongs to a consultation outcome" do
64+
let(:consultation) { create(:published_consultation, title: "my-consultation") }
65+
let(:outcome) { create(:consultation_outcome, consultation:) }
66+
let(:attachment_data) { create(:attachment_data, attachable: outcome) }
67+
let(:attachment) { create(:file_attachment, attachable: outcome, attachment_data:) }
68+
69+
before do
70+
attachment_data.attachments = [attachment]
71+
attachment_data.save!
72+
end
73+
74+
it "updates the asset with the parent consultation's public URL" do
75+
AssetManager::AssetUpdater.expects(:call).with(
76+
asset_manager_id,
77+
{ "draft" => false, "parent_document_url" => "https://www.test.gov.uk/government/consultations/my-consultation" },
78+
)
79+
80+
job.perform(attachment_data.id)
81+
end
82+
end
6283
end
6384
end

0 commit comments

Comments
 (0)