Send alert emails to organisation admins when forms change state#2613
Merged
stephencdaly merged 10 commits intomainfrom Mar 12, 2026
Merged
Send alert emails to organisation admins when forms change state#2613stephencdaly merged 10 commits intomainfrom
stephencdaly merged 10 commits intomainfrom
Conversation
ff85fdd to
d162b11
Compare
c125ce4 to
979317a
Compare
7d4893e to
6066b63
Compare
Add a service with a method to send the appropriate email when a form is made live. The email to send depends on the previous state of the form, and whether the form is a copy if it was in the 'draft' state.
When a form is made live, call the OrgAdminAlertsService to send the appropriate alerts to org admins. This is done in the controller as we need to know the user making the change to include in the alert.
There is a separate controller for making an archived form live agin without changes. When the form is unarchived, send the appropriate alerts to org admins.
Add a method that calls the correct mailer to send an email to organisation admins when a new draft form is created. The mailer to user depends on whether the form is a copy of another form or not.
When a new form is successfully created, call the OrgAdminAlerService to send an email to all organisation admins. The controller does not need to check if the group is active, as the service does this.
When a form is successfully copied, call the OrgAdminAlerService to send an email to all organisation admins. The controller does not need to check if the group is active, as the service does this.
Add a method that sends an email to all organisation admins when a draft of a live or archived form is created. We do not need to check whether the group is active in this case, as the group would need to be active for the form to have been made live.
Send an email to organisation admins when a draft is created for an existing live or archived form. This is added as an after_action in the FormsController base controller as any controller action that updates a form will create a draft if the form is currently in a live or archived state. We need to store the initial state of the form in the controller to compare to in the after_action to determine if a draft was created. This is because the form could have been updated in a separate instance of the Form model, which is the case when adding a new question to the form - so we cannot use the `state_previously_was` helper method provided by ActiveModel::Dirty. As all controllers that inherit from FormsController use the `current_form`, we can set the instance variable in a before_action along with the @initial_form_state. This makes the controller tests for FormsController redundant as they were just checking the that form was only retrieved once.
The FeatureService stubbing didn't work with the new feature flag that had been added, so set the feature flag using RSpec metadata instead.
6066b63 to
3799172
Compare
|
|
🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2613.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 For the sign in details and more information, see the review apps wiki page. |
SamJamCul
approved these changes
Mar 12, 2026
Contributor
SamJamCul
left a comment
There was a problem hiding this comment.
Looking good, I think this does everything we need
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.



What problem does this pull request solve?
Trello card: https://trello.com/c/vnpXef5W
Send emails to all organisation admins for the state changes we care about if the feature flag is enabled.
These are as follows:
Things to consider when reviewing