Skip to content

Commit

Permalink
Copy over files from #8897
Browse files Browse the repository at this point in the history
  • Loading branch information
evrii committed Oct 29, 2024
1 parent 2fc7cf4 commit 89cee2b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
2 changes: 2 additions & 0 deletions api/src/main/java/org/pmiops/workbench/mail/MailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
42 changes: 42 additions & 0 deletions api/src/main/java/org/pmiops/workbench/mail/MailServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -579,6 +601,18 @@ private ImmutableMap<EmailSubstitutionField, String> initialCreditsExpirationSub
.build();
}

private ImmutableMap<EmailSubstitutionField, String> initialCreditsExpiringSubstitutionMap(
DbUser user) {

return new ImmutableMap.Builder<EmailSubstitutionField, String>()
.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<EmailSubstitutionField, String> accessTierSubstitutionMap(
Instant expirationTime, DbUser user, String tierShortName) {

Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
</head>
<body>
<img src="${HEADER_IMG}">
<div>Hello ${FIRST_NAME} ${LAST_NAME},</div>
<div>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}.</div>
<div>Once you use all of your initial credits, you ${INITIAL_CREDITS_RESOLUTION}</div>
<div>If you have any questions about this email, please contact [email protected].</div>
<div>Thanks for using the Researcher Workbench.</div>
<div>Hello ${FIRST_NAME},</div>
<div>This is a reminder that you have used ${USED_CREDITS} of the initial credits offered to your <i>All of Us</i> Researcher Workbench account ${USERNAME} by the <i>All of Us</i> Research Program.</div>
<div style="font-weight:bold">The remaining balance of your initial credits is ${CREDIT_BALANCE}.</div>
<div><i>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.</i></div>

<div>For resources and tips for optimizing your credit usage and setting up your billing account, visit the “<a href="https://support.researchallofus.org/hc/en-us/categories/5942730401428">Credits and Billing</a>” section of the User Support Hub.</div>
<div><div style="font-weight:bold;display: inline">Questions?</div> Contact our support team by using the Help Desk widget in the Workbench or by emailing <a href="mailto:[email protected]">[email protected]</a></div>
<div><i>All of Us</i> Researcher Workbench support team</div>
</body>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<style>
body {
background-color: #F1F1F1;
padding-left: 1rem;
padding-top: 1rem;
width: 600px;
}
* {
font-family: 'Montserrat', sans-serif;
font-weight: 300;
}
div {
margin-top: 2rem;
margin-bottom: 1rem;
color: #302C71;
font-size: 24px;
font-weight: 300;
line-height: 36px;
}
* {
margin-bottom: 6px;
}
</style>
</head>
<body>
<img src="${HEADER_IMG}">
<div>Hello ${FIRST_NAME},</div>
<div>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.</div>
<div style="font-weight:bold; margin-bottom: 0">Your initial credits will expire on ${INITIAL_CREDITS_EXPIRATION}.</div>
<div style="font-weight:bold; margin-top: 0">You are eligible to request a 270-day extension under your profile in the Researcher Workbench.</div>

<div>For more information about using initial credits and requesting an extension, read the “<a href="https://support.researchallofus.org/hc/en-us/articles/28920849686036-Using-All-of-Us-Initial-Credits">Using ${ALL_OF_US} Initial Credits</a>” article on the User Support Hub.</div>
<div><div style="font-weight:bold;display: inline">Questions?</div> Contact our support team by using the Help Desk widget in the Workbench or by emailing <a href="mailto:[email protected]">[email protected]</a></div>
<div>${ALL_OF_US} Researcher Workbench support team</div>
</body>

0 comments on commit 89cee2b

Please sign in to comment.