Skip to content

Commit 2bdc282

Browse files
committed
Fix parent_document_url not being sent to asset manager for response-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.
1 parent e028374 commit 2bdc282

3 files changed

Lines changed: 67 additions & 0 deletions

File tree

app/models/call_for_evidence_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

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: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,68 @@ 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
83+
84+
context "attachment belongs to a consultation public feedback" do
85+
let(:consultation) { create(:published_consultation, title: "my-consultation") }
86+
let(:public_feedback) { create(:consultation_public_feedback, consultation:) }
87+
let(:attachment_data) { create(:attachment_data, attachable: public_feedback) }
88+
let(:attachment) { create(:file_attachment, attachable: public_feedback, attachment_data:) }
89+
90+
before do
91+
attachment_data.attachments = [attachment]
92+
attachment_data.save!
93+
end
94+
95+
it "updates the asset with the parent consultation's public URL" do
96+
AssetManager::AssetUpdater.expects(:call).with(
97+
asset_manager_id,
98+
{ "draft" => false, "parent_document_url" => "https://www.test.gov.uk/government/consultations/my-consultation" },
99+
)
100+
101+
job.perform(attachment_data.id)
102+
end
103+
end
104+
105+
context "attachment belongs to a call for evidence outcome" do
106+
let(:call_for_evidence) { create(:published_call_for_evidence, title: "my-call-for-evidence") }
107+
let(:outcome) { create(:call_for_evidence_outcome, call_for_evidence:) }
108+
let(:attachment_data) { create(:attachment_data, attachable: outcome) }
109+
let(:attachment) { create(:file_attachment, attachable: outcome, attachment_data:) }
110+
111+
before do
112+
attachment_data.attachments = [attachment]
113+
attachment_data.save!
114+
end
115+
116+
it "updates the asset with the parent call for evidence's public URL" do
117+
AssetManager::AssetUpdater.expects(:call).with(
118+
asset_manager_id,
119+
{ "draft" => false, "parent_document_url" => "https://www.test.gov.uk/government/calls-for-evidence/my-call-for-evidence" },
120+
)
121+
122+
job.perform(attachment_data.id)
123+
end
124+
end
62125
end
63126
end

0 commit comments

Comments
 (0)