Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#11878] Add new account request alert email for admins #12926

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 @@ -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]"),
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 @@ -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 =
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 @@ -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;
Expand Down Expand Up @@ -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}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
60 changes: 60 additions & 0 deletions src/main/resources/adminEmailTemplate-newAccountRequestAlert.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<p>Hello, Admin</p>

<p>
A new instructor account request has been 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>
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>
Comments
</strong>
</td>
<td style="padding:5px;">
${comments}
</td>
</tr>
</table>
</div>

Accept/reject this request on the admin panel: <a href="${adminAccountRequestsPageUrl}">${adminAccountRequestsPageUrl}</a>

<p>
Regards,<br>
TEAMMATES Team.
</p>
58 changes: 58 additions & 0 deletions src/test/java/teammates/sqllogic/api/SqlEmailGeneratorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package teammates.sqllogic.api;

import java.io.IOException;

import org.testng.annotations.Test;

import teammates.common.datatransfer.AccountRequestStatus;
import teammates.common.util.Config;
import teammates.common.util.EmailType;
import teammates.common.util.EmailWrapper;
import teammates.storage.sqlentity.AccountRequest;
import teammates.test.BaseTestCase;
import teammates.test.EmailChecker;

/**
* SUT: {@link SqlEmailGenerator}.
*/
public class SqlEmailGeneratorTest extends BaseTestCase {
private final SqlEmailGenerator sqlEmailGenerator = SqlEmailGenerator.inst();

@Test
void testGenerateNewAccountRequestAdminAlertEmail_withComments_generatesSuccessfully() throws IOException {
AccountRequest accountRequest = new AccountRequest("chosen-one@jedi.org", "Anakin Skywalker", "Jedi Order",
AccountRequestStatus.PENDING,
"I don't like sand. It's coarse and rough and irritating... and it gets everywhere.");
EmailWrapper email = sqlEmailGenerator.generateNewAccountRequestAdminAlertEmail(accountRequest);
verifyEmail(email, Config.SUPPORT_EMAIL, EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT,
"TEAMMATES (Action Needed): New Account Request Received",
"/adminNewAccountRequestAlertEmailWithComments.html");
}

@Test
void testGenerateNewAccountRequestAdminAlertEmail_withNoComments_generatesSuccessfully() throws IOException {
AccountRequest accountRequest = new AccountRequest("maul@sith.org", "Maul", "Sith Order",
AccountRequestStatus.PENDING, null);
EmailWrapper email = sqlEmailGenerator.generateNewAccountRequestAdminAlertEmail(accountRequest);
verifyEmail(email, Config.SUPPORT_EMAIL, EmailType.NEW_ACCOUNT_REQUEST_ADMIN_ALERT,
"TEAMMATES (Action Needed): New Account Request Received",
"/adminNewAccountRequestAlertEmailWithNoComments.html");
}

private void verifyEmail(EmailWrapper email, String expectedRecipientEmailAddress, EmailType expectedEmailType,
String expectedSubject, 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());
String emailContent = email.getContent();
EmailChecker.verifyEmailContent(emailContent, expectedEmailContentFilePathname);
verifyEmailContentHasNoPlaceholders(emailContent);
}

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

<p>
A new instructor account request has been 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;">
Anakin Skywalker
</td>
</tr>

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

<tr>
<td style="padding:5px;">
<strong>
Email Address
</strong>
</td>
<td style="padding:5px;">
chosen-one@jedi.org
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Comments
</strong>
</td>
<td style="padding:5px;">
I don't like sand. It's coarse and rough and irritating... and it gets everywhere.
</td>
</tr>
</table>
</div>

Accept/reject this request on the admin panel: <a href="${app.url}/web/admin/home">${app.url}/web/admin/home</a>

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

<p>
A new instructor account request has been 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>
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;">
maul@sith.org
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Comments
</strong>
</td>
<td style="padding:5px;">

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

Accept/reject this request on the admin panel: <a href="${app.url}/web/admin/home">${app.url}/web/admin/home</a>

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