Skip to content

[WHIT-2990] Change news article lead image payload from image to images with type#11189

Open
lauraghiorghisor-tw wants to merge 2 commits intomainfrom
change-payload-for-lead-images
Open

[WHIT-2990] Change news article lead image payload from image to images with type#11189
lauraghiorghisor-tw wants to merge 2 commits intomainfrom
change-payload-for-lead-images

Conversation

@lauraghiorghisor-tw
Copy link
Contributor

@lauraghiorghisor-tw lauraghiorghisor-tw commented Feb 27, 2026

Change news article lead image payload from single image to images of 'type' lead, with 'sources'

To ensure a consistent image payload across types, we are bringing the lead image payload in line with that of the other non-embeddable images, such as topical events' headers and logos, and history pages' sidebar.

The change is from sending a singular details.image to sending details.images with a type to identify the usage, and a hash of sources corresponding to the various image variants, rather than the url, high_resolution_url, medium_resolution_url we were sending prior. Since the code is scoped to config-driven document types, this change only affects news articles. History pages have been dealt with separately, and republished.

This change is accompanied by changes in publishing API, Frontend, and the metadata component (which looks for a url). All these changes will require a 2-step release: an expand to allow both payloads, then a contract after republishing. All news articles will require republishing for the change to take effect.

Note on the payload specifics:

  • We have agreed with Frontend owners that, in order to keep the API consistent, and the FE code relatively simple, we will send the sources hash with all the variant keys, even for cases where the image is not truly "versioned". In the case of lead images, that's the placeholder image, which we now send replicated for all the versions ("default" kind's versions: s960, s712, s630, s465, s300, s216). This also ensures the system can expand in the future, if we then provide a versioned placeholder image. This is in line with what we do for svg images elsewhere, which only generate one asset variant.

Note on FeaturedImageData changes:

  • I had to compute a sources payload for the FeaturedImageData since that's the model underlying the fallback organisation image. The publishing_api_details method sits on the Image model for regular images, so it would have made sense to put it on the "parent" model for FeaturedImageData as well, i.e. Organisation in this case. Nonetheless, there are many models using this _Data class, not just Organisation, so it is more convenient to place it straight on the FeaturedImageData for the time being.
  • We can reconsider this at a later stage when more FeatureImageData usages need to be made consistent with this new payload shape, so I have made no attempts to unify concerns at this point.

Release/republish plan

Must ensure that all News Articles have been updated while republishing, otherwise we can't merge the contract PR on FE.

Testing

Scenario Before code merge After code merge
Edition already published, custom image, before bulk republish - no change 2b 2a
Draft edition, org default image, before bulk republish - no change 3 b draft edition before republciation 3a
Draft edition, org default image, republished - payload changed, no visible changes 4b org image draft state after republish 4a
Published, custom image, republished, payload changed, no visible changes 5b published with custom image 5a
Published, placeholder image, republished - payload changed, no visible changes 6b placeholder 6a
New draft from published, no republication step - payload changed, no visible changes 7b before rep 7a
the new draft

Jira

@lauraghiorghisor-tw lauraghiorghisor-tw changed the title Change news article lead image payload from single image to images of… [WHIT-2990] Change news article lead image payload from single image to images of… Feb 27, 2026
@lauraghiorghisor-tw lauraghiorghisor-tw changed the title [WHIT-2990] Change news article lead image payload from single image to images of… [WHIT-2990] Change news article lead image payload from image to images with type Mar 2, 2026
@lauraghiorghisor-tw lauraghiorghisor-tw force-pushed the change-payload-for-lead-images branch 6 times, most recently from d663312 to d6d2365 Compare March 6, 2026 15:44
assert_equal expected_payload, edition.lead_image_payload(lead_usage)
end

test "#lead_image_payload does not include a caption, if caption is nil" do
Copy link
Contributor Author

@lauraghiorghisor-tw lauraghiorghisor-tw Mar 6, 2026

Choose a reason for hiding this comment

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

This is changing now, since we are always sending the caption. As far as I can tell, it makes no difference to FE, and it's now been allowed in publishing API -> alphagov/publishing-api#3924. This is consistent with the "intention" introduced by the "caption_enabled" configuration, i.e. "no caption key" should mean it is disabled, and "nil caption" should mean it is enabled but - intentionally - missing.

Previously we were using this definition instead, which allowed null, but we were always dropping the nulls in whitehall anyway by using compact on the payload, so that did not make much sense.

{
high_resolution_url: placeholder_image_url,
url: placeholder_image_url,
sources: Whitehall.image_kinds.fetch("default").versions.map { |v| [v.name.to_sym, placeholder_image_url] }.to_h,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replicating this same url as was agreed to do, like we do with svgs as well.

high_resolution_url: default_lead_image.url(:s960),
url: default_lead_image.url(:s300),
}
return default_lead_image.publishing_api_details.merge(type: lead_image_usage.key, caption: nil)
Copy link
Contributor Author

@lauraghiorghisor-tw lauraghiorghisor-tw Mar 6, 2026

Choose a reason for hiding this comment

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

I don't know (yet) what we want to do with FeatureImageData so I only added sources and content_type to that method, preferring to inject type and caption here. That model does not have type yet, nor caption directly. Caption is provided on some of the models that use FeatureImageData (such as Feature), but not on Organisation, which we care about here.

Copy link
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.

LGTM 👍

This will be used in a future commit to compute the lead image payload. `FeaturedImageData` is the model used for the organisation default news image, which is used as a lead image fallback.

The `publishing_api_details` method sits on the `Image` model for regular images, so it would have made sense to put it on the "parent" model for `FeaturedImageData`, i.e. `Organisation` in this case. Nonetheless, there are many models using this `_Data` class, not just `Organisation`, so it is more convenient to place it straight on the `FeaturedImageData` for the time being.

We can reconsider this at a later stage when more `FeatureImageData` usages need to be made consistent with this new payload shape, so I have made no attempts to unify concerns at this point.
… 'type' lead, with 'sources'

To ensure a consistent image payload across types, we are bringing the lead image payload in line with that of the other non-embeddable images, such as topical events' headers and logos, and history pages' sidebar.

The change is from sending a singular `details.image` to sending `details.images` with a `type` to identify the `usage`, and a hash of `sources` corresponding to the various image variants, rather than the `url`, `high_resolution_url`, `medium_resolution_url` we were sending prior. Since the code is scoped to config-driven document types, this change only affects news articles. History pages have been dealt with separately, and republished.

This change is accompanied by changes in publishing API, Frontend, and the metadata component (which looks for a url). All these changes will require a 2-step release: an expand to allow both payloads, then a contract after republishing. All news articles will require republishing for the change to take effect.

Note on the payload specifics:
- We have agreed with Frontend owners that, in order to keep the API consistent, and the FE code relatively simple, we will send the `sources` hash with all the variant keys, even for cases where the image is not truly "versioned". In the case of lead images, that's the placeholder image, which we now send replicated for all the versions ("default" kind's versions: s960, s712, s630, s465, s300, s216). This also ensures the system can expand in the future, if we then provide a versioned placeholder image. This is in line with what we do for svg images elsewhere, which only generate one asset variant.
@lauraghiorghisor-tw lauraghiorghisor-tw force-pushed the change-payload-for-lead-images branch from 600d89a to 5558a04 Compare March 11, 2026 09:37
person.image.republish_on_assets_ready
end

test "#publishing_api_payload returns image sources and content type" do
Copy link
Contributor

Choose a reason for hiding this comment

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

This is still a thing to do I think?

Suggested change
test "#publishing_api_payload returns image sources and content type" do
test "#publishing_api_details returns image sources and content type" do

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.

2 participants