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

Change condition model to delete secondary skip routes when skip route is deleted #686

Merged
merged 1 commit into from
Feb 10, 2025

Conversation

lfdebrux
Copy link
Member

@lfdebrux lfdebrux commented Feb 6, 2025

What problem does this pull request solve?

Trello card: https://trello.com/c/iMnMgYPr/2106-deleting-a-route-should-delete-the-secondary-skip-route-for-the-same-question

Currently deleting a skip route for a question that has a secondary skip route puts the form in a state where there is an invalid route that can’t be deleted.

We've decided to fix this by making it so that deleting a route for a page also deletes any secondary skip routes for that page.

Because routes and associations between conditions are directly expressed in our model, we need to jump through some hoops to make this work. This commit adds a before_destroy callback to take care of things.

Things to consider when reviewing

  • Ensure that you consider the wider context.
  • Does it work when run on your machine?
  • Is it clear what the code is doing?
  • Do the commit messages explain why the changes were made?
  • Are there all the unit tests needed?
  • Has all relevant documentation been updated?

lfdebrux added a commit to alphagov/forms-admin that referenced this pull request Feb 6, 2025
Currently (when branching is enabled) deleting a skip route for a
question that has a secondary skip route puts the form in a state where
there is a route with an error that can’t be deleted.

We do want users to be able to delete individual routes for a question.

So we’ve agreed that we will delete the secondary skip for a question
when deleting any other routes for that question. And we’ll let the user
know before the delete a route, with a warning.

This commit adds the warning; note that the deletion will take place in
forms-api, see alphagov/forms-api#686. To enable this we add a method
`#has_secondary_skip?` to the DeleteConfirmationInput object... I'm not
sure if this is the best place for this, but it'll do for now.
@lfdebrux lfdebrux force-pushed the ldeb-change-delete-condition branch 2 times, most recently from 9961ffd to 6694009 Compare February 6, 2025 10:50
lfdebrux added a commit to alphagov/forms-admin that referenced this pull request Feb 6, 2025
Currently (when branching is enabled) deleting a skip route for a
question that has a secondary skip route puts the form in a state where
there is a route with an error that can’t be deleted.

We do want users to be able to delete individual routes for a question.

So we’ve agreed that we will delete the secondary skip for a question
when deleting any other routes for that question. And we’ll let the user
know before the delete a route, with a warning.

This commit adds the warning; note that the deletion will take place in
forms-api, see alphagov/forms-api#686. To enable this we add a method
`#has_secondary_skip?` to the DeleteConfirmationInput object... I'm not
sure if this is the best place for this, but it'll do for now.
lfdebrux added a commit to alphagov/forms-admin that referenced this pull request Feb 7, 2025
Currently (when branching is enabled) deleting a skip route for a
question that has a secondary skip route puts the form in a state where
there is a route with an error that can’t be deleted.

We do want users to be able to delete individual routes for a question.

So we’ve agreed that we will delete the secondary skip for a question
when deleting any other routes for that question. And we’ll let the user
know before the delete a route, with a warning.

This commit adds the warning; note that the deletion will take place in
forms-api, see alphagov/forms-api#686. To enable this we add a method
`#has_secondary_skip?` to the DeleteConfirmationInput object... I'm not
sure if this is the best place for this, but it'll do for now.
Copy link
Contributor

@jamie-o-wilkinson jamie-o-wilkinson left a comment

Choose a reason for hiding this comment

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

Have talked this through with @lfdebrux, all looks good to me 👍

lfdebrux added a commit to alphagov/forms-admin that referenced this pull request Feb 10, 2025
Currently (when branching is enabled) deleting a skip route for a
question that has a secondary skip route puts the form in a state where
there is a route with an error that can’t be deleted.

We do want users to be able to delete individual routes for a question.

So we’ve agreed that we will delete the secondary skip for a question
when deleting any other routes for that question. And we’ll let the user
know before the delete a route, with a warning.

This commit adds the warning; note that the deletion will take place in
forms-api, see alphagov/forms-api#686. To enable this we add a method
`#has_secondary_skip?` to the DeleteConfirmationInput object... I'm not
sure if this is the best place for this, but it'll do for now.
…e is deleted

Currently deleting a skip route for a question that has a secondary skip
route puts the form in a state where there is an invalid route that
can’t be deleted.

We've decided to fix this by making it so that deleting a route for a
page also deletes any secondary skip routes for that page.

Because routes and associations between conditions are directly
expressed in our model, we need to jump through some hoops to make this
work. This commit adds a before_destroy callback to take care of things.
@lfdebrux lfdebrux force-pushed the ldeb-change-delete-condition branch from 6694009 to e4b9f09 Compare February 10, 2025 14:10
@lfdebrux lfdebrux merged commit b5f3f05 into main Feb 10, 2025
4 checks passed
@lfdebrux lfdebrux deleted the ldeb-change-delete-condition branch February 10, 2025 14:28
lfdebrux added a commit to alphagov/forms-admin that referenced this pull request Feb 13, 2025
We've found that in production the "delete all routes" journey has
stopped working properly; after the user confirms that they want to
delete all routes for a question, they see an error page rather than
being redirected to the "add and edit questions" page as expected.

Debugging locally revealed this is an unintended side-effect of an
unrelated change in forms-api, in PR alphagov/forms-api#686, which
changes the conditions model to delete secondary skip routes when a
skip route is deleted.

Because the process to delete all routes deletes the primary condition
before the secondary skip, when it comes to delete the secondary skip
that no longer exists, and the API responds with a 404. This 404 is then
parlayed by ActiveResource into a ResourceNotFound exception, which then
bubbles up to the Rails middleware, and is treated as a record not found
error, and Rails renders a 404 error page.

This commit adds a test that simulates this interaction, so we can make
some changes in our system to handle the scenario better.
lfdebrux added a commit to alphagov/forms-admin that referenced this pull request Feb 13, 2025
We've found that in production the "delete all routes" journey has
stopped working properly; after the user confirms that they want to
delete all routes for a question, they see an error page rather than
being redirected to the "add and edit questions" page as expected.

Debugging locally revealed this is an unintended side-effect of an
unrelated change in forms-api, in PR alphagov/forms-api#686, which
changes the conditions model to delete secondary skip routes when a
skip route is deleted.

Because the process to delete all routes deletes the primary condition
before the secondary skip, when it comes to delete the secondary skip
that no longer exists, and the API responds with a 404. This 404 is then
parlayed by ActiveResource into a ResourceNotFound exception, which then
bubbles up to the Rails middleware, and is treated as a record not found
error, and Rails renders a 404 error page.

This commit adds a test that simulates this interaction, so we can make
some changes in our system to handle the scenario better.
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