Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop 404 when withdrawing a section on published manual #2263

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

davidgisbey
Copy link
Contributor

@davidgisbey davidgisbey commented Dec 20, 2023

Description

When a manual is published all it's sections are published as well. Published sections retain a published state except in 2 circumstances.

  1. they are edited at which point they come drafts
  2. they are withdrawn at which point they're removed from the manual in the Manuals Publisher DB

If they are edited a draft section is pushed downstream to Publishing API and the Draft Content Store.

When this occurs and the section is withdrawn, we need to discard the draft Section from Publishing API.

There's some logic to handle this in the remove_service which checks to see if the section is a draft (i.e. has a draft edition in Publishing API) and if so it attempts to discard the draft.

However, there's an issue with this. Within the remove service assign_attributes is called on the section. If you go and have a look at the method defined in the Section model, you can see that it actually creates a new draft
section when called on a published section. It then passes change note params to the new draft edition of the section.

This means that when #draft? is called on the section it will always return true. This causes an issue when the following is called:

```
if section.draft?
  Adapters.publishing.discard_section(section)
end
```

Publiishing API blows up as there is no draft section in the Publishing API database.

There are feature specs which explicitly cover that the section is removed when Published sections are withdrawn. The proposed fix of capturing the state prior so assign_attributes being called breaks these tests.

I'm pretty sure that the tests are actually testing the incorrect behaviour which is causing the bug though.

At first glance I thought it might be possible to not bother creating a new draft edition prior to removing the section from the manual, but it's actually required for capturing the change note the user inputs so that users can see why the section was removed.

When an edition is published downstream, any change notes are pulled from removed sections and added as PublicationLogs

These are then rendered on the frontend.

Trello card

https://trello.com/c/GMy5HBPv/1830-fix-manual-section-withdrawal-error-caused-by-missing-draft-in-publishing-api

⚠️ This repo is Continuously Deployed: make sure you follow the guidance ⚠️

Follow these steps if you are doing a Rails upgrade.

@davidgisbey davidgisbey force-pushed the only-withdraw-draft-sections-if-draft-present branch 5 times, most recently from 586e2f5 to 02b778b Compare December 20, 2023 15:53
@davidgisbey davidgisbey force-pushed the only-withdraw-draft-sections-if-draft-present branch 2 times, most recently from 08fb8c4 to 88bc7c2 Compare December 28, 2023 13:10
When a manual is published all sections are published as well.
Post publication sections retain a published state expect in 2
circumstances.

1. they are edited
2. they are withdrawn

If they are edited a draft section is pushed downstream to Publishing API
and the Draft Content Store.

When the section is withdrawn, we need to discard the draft from Publishing
API.

There's some logic to handle this in the remove_service which checks to
see if the section is a draft (i.e. has a draft edition in Publishing API)
and if so it attempts to discard the draft.

However, there's an issue with this. Within the remove service assign_attributes
is called on the section. If you go and have a look at the method defined
in the Section model, you can see that it actually creates a new draft
section when called if the latest edition is published. It then passes
change note params to the new draft edition of the section.

This means that when #draft? is called on the section it will always return true.
This causes an issue when the following is called:

```
if section.draft?
  Adapters.publishing.discard_section(section)
end
```

There blows up when a section was in a published state prior to the
remove_service being called as there is no draft section in the Publishing
API database.

There are feature specs which explicity cover that the section is removed
when Published sections are withdrawn. The proposed fix of capturing
the state prior so assign_attributes being called breaks these tests.

I'm pretty sure that the tests are actually testing the incorrect behaviour
which is causing the bug though.

At first glance I thought it might be possible to not bother creating a new
draft edition prior to removing the section from the manual, but it's actually
required for capturing the change note the user inputs so that users can see
why the section was removed.

When an edition is published downstream, any change notes
are pulled from removed sections added as PublicationLogs
These are then rendered on the frontend.
@davidgisbey davidgisbey force-pushed the only-withdraw-draft-sections-if-draft-present branch from 88bc7c2 to 073cb41 Compare December 28, 2023 13:14
@davidgisbey davidgisbey marked this pull request as ready for review January 2, 2024 10:02
Copy link
Contributor

@ryanb-gds ryanb-gds left a comment

Choose a reason for hiding this comment

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

Good short term fix, thanks!

@davidgisbey davidgisbey merged commit 1e831ae into main Jan 2, 2024
11 checks passed
@davidgisbey davidgisbey deleted the only-withdraw-draft-sections-if-draft-present branch January 2, 2024 10:51
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