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

EES-4930 Send Public API subscription notifications #5097

Merged
merged 19 commits into from
Jul 30, 2024
Merged

EES-4930 Send Public API subscription notifications #5097

merged 19 commits into from
Jul 30, 2024

Conversation

benoutram
Copy link
Collaborator

@benoutram benoutram commented Jul 25, 2024

⚠️ The tests in this PR depend on the change to make Azurite available to the Publisher function integration tests made in #5099

This PR completes the work originally started by @jack-hive to send Public API subscription notifications, building on the work also added by @jack-hive in #5043, #5076 and #5056 which allowed subscribing and unsubscribing to Public API data sets.

In this PR a new queue triggered function ApiSubscriptionFunctions.NotifySubscribers is added to Notifier.

ApiSubscriptionFunctions.NotifySubscribers function

The function expects a ApiNotificationMessage queue message as input:

{
    "dataSetId" : "00000000-0000-0000-0000-000000000000",
    "dataSetFileId" : "00000000-0000-0000-0000-000000000000",
    "version" : "1.1"
}

On receipt of this message it will send email notifications using Gov.uk Notify for all verified subscribers of the data set.

It uses FluentValidation to throw a validation exception if any of dataSetId, dataSetFileId or version in the queue message are empty.

Notification email template

The email template is personalised with the data set title, version, a link to the data set file details page, and an unsubscribe link.
It expects values for these placeholders to be provided: data_set_title, data_set_url, data_set_version, unsubscribe_url.

image

Rename Notifier functions

I standardised the naming across all of Notifier's Publication and Public API subscription functions. The full list of functions is now:

PublicationSubscriptions_RequestPendingSubscription
PublicationSubscriptions_VerifySubscription
PublicationSubscriptions_Unsubscribe
PublicationSubscriptions_NotifySubscribers
PublicationSubscriptions_RemoveExpiredSubscriptions

PublicApiSubscriptions_RequestPendingSubscription
PublicApiSubscriptions_VerifySubscription
PublicApiSubscriptions_Unsubscribe
PublicApiSubscriptions_NotifySubscribers
PublicApiSubscriptions_RemoveExpiredSubscriptions

Changes to Publisher

The publisher functions have been changed to queue a ApiNotificationMessage message on publishing of data sets.

Full list of changes

This is a record of the changes I made to complete this work.

  • Moved IApiSubscriptionTableStorageService/ApiSubscriptionTableStorageService from Notifier.Repositories to Notifier.Services.
  • Moved Constants.NotifierTableStorageTableName and Constants.NotifierQueueStorage to outer scope.
  • Formatted code and organised imports.
  • Remove the unused IOptions<AppSettingsOptions> parameter from the ApiSubscriptionRepository constructor.
  • Removed the unused FunctionContext parameter from the NotifySubscribers function.
  • Added the ApiSubscriptionNotificationId environment property to appsettings.Local.json.example and the infrastructure ARM template.
  • Renamed ApiSubscriptionStatus SubscriptionPending as Pending.
  • Changed ApiNotificationMessage Version from type SemVersion to string to simplify serialisation.
  • Added missing DataSetTitle to the fields returned in the NotifySubscribers table query, required for the email personalisation.
  • Corrected the NotifySubscribers table query to exclude Pending subscribers from being sent notifications.
  • Added validation of the ApiNotificationMessage to the NotifySubscribers function.
  • Tidied up all Public API email template variables.
  • Included DataSetFileId in ApiNotificationMessage and fixed the link to the data set file details page in the email.
  • Corrected dataSetId for dataSetFileId in DataSetFileService.GetDataSetFile and dataSetFileService.ts to avoid ambiguity.
  • Standardised function names across all Publication and Public API subscription functions.
  • Added NotifySubscribersTests function integration tests.
  • Made changes to all of the Gov.uk Notify Public API email templates consistent with the changes in this PR.
  • Added new Key Vault secret ees-notifier-templateid-api-subscription-notification to all Azure environments (EES-5359).

@benoutram benoutram changed the base branch from dev to EES-4930-Add-Azurite-To-Publisher-Tests July 25, 2024 19:39
@@ -0,0 +1,23 @@
namespace GovUk.Education.ExploreEducationStatistics.Notifier.Model;

public static class NotifierTableStorageTableNames
Copy link
Collaborator

Choose a reason for hiding this comment

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

I know it was me who named it like this, but I'm now thinking this might be better named as simply NotifierTableStorage.

And the fields inside could be renamed like:
PublicationPendingSubscriptionsTableName --> PublicationPendingSubscriptionsTable
...
...

Copy link
Collaborator Author

@benoutram benoutram Jul 29, 2024

Choose a reason for hiding this comment

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

Ah yeah, good point, I think this does make things a little tidier. I've done this renaming now as a new commit. Thanks. 🙂

@benoutram benoutram requested a review from jack-hive July 29, 2024 15:06
@benoutram benoutram force-pushed the EES-4930-Add-Azurite-To-Publisher-Tests branch from c187534 to f9a008b Compare July 29, 2024 15:36
@benoutram benoutram force-pushed the EES-4930-Add-Azurite-To-Publisher-Tests branch from f9a008b to 801eb32 Compare July 29, 2024 17:59
Base automatically changed from EES-4930-Add-Azurite-To-Publisher-Tests to dev July 30, 2024 07:29
jack-hive and others added 18 commits July 30, 2024 08:30
…s + adding messages to the queue when an API data set has a new version
…eStorageService from Notifier.Repositories to Notifier.Services
…ifyApiSubscribers function. Remove unused IOptions<AppSettingsOptions> parameter from ApiSubscriptionRepository constructor.
…e and shorten names of table name constants.
@benoutram benoutram merged commit 4c0f4f4 into dev Jul 30, 2024
7 checks passed
@benoutram benoutram deleted the EES-4930 branch July 30, 2024 08:27
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