From 89cee2be8a0d6cbc1e8a683e0b7bf2217440e0f8 Mon Sep 17 00:00:00 2001 From: Eric Rollins Date: Tue, 29 Oct 2024 16:56:50 -0400 Subject: [PATCH] Copy over files from https://github.com/all-of-us/workbench/pull/8897 --- .../mail/EmailSubstitutionField.java | 1 + .../pmiops/workbench/mail/MailService.java | 2 + .../workbench/mail/MailServiceImpl.java | 42 +++++++++++++++++++ .../content.html | 14 ++++--- .../initial_credits_expiring/content.html | 39 +++++++++++++++++ 5 files changed, 92 insertions(+), 6 deletions(-) create mode 100644 api/src/main/resources/emails/initial_credits_expiring/content.html diff --git a/api/src/main/java/org/pmiops/workbench/mail/EmailSubstitutionField.java b/api/src/main/java/org/pmiops/workbench/mail/EmailSubstitutionField.java index aaa618f37af..a9fa7b54338 100644 --- a/api/src/main/java/org/pmiops/workbench/mail/EmailSubstitutionField.java +++ b/api/src/main/java/org/pmiops/workbench/mail/EmailSubstitutionField.java @@ -24,6 +24,7 @@ public enum EmailSubstitutionField { FIRST_NAME("FIRST_NAME"), FROM_EMAIL("FROM_EMAIL"), HEADER_IMG("HEADER_IMG"), + INITIAL_CREDITS_EXPIRATION("INITIAL_CREDITS_EXPIRATION"), INITIAL_CREDITS_RESOLUTION("INITIAL_CREDITS_RESOLUTION"), INSTITUTION_NAME("INSTITUTION_NAME"), INSTRUCTIONS("INSTRUCTIONS"), diff --git a/api/src/main/java/org/pmiops/workbench/mail/MailService.java b/api/src/main/java/org/pmiops/workbench/mail/MailService.java index 779b9619012..dc12c52c543 100644 --- a/api/src/main/java/org/pmiops/workbench/mail/MailService.java +++ b/api/src/main/java/org/pmiops/workbench/mail/MailService.java @@ -25,6 +25,8 @@ void alertUserInitialCreditsDollarThreshold( void alertUserInitialCreditsExhausted(final DbUser user) throws MessagingException; + void alertUserInitialCreditsExpiring(final DbUser user) throws MessagingException; + void alertUserAccessTierWarningThreshold( final DbUser user, long daysRemaining, Instant expirationTime, String tierShortName) throws MessagingException; diff --git a/api/src/main/java/org/pmiops/workbench/mail/MailServiceImpl.java b/api/src/main/java/org/pmiops/workbench/mail/MailServiceImpl.java index d5a110ec1cb..d2f3fab0081 100644 --- a/api/src/main/java/org/pmiops/workbench/mail/MailServiceImpl.java +++ b/api/src/main/java/org/pmiops/workbench/mail/MailServiceImpl.java @@ -80,6 +80,8 @@ public class MailServiceImpl implements MailService { "emails/initial_credits_dollar_threshold/content.html"; private static final String INITIAL_CREDITS_EXHAUSTION_RESOURCE = "emails/initial_credits_exhaustion/content.html"; + private static final String INITIAL_CREDITS_EXPIRING_RESOURCE = + "emails/initial_credits_expiring/content.html"; private static final String INSTRUCTIONS_RESOURCE = "emails/instructions/content.html"; private static final String NEW_USER_SATISFACTION_SURVEY_RESOURCE = "emails/new_user_satisfaction_survey/content.html"; @@ -224,6 +226,26 @@ public void alertUserInitialCreditsExhausted(final DbUser user) throws Messaging htmlMessage); } + @Override + public void alertUserInitialCreditsExpiring(DbUser user) throws MessagingException { + final String logMsg = + String.format( + "Sending email because initial credits are expiring soon for User %s", + userForLogging(user)); + log.info(logMsg); + + final String htmlMessage = + buildHtml( + INITIAL_CREDITS_EXPIRING_RESOURCE, initialCreditsExpiringSubstitutionMap(user)); + + sendWithRetries( + Collections.singletonList(user.getContactEmail()), + Collections.emptyList(), + "Alert - Initial credit expiration in All of Us Researcher Workbench", + logMsg, + htmlMessage); + } + @Override public void alertUserAccessTierWarningThreshold( final DbUser user, long daysRemaining, Instant expirationTime, String tierShortName) @@ -579,6 +601,18 @@ private ImmutableMap initialCreditsExpirationSub .build(); } + private ImmutableMap initialCreditsExpiringSubstitutionMap( + DbUser user) { + + return new ImmutableMap.Builder() + .put(EmailSubstitutionField.HEADER_IMG, getAllOfUsLogo()) + .put(EmailSubstitutionField.ALL_OF_US, getAllOfUsItalicsText()) + .put(EmailSubstitutionField.FIRST_NAME, user.getGivenName()) + .put(EmailSubstitutionField.USERNAME, user.getUsername()) + .put(EmailSubstitutionField.INITIAL_CREDITS_EXPIRATION, formatCondensedDateCentralTime(user.getUserInitialCreditsExpiration().getExpirationTime().toInstant())) + .build(); + } + private ImmutableMap accessTierSubstitutionMap( Instant expirationTime, DbUser user, String tierShortName) { @@ -816,6 +850,14 @@ private String formatCurrency(double currentUsage) { return NumberFormat.getCurrencyInstance().format(currentUsage); } + private String formatCondensedDateCentralTime(Instant date) { + // e.g. 04/05/2021 + return DateTimeFormatter.ofPattern("MM/dd/yyyy") + .withLocale(Locale.US) + .withZone(ZoneId.of("America/Chicago")) + .format(date); + } + private String formatDateCentralTime(Instant date) { // e.g. April 5, 2021 return DateTimeFormatter.ofPattern("MMMM d, yyyy") diff --git a/api/src/main/resources/emails/initial_credits_dollar_threshold/content.html b/api/src/main/resources/emails/initial_credits_dollar_threshold/content.html index d363f442eb9..2ce28b735b0 100644 --- a/api/src/main/resources/emails/initial_credits_dollar_threshold/content.html +++ b/api/src/main/resources/emails/initial_credits_dollar_threshold/content.html @@ -28,10 +28,12 @@ -
Hello ${FIRST_NAME} ${LAST_NAME},
-
This is a reminder that your account ${USERNAME} has used ${USED_CREDITS} in initial credits offered by the All of Us Program. - The remaining balance on your initial credits is ${CREDIT_BALANCE}.
-
Once you use all of your initial credits, you ${INITIAL_CREDITS_RESOLUTION}
-
If you have any questions about this email, please contact support@researchallofus.org.
-
Thanks for using the Researcher Workbench.
+
Hello ${FIRST_NAME},
+
This is a reminder that you have used ${USED_CREDITS} of the initial credits offered to your All of Us Researcher Workbench account ${USERNAME} by the All of Us Research Program.
+
The remaining balance of your initial credits is ${CREDIT_BALANCE}.
+
Once you use all of your initial credits, all active cloud environments will be deleted and any data from actively running analysis may be lost. Files saved to your workspace bucket and persistent disk will remain.
+ +
For resources and tips for optimizing your credit usage and setting up your billing account, visit the “Credits and Billing” section of the User Support Hub.
+
Questions?
Contact our support team by using the Help Desk widget in the Workbench or by emailing support@researchallofus.org
+
All of Us Researcher Workbench support team
diff --git a/api/src/main/resources/emails/initial_credits_expiring/content.html b/api/src/main/resources/emails/initial_credits_expiring/content.html new file mode 100644 index 00000000000..35d411b7492 --- /dev/null +++ b/api/src/main/resources/emails/initial_credits_expiring/content.html @@ -0,0 +1,39 @@ + + + + + + + + +
Hello ${FIRST_NAME},
+
This is a notification that the initial credits offered to your ${ALL_OF_US} Researcher Workbench account ${USERNAME} by the ${ALL_OF_US} Research Program are expiring soon.
+
Your initial credits will expire on ${INITIAL_CREDITS_EXPIRATION}.
+
You are eligible to request a 270-day extension under your profile in the Researcher Workbench.
+ +
For more information about using initial credits and requesting an extension, read the “Using ${ALL_OF_US} Initial Credits” article on the User Support Hub.
+
Questions?
Contact our support team by using the Help Desk widget in the Workbench or by emailing support@researchallofus.org
+
${ALL_OF_US} Researcher Workbench support team
+