Skip to content

Commit

Permalink
[#11878] Create instructor request acknowledgement email (#12944)
Browse files Browse the repository at this point in the history
* Create instructor request acknowledgement email

* Add tests for acknowledgement email

* Fix test cases

* Fix comments in expected email

* Use config support email value in email template

* Fix email recipient

* Fix test expected emails

* Remove trailing space

* Use placeholder for support email

* Sanitize acknowledgement email

* Set acknowledgement email to bcc support
  • Loading branch information
xenosf authored Mar 30, 2024
1 parent 9794b8a commit 00b85ce
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ void testExecute_typicalCase_createsSuccessfully() {
assertEquals("My road leads into the desert. I can see it.", accountRequest.getComments());
assertNull(accountRequest.getRegisteredAt());
verifySpecifiedTasksAdded(Const.TaskQueue.SEARCH_INDEXING_QUEUE_NAME, 1);
verifyNumberOfEmailsSent(1);
verifyNumberOfEmailsSent(2);
EmailWrapper sentAdminAlertEmail = mockEmailSender.getEmailsSent().get(0);
EmailWrapper sentAcknowledgementEmail = mockEmailSender.getEmailsSent().get(1);
assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT, sentAdminAlertEmail.getType());
assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT, sentAcknowledgementEmail.getType());
}

@Test
Expand All @@ -153,9 +155,11 @@ void testExecute_leadingAndTrailingSpacesAndNullComments_createsSuccessfully() {
assertNull(accountRequest.getComments());
assertNull(accountRequest.getRegisteredAt());
verifySpecifiedTasksAdded(Const.TaskQueue.SEARCH_INDEXING_QUEUE_NAME, 1);
verifyNumberOfEmailsSent(1);
verifyNumberOfEmailsSent(2);
EmailWrapper sentAdminAlertEmail = mockEmailSender.getEmailsSent().get(0);
EmailWrapper sentAcknowledgementEmail = mockEmailSender.getEmailsSent().get(1);
assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT, sentAdminAlertEmail.getType());
assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT, sentAcknowledgementEmail.getType());
}

@Test
Expand Down Expand Up @@ -186,9 +190,11 @@ void testExecute_accountRequestWithSameEmailAddressAndInstituteAlreadyExists_cre
assertEquals("My road leads into the desert. I can see it.", accountRequest.getComments());
assertNull(accountRequest.getRegisteredAt());
verifySpecifiedTasksAdded(Const.TaskQueue.SEARCH_INDEXING_QUEUE_NAME, 1);
verifyNumberOfEmailsSent(1);
verifyNumberOfEmailsSent(2);
EmailWrapper sentAdminAlertEmail = mockEmailSender.getEmailsSent().get(0);
EmailWrapper sentAcknowledgementEmail = mockEmailSender.getEmailsSent().get(1);
assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT, sentAdminAlertEmail.getType());
assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT, sentAcknowledgementEmail.getType());
}

@Override
Expand Down
1 change: 1 addition & 0 deletions src/main/java/teammates/common/util/EmailType.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum EmailType {
STUDENT_COURSE_JOIN("TEAMMATES: Invitation to join course [%s][Course ID: %s]"),
STUDENT_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET("TEAMMATES: Your account has been reset for course [%s][Course ID: %s]"),
NEW_ACCOUNT_REQUEST_ADMIN_ALERT("TEAMMATES (Action Needed): New Account Request Received"),
NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT("TEAMMATES: Acknowledgement of Instructor Account Request"),
INSTRUCTOR_COURSE_JOIN("TEAMMATES: Invitation to join course as an instructor [%s][Course ID: %s]"),
INSTRUCTOR_COURSE_REJOIN_AFTER_GOOGLE_ID_RESET("TEAMMATES: Your account has been reset for course [%s][Course ID: %s]"),
USER_COURSE_REGISTER("TEAMMATES: Registered for Course [%s][Course ID: %s]"),
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/teammates/common/util/Templates.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static String populateTemplate(String template, String... keyValuePairs)
public static class EmailTemplates {
public static final String ADMIN_NEW_ACCOUNT_REQUEST_ALERT =
FileHelper.readResourceFile("adminEmailTemplate-newAccountRequestAlert.html");
public static final String INSTRUCTOR_NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT =
FileHelper.readResourceFile("instructorEmailTemplate-newAccountRequestAcknowledgement.html");
public static final String USER_COURSE_JOIN =
FileHelper.readResourceFile("userEmailTemplate-courseJoin.html");
public static final String USER_COURSE_REGISTER =
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,34 @@ public EmailWrapper generateNewAccountRequestAdminAlertEmail(AccountRequest acco
return email;
}

/**
* Generates the acknowledgement email to be sent to the person who submitted {@code accountRequest}.
*/
public EmailWrapper generateNewAccountRequestAcknowledgementEmail(AccountRequest accountRequest) {
String name = SanitizationHelper.sanitizeForHtml(accountRequest.getName());
String institute = SanitizationHelper.sanitizeForHtml(accountRequest.getInstitute());
String emailAddress = SanitizationHelper.sanitizeForHtml(accountRequest.getEmail());
String comments = SanitizationHelper.sanitizeForHtml(accountRequest.getComments());
if (comments == null) {
comments = "";
}
String[] templateKeyValuePairs = new String[] {
"${name}", name,
"${institute}", institute,
"${emailAddress}", emailAddress,
"${comments}", comments,
"${supportEmail}", Config.SUPPORT_EMAIL,
};
String content = Templates.populateTemplate(
EmailTemplates.INSTRUCTOR_NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT, templateKeyValuePairs);
EmailWrapper email = getEmptyEmailAddressedToEmail(emailAddress);
email.setType(EmailType.NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT);
email.setBcc(Config.SUPPORT_EMAIL);
email.setSubjectFromType();
email.setContent(content);
return email;
}

/**
* Generates the course registered email for the user with the given details in {@code course}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@ public JsonResult execute()

assert accountRequest != null;
EmailWrapper adminAlertEmail = sqlEmailGenerator.generateNewAccountRequestAdminAlertEmail(accountRequest);
EmailWrapper userAcknowledgementEmail = sqlEmailGenerator
.generateNewAccountRequestAcknowledgementEmail(accountRequest);
emailSender.sendEmail(adminAlertEmail);
emailSender.sendEmail(userAcknowledgementEmail);
AccountRequestData output = new AccountRequestData(accountRequest);
return new JsonResult(output);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<p>Hello, ${name}</p>

<p>
Thank you for submitting an account request. This is what you have submitted:
</p>

<div>
<table style="max-width:600px;border:1px solid black;">
<tr>
<td style="padding:5px;">
<strong>
Full Name
</strong>
</td>
<td style="padding:5px;">
${name}
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Country & Institute
</strong>
</td>
<td style="padding:5px;">
${institute}
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Email Address
</strong>
</td>
<td style="padding:5px;">
${emailAddress}
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Home Page URL<br>& Comments
</strong>
</td>
<td style="padding:5px;">
${comments}
</td>
</tr>
</table>
</div>

<p>
Your request will be reviewed within 24 hours. We will send another email once your request has been accepted.
</p>
<p>
If you have any additional queries, please feel free to contact us at ${supportEmail}.
</p>

<p>
Regards,<br>
TEAMMATES Team.
</p>
37 changes: 37 additions & 0 deletions src/test/java/teammates/sqllogic/api/SqlEmailGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,29 @@ void testGenerateNewAccountRequestAdminAlertEmail_withNoComments_generatesSucces
"/adminNewAccountRequestAlertEmailWithNoComments.html");
}

@Test
void testGenerateNewAccountRequestAcknowledgementEmail_withComments_generatesSuccessfully() throws IOException {
AccountRequest accountRequest = new AccountRequest("[email protected]", "Darth Vader", "Sith Order",
AccountRequestStatus.PENDING,
"I Am Your Father");
EmailWrapper email = sqlEmailGenerator.generateNewAccountRequestAcknowledgementEmail(accountRequest);
verifyEmail(email, "[email protected]", EmailType.NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT,
"TEAMMATES: Acknowledgement of Instructor Account Request",
Config.SUPPORT_EMAIL,
"/instructorNewAccountRequestAcknowledgementEmailWithComments.html");
}

@Test
void testGenerateNewAccountRequestAcknowledgementEmail_withNoComments_generatesSuccessfully() throws IOException {
AccountRequest accountRequest = new AccountRequest("[email protected]", "Maul", "Sith Order",
AccountRequestStatus.PENDING, null);
EmailWrapper email = sqlEmailGenerator.generateNewAccountRequestAcknowledgementEmail(accountRequest);
verifyEmail(email, "[email protected]", EmailType.NEW_ACCOUNT_REQUEST_ACKNOWLEDGEMENT,
"TEAMMATES: Acknowledgement of Instructor Account Request",
Config.SUPPORT_EMAIL,
"/instructorNewAccountRequestAcknowledgementEmailWithNoComments.html");
}

private void verifyEmail(EmailWrapper email, String expectedRecipientEmailAddress, EmailType expectedEmailType,
String expectedSubject, String expectedEmailContentFilePathname) throws IOException {
assertEquals(expectedRecipientEmailAddress, email.getRecipient());
Expand All @@ -52,6 +75,20 @@ private void verifyEmail(EmailWrapper email, String expectedRecipientEmailAddres
verifyEmailContentHasNoPlaceholders(emailContent);
}

private void verifyEmail(EmailWrapper email, String expectedRecipientEmailAddress, EmailType expectedEmailType,
String expectedSubject, String expectedBcc, String expectedEmailContentFilePathname) throws IOException {
assertEquals(expectedRecipientEmailAddress, email.getRecipient());
assertEquals(Config.EMAIL_SENDEREMAIL, email.getSenderEmail());
assertEquals(Config.EMAIL_SENDERNAME, email.getSenderName());
assertEquals(Config.EMAIL_REPLYTO, email.getReplyTo());
assertEquals(expectedEmailType, email.getType());
assertEquals(expectedSubject, email.getSubject());
assertEquals(expectedBcc, email.getBcc());
String emailContent = email.getContent();
EmailChecker.verifyEmailContent(emailContent, expectedEmailContentFilePathname);
verifyEmailContentHasNoPlaceholders(emailContent);
}

private void verifyEmailContentHasNoPlaceholders(String emailContent) {
assertFalse(emailContent.contains("${"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<p>Hello, Darth Vader</p>

<p>
Thank you for submitting an account request. This is what you have submitted:
</p>

<div>
<table style="max-width:600px;border:1px solid black;">
<tr>
<td style="padding:5px;">
<strong>
Full Name
</strong>
</td>
<td style="padding:5px;">
Darth Vader
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Country & Institute
</strong>
</td>
<td style="padding:5px;">
Sith Order
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Email Address
</strong>
</td>
<td style="padding:5px;">
[email protected]
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Home Page URL<br>& Comments
</strong>
</td>
<td style="padding:5px;">
I Am Your Father
</td>
</tr>
</table>
</div>

<p>
Your request will be reviewed within 24 hours. We will send another email once your request has been accepted.
</p>
<p>
If you have any additional queries, please feel free to contact us at ${support.email}.
</p>

<p>
Regards,<br>
TEAMMATES Team.
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<p>Hello, Maul</p>

<p>
Thank you for submitting an account request. This is what you have submitted:
</p>

<div>
<table style="max-width:600px;border:1px solid black;">
<tr>
<td style="padding:5px;">
<strong>
Full Name
</strong>
</td>
<td style="padding:5px;">
Maul
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Country & Institute
</strong>
</td>
<td style="padding:5px;">
Sith Order
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Email Address
</strong>
</td>
<td style="padding:5px;">
[email protected]
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Home Page URL<br>& Comments
</strong>
</td>
<td style="padding:5px;">

</td>
</tr>
</table>
</div>

<p>
Your request will be reviewed within 24 hours. We will send another email once your request has been accepted.
</p>
<p>
If you have any additional queries, please feel free to contact us at ${support.email}.
</p>

<p>
Regards,<br>
TEAMMATES Team.
</p>

0 comments on commit 00b85ce

Please sign in to comment.