Skip to content

Commit

Permalink
Merge pull request #2263 from alphagov/only-withdraw-draft-sections-i…
Browse files Browse the repository at this point in the history
…f-draft-present

Stop 404 when withdrawing a section on published manual
  • Loading branch information
davidgisbey authored Jan 2, 2024
2 parents f93fb57 + 073cb41 commit 1e831ae
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
10 changes: 9 additions & 1 deletion app/services/section/remove_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ def call
minor_update: attributes.fetch(:minor_update, "0"),
change_note: attributes.fetch(:change_note, ""),
}

# We need to capture the state of the section before assigning attributes.
# The Section#assign_attributes method always creates a new draft section if
# the latest edition is published.
# This causes Adapters.publishing.discard_section(section) to be called which
# blows up as there is no draft section in the Publishing API database.
draft_section = section.draft?

section.assign_attributes(change_note_params)

if section.valid?
Expand All @@ -30,7 +38,7 @@ def call
manual.save!(user)
Adapters.publishing.save_draft(manual, include_sections: false)

if section.draft?
if draft_section
Adapters.publishing.discard_section(section)
end
end
Expand Down
12 changes: 4 additions & 8 deletions features/removing-a-manual-section.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ Feature: Removing a section from a manual
Given I am logged in as a GDS editor
And a published manual exists
When I remove one of the sections from the manual
Then the section is removed from the manual
When I publish the manual
And I publish the manual
Then the removed section is not published
But the removed section is withdrawn with a redirect to the manual
And the removed section is archived
Expand All @@ -70,8 +69,7 @@ Feature: Removing a section from a manual
Given I am logged in as an editor
And a published manual exists
When I remove one of the sections from the manual
Then the section is removed from the manual
When I publish the manual
And I publish the manual
Then the removed section is not published
But the removed section is withdrawn with a redirect to the manual
And the removed section is archived
Expand All @@ -87,14 +85,12 @@ Feature: Removing a section from a manual
When I remove one of the sections from the manual with a major update omitting the note
Then I see an error requesting that I provide a change note
When I remove one of the sections from the manual with a major update
Then the section is removed from the manual
When I add another section and publish the manual later
And I add another section and publish the manual later
Then the removed section change note is included

Scenario: Removing a section with a minor update change notes
Given I am logged in as a GDS editor
And a published manual exists
When I remove one of the sections from the manual with a minor update
Then the section is removed from the manual
When I add another section and publish the manual later
And I add another section and publish the manual later
Then the removed section change note is not included

0 comments on commit 1e831ae

Please sign in to comment.