diff --git a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java index 70aa4ecc521..c2af0829c69 100644 --- a/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java +++ b/src/it/java/teammates/it/ui/webapi/CreateAccountRequestActionIT.java @@ -43,13 +43,16 @@ protected void testExecute() throws Exception { assertEquals("The Fellowship of the Ring", accountRequest.getInstitute()); assertNull(accountRequest.getRegisteredAt()); assertEquals(accountRequest.getRegistrationUrl(), output.getJoinLink()); - verifyNumberOfEmailsSent(1); verifySpecifiedTasksAdded(Const.TaskQueue.SEARCH_INDEXING_QUEUE_NAME, 1); + verifyNumberOfEmailsSent(2); EmailWrapper emailSent = mockEmailSender.getEmailsSent().get(0); assertEquals(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), "Frodo Baggins"), emailSent.getSubject()); assertEquals("ring-bearer@fellowship.net", emailSent.getRecipient()); assertTrue(emailSent.getContent().contains(output.getJoinLink())); + EmailWrapper sentAdminAlertEmail = mockEmailSender.getEmailsSent().get(1); + // Check only the email type. The content of the email is not tested here, but in the email generator test(s). + assertEquals(EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT, sentAdminAlertEmail.getType()); } @Override diff --git a/src/main/java/teammates/common/util/EmailType.java b/src/main/java/teammates/common/util/EmailType.java index af649debb7b..5f0cd5df568 100644 --- a/src/main/java/teammates/common/util/EmailType.java +++ b/src/main/java/teammates/common/util/EmailType.java @@ -23,6 +23,7 @@ public enum EmailType { NEW_INSTRUCTOR_ACCOUNT("TEAMMATES: Welcome to TEAMMATES! %s"), 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"), 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 524c84bc2c6..75cf95a2d38 100644 --- a/src/main/java/teammates/common/util/Templates.java +++ b/src/main/java/teammates/common/util/Templates.java @@ -32,6 +32,8 @@ public static String populateTemplate(String template, String... keyValuePairs) * Collection of templates of emails to be sent by the system. */ public static class EmailTemplates { + public static final String ADMIN_NEW_ACCOUNT_REQUEST_ALERT = + FileHelper.readResourceFile("adminEmailTemplate-newAccountRequestAlert.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 2bd8f2bfb08..f89eb4008a7 100644 --- a/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java +++ b/src/main/java/teammates/sqllogic/api/SqlEmailGenerator.java @@ -26,6 +26,7 @@ import teammates.sqllogic.core.FeedbackSessionsLogic; import teammates.sqllogic.core.UsersLogic; import teammates.storage.sqlentity.Account; +import teammates.storage.sqlentity.AccountRequest; import teammates.storage.sqlentity.Course; import teammates.storage.sqlentity.DeadlineExtension; import teammates.storage.sqlentity.FeedbackSession; @@ -973,6 +974,33 @@ public EmailWrapper generateInstructorCourseRejoinEmailAfterGoogleIdReset( return email; } + /** + * Generates the email to alert the admin of the new {@code accountRequest}. + */ + public EmailWrapper generateNewAccountRequestAdminAlertEmail(AccountRequest accountRequest) { + String name = accountRequest.getName(); + String institute = accountRequest.getInstitute(); + String emailAddress = accountRequest.getEmail(); + String comments = accountRequest.getComments(); + if (comments == null) { + comments = ""; + } + String adminAccountRequestsPageUrl = Config.getFrontEndAppUrl(Const.WebPageURIs.ADMIN_HOME_PAGE).toAbsoluteString(); + String[] templateKeyValuePairs = new String[] { + "${name}", name, + "${institute}", institute, + "${emailAddress}", emailAddress, + "${comments}", comments, + "${adminAccountRequestsPageUrl}", adminAccountRequestsPageUrl, + }; + String content = Templates.populateTemplate(EmailTemplates.ADMIN_NEW_ACCOUNT_REQUEST_ALERT, templateKeyValuePairs); + EmailWrapper email = getEmptyEmailAddressedToEmail(Config.SUPPORT_EMAIL); + email.setType(EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT); + 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 30a4e9da8a7..b6243a0016f 100644 --- a/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java +++ b/src/main/java/teammates/ui/webapi/CreateAccountRequestAction.java @@ -45,7 +45,8 @@ public JsonResult execute() EmailWrapper email = emailGenerator.generateNewInstructorAccountJoinEmail( instructorEmail, instructorName, joinLink); emailSender.sendEmail(email); - + EmailWrapper adminAlertEmail = sqlEmailGenerator.generateNewAccountRequestAdminAlertEmail(accountRequest); + emailSender.sendEmail(adminAlertEmail); JoinLinkData output = new JoinLinkData(joinLink); return new JsonResult(output); } diff --git a/src/main/resources/adminEmailTemplate-newAccountRequestAlert.html b/src/main/resources/adminEmailTemplate-newAccountRequestAlert.html new file mode 100644 index 00000000000..a91c1250a26 --- /dev/null +++ b/src/main/resources/adminEmailTemplate-newAccountRequestAlert.html @@ -0,0 +1,60 @@ +
Hello, Admin
+ ++ A new instructor account request has been submitted: +
+ ++ + Full Name + + | ++ ${name} + | +
+ + Institute + + | ++ ${institute} + | +
+ + Email Address + + | ++ ${emailAddress} + | +
+ + Comments + + | ++ ${comments} + | +
+ Regards,
+ TEAMMATES Team.
+
Hello, Admin
+ ++ A new instructor account request has been submitted: +
+ ++ + Full Name + + | ++ Anakin Skywalker + | +
+ + Institute + + | ++ Jedi Order + | +
+ + Email Address + + | ++ chosen-one@jedi.org + | +
+ + Comments + + | ++ I don't like sand. It's coarse and rough and irritating... and it gets everywhere. + | +
+ Regards,
+ TEAMMATES Team.
+
Hello, Admin
+ ++ A new instructor account request has been submitted: +
+ ++ + Full Name + + | ++ Maul + | +
+ + Institute + + | ++ Sith Order + | +
+ + Email Address + + | ++ maul@sith.org + | +
+ + Comments + + | ++ + | +
+ Regards,
+ TEAMMATES Team.
+