diff --git a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java index f1acd18c78c..4af6e284595 100644 --- a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java @@ -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 @@ -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 @@ -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 diff --git a/src/main/java/teammates/common/util/EmailType.java b/src/main/java/teammates/common/util/EmailType.java index 5f0cd5df568..6ee9abcbab9 100644 --- a/src/main/java/teammates/common/util/EmailType.java +++ b/src/main/java/teammates/common/util/EmailType.java @@ -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]"), diff --git a/src/main/java/teammates/common/util/Templates.java b/src/main/java/teammates/common/util/Templates.java index 75cf95a2d38..1fea9a61405 100644 --- a/src/main/java/teammates/common/util/Templates.java +++ b/src/main/java/teammates/common/util/Templates.java @@ -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 = diff --git a/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java b/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java index f89eb4008a7..befe9647656 100644 --- a/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java +++ b/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java @@ -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}. */ diff --git a/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java b/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java index 34a450f3b65..223c7d23916 100644 --- a/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java +++ b/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java @@ -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); } diff --git a/src/main/resources/instructorEmailTemplate-newAccountRequestAcknowledgement.html b/src/main/resources/instructorEmailTemplate-newAccountRequestAcknowledgement.html new file mode 100644 index 00000000000..91b29fe648d --- /dev/null +++ b/src/main/resources/instructorEmailTemplate-newAccountRequestAcknowledgement.html @@ -0,0 +1,65 @@ +

Hello, ${name}

+ +

+ Thank you for submitting an account request. This is what you have submitted: +

+ +
+ + + + + + + + + + + + + + + + + + + + +
+ + Full Name + + + ${name} +
+ + Country & Institute + + + ${institute} +
+ + Email Address + + + ${emailAddress} +
+ + Home Page URL
& Comments +
+
+ ${comments} +
+
+ +

+ Your request will be reviewed within 24 hours. We will send another email once your request has been accepted. +

+

+ If you have any additional queries, please feel free to contact us at ${supportEmail}. +

+ +

+ Regards,
+ TEAMMATES Team. +

diff --git a/src/test/java/teammates/sqllogic/api/SqlEmailGeneratorTest.java b/src/test/java/teammates/sqllogic/api/SqlEmailGeneratorTest.java index 24a77f91ac7..036ccf4b448 100644 --- a/src/test/java/teammates/sqllogic/api/SqlEmailGeneratorTest.java +++ b/src/test/java/teammates/sqllogic/api/SqlEmailGeneratorTest.java @@ -39,6 +39,29 @@ void testGenerateNewAccountRequestAdminAlertEmail_withNoComments_generatesSucces "/adminNewAccountRequestAlertEmailWithNoComments.html"); } + @Test + void testGenerateNewAccountRequestAcknowledgementEmail_withComments_generatesSuccessfully() throws IOException { + AccountRequest accountRequest = new AccountRequest("darth-vader@sith.org", "Darth Vader", "Sith Order", + AccountRequestStatus.PENDING, + "I Am Your Father"); + EmailWrapper email = sqlEmailGenerator.generateNewAccountRequestAcknowledgementEmail(accountRequest); + verifyEmail(email, "darth-vader@sith.org", 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("maul@sith.org", "Maul", "Sith Order", + AccountRequestStatus.PENDING, null); + EmailWrapper email = sqlEmailGenerator.generateNewAccountRequestAcknowledgementEmail(accountRequest); + verifyEmail(email, "maul@sith.org", 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()); @@ -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("${")); } diff --git a/src/test/resources/emails/instructorNewAccountRequestAcknowledgementEmailWithComments.html b/src/test/resources/emails/instructorNewAccountRequestAcknowledgementEmailWithComments.html new file mode 100644 index 00000000000..a5b24b850de --- /dev/null +++ b/src/test/resources/emails/instructorNewAccountRequestAcknowledgementEmailWithComments.html @@ -0,0 +1,65 @@ +

Hello, Darth Vader

+ +

+ Thank you for submitting an account request. This is what you have submitted: +

+ +
+ + + + + + + + + + + + + + + + + + + + +
+ + Full Name + + + Darth Vader +
+ + Country & Institute + + + Sith Order +
+ + Email Address + + + darth-vader@sith.org +
+ + Home Page URL
& Comments +
+
+ I Am Your Father +
+
+ +

+ Your request will be reviewed within 24 hours. We will send another email once your request has been accepted. +

+

+ If you have any additional queries, please feel free to contact us at ${support.email}. +

+ +

+ Regards,
+ TEAMMATES Team. +

diff --git a/src/test/resources/emails/instructorNewAccountRequestAcknowledgementEmailWithNoComments.html b/src/test/resources/emails/instructorNewAccountRequestAcknowledgementEmailWithNoComments.html new file mode 100644 index 00000000000..7b5e303cb86 --- /dev/null +++ b/src/test/resources/emails/instructorNewAccountRequestAcknowledgementEmailWithNoComments.html @@ -0,0 +1,65 @@ +

Hello, Maul

+ +

+ Thank you for submitting an account request. This is what you have submitted: +

+ +
+ + + + + + + + + + + + + + + + + + + + +
+ + Full Name + + + Maul +
+ + Country & Institute + + + Sith Order +
+ + Email Address + + + maul@sith.org +
+ + Home Page URL
& Comments +
+
+ +
+
+ +

+ Your request will be reviewed within 24 hours. We will send another email once your request has been accepted. +

+

+ If you have any additional queries, please feel free to contact us at ${support.email}. +

+ +

+ Regards,
+ TEAMMATES Team. +