First published at validation 3.0 [WHIT-3076]#11473
Open
davidsauntson wants to merge 8 commits into
Open
Conversation
It was possible to set the `first_published_date` to any time before the present, which allowed users to backdate the `first_published_at` date so it came _after_ the first change note. The causes some undesireable behaviour, including a confusing ordering in the list of events in the 'See all updates' section of a rendered page. Adds validation to the `Edition` model so that the `first_published_at` date cannot be overriden to come after the date of the earliest change note (`major_change_published_at`) on associated editions. (cherry picked from commit c1ea53c)
In some validation cases, calling `edition.other_editions` raises a `NoMethodError` exception because there is no associated `document` object for that `edition`. This commit adds a guard clause to the `#other_editions` method so that it returns an empty array instead of raising an exception. (cherry picked from commit b47e065)
…ror messages The `first_published_preceeds_change_notes` validation caused two contradictory error messages when the `first_published_at` date was set to the future on editions with `change_notes`, ie: - "First published date must be between 01/01/1900 and the present" - "First published must be before the first change note (<change note date>)" This change fixes this by only running the `first_published_at, inclusion` validation if there are no `other_editions` present for the draft edition in question. The guard clause was added to `#other_editions` that returns an empty array instead of `nil`, so that `.empty?` can be used in the inline attribute validation. (cherry picked from commit 997ab2b)
The `#first_published_preceeds_change_notes` error message presents the date of the earliest change note to users. In production, this caused a problem where a user backdated an edition into a previous government, entered history mode and then did not have permissions to edit or delete the draft edition (see https://govuk.zendesk.com/agent/tickets/6565061). This change introduces validation that ensures the `first_published_at` date is after the start of the current government. This is only applied to non-political and non-historic editions so that users with the correct privileges can still edit those editions as required. (cherry picked from commit 54ed806)
Since we can no longer create editions with a `first_published_at` before the start of the current government, some tests that use FactoryBot's `create` method fail validation. This change makes these tests use `#build` instead of `#create`, since this does not run validation. The tests don't need the validation or persistence of the `#create` brings. (cherry picked from commit 69d3043)
Since we can no longer create editions with `first_published_at` dates before the start of the current government, and the behavioural tests create governments starting when the tests are run, some of the behavioural tests fail. This change allows the tests to pass by changing the default `first_published_at` date to `today`. (cherry picked from commit 78bd24b)
Users trying to edit previously published, historic documents are unable to do so if the `first_published_at` date was (correctly) updated in the past, since the validation prevents them from saving. This caused a minor production incident. This change partially fixes that by ensuring we check `first_published_at` validity compared to government and change note dates when the attribute has been changed.
…or political editions Users trying to edit previously published, historic documents are unable to do so if the `first_published_at` date was (correctly) updated in the past, since the validation prevents them from saving. This caused a minor production incident. This commit (along with the previous one) fixes this by ensuring the `first_published_preceeds_change_notes` validation doesn't run on historic or political editions.
0c049b3 to
7499523
Compare
ChrisBAshton
approved these changes
May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Users trying to edit previously published, historic documents are unable to do so if the
first_published_atdate was (correctly) updated in the past, since the validation prevents them from saving. This caused a minor production incident.These changes fix that by building on #11429 and #11393 to ensure the validation is only applied when:
first_published_atdate has actually changedThese changes are in the last two commits: b7f9001 and 0c049b3
This application is owned by the Whitehall Experience team. Please let us know in #govuk-whitehall-experience-tech when you raise any PRs.
Follow these steps if you are doing a Rails upgrade.