Skip to content

Add forms specific base controller#2607

Merged
stephencdaly merged 3 commits intomainfrom
refactor-forms-controller
Mar 10, 2026
Merged

Add forms specific base controller#2607
stephencdaly merged 3 commits intomainfrom
refactor-forms-controller

Conversation

@stephencdaly
Copy link
Contributor

@stephencdaly stephencdaly commented Mar 10, 2026

What problem does this pull request solve?

Trello card: https://trello.com/c/vnpXef5W

We need to add a new form-specific after_action to the base controller to send emails to organisation admins when a draft is made of an existing form. This needs to apply to all controllers that can edit a form, as we create a draft when a change is first made to a form rather then when a specific action is performed, and we need to send the email from the controller so that we know the identity of the current user.

We don't want to further pollute WebController with form-specific code, so add a new FormsController base controller that all controllers that handle ations related to an individual form inherit from.

There was an existing controller named FormsController which has been renamed to Forms::DraftController to better describe what it does.

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?
  • Do the end to end tests need updating before these changes will pass?
  • Has all relevant documentation been updated?

This action is performed when a post request is made to the /pages
routes, so it makes sense to exist in the PagesController.
This controller is now only responsible for rendering the draft form
page. Rename it to reflect this, and move it into the Forms namespace
for consistency.
@stephencdaly stephencdaly changed the title Add base controller for controllers that deal with an individual form Add forms specific base controller Mar 10, 2026
Move form-specific methods from WebController into a new
FormsController which all controllers that handle ations related to
an individual form inherit from.

We need to add a new form-specific after_action and don't want to
further pollute WebController with form-specific code.

Move the verify_authorized after_action to the FormsController to
avoid duplication and to ensure that all form-related controllers have
authorisation checks.
@stephencdaly stephencdaly force-pushed the refactor-forms-controller branch from a8ed704 to efd1b56 Compare March 10, 2026 11:39
@sonarqubecloud
Copy link

@github-actions
Copy link

🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2607.admin.review.forms.service.gov.uk/

It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready
after 5 minutes, there may be something wrong with the ECS task. You will need to go to the integration AWS account
to debug, or otherwise ask an infrastructure person.

For the sign in details and more information, see the review apps wiki page.

Copy link
Contributor

@lfdebrux lfdebrux left a comment

Choose a reason for hiding this comment

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

I like this!

@stephencdaly stephencdaly added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit d3441b5 Mar 10, 2026
7 checks passed
@stephencdaly stephencdaly deleted the refactor-forms-controller branch March 10, 2026 13:50
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