Skip to content

Commit

Permalink
[TEAMMATES#11450] 'Session opening soon' alerts to instructors: Also …
Browse files Browse the repository at this point in the history
…give the join link if applicable (TEAMMATES#11453)

* Add join course details during notification for course opening

* Update unit tests for feedback session reminder email

* Add documentation for helper functions

* Update template for join course before edit details

* Undo unnecessary lints

* Make html indentation 2 space and edit comments

* Update functions from merge

* Use instructor.getRegistrationUrl()

Co-authored-by: Ahmed Bahajjaj <[email protected]>
  • Loading branch information
josiahkhoo and madanalogy authored Nov 4, 2021
1 parent edc10ac commit a69b068
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 26 deletions.
4 changes: 4 additions & 0 deletions src/main/java/teammates/common/util/Templates.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public static class EmailTemplates {
FileHelper.readResourceFile("userEmailFragment-sessionAdditionalContactInformationFragment.html");
public static final String OWNER_FEEDBACK_SESSION_OPENING_SOON =
FileHelper.readResourceFile("ownerEmailTemplate-sessionOpeningSoon.html");
public static final String FRAGMENT_OPENING_SOON_EDIT_DETAILS =
FileHelper.readResourceFile("ownerEmailFragment-editDetails.html");
public static final String FRAGMENT_OPENING_SOON_JOIN_COURSE_BEFORE_EDIT_DETAILS =
FileHelper.readResourceFile("ownerEmailFragment-joinCourseBeforeEditDetails.html");
}

}
44 changes: 36 additions & 8 deletions src/main/java/teammates/logic/api/EmailGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ private EmailWrapper generateFeedbackSessionOpeningSoonEmailBase(
CourseAttributes course, FeedbackSessionAttributes session,
InstructorAttributes coOwner, EmailType type, String editUrl) {

String additionalNotes;

// If instructor has not joined the course, populate additional notes with information to join course.
if (coOwner.isRegistered()) {
additionalNotes = fillUpEditFeedbackSessionDetailsFragment(editUrl);
} else {
additionalNotes = fillUpJoinCourseBeforeEditFeedbackSessionDetailsFragment(editUrl,
getInstructorCourseJoinUrl(coOwner));
}

String emailBody = Templates.populateTemplate(EmailTemplates.OWNER_FEEDBACK_SESSION_OPENING_SOON,
"${userName}", SanitizationHelper.sanitizeForHtml(coOwner.getName()),
"${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()),
Expand All @@ -140,8 +150,7 @@ private EmailWrapper generateFeedbackSessionOpeningSoonEmailBase(
"${sessionInstructions}", session.getInstructionsString(),
"${startTime}", SanitizationHelper.sanitizeForHtml(TimeHelper.formatInstant(
session.getStartTime(), session.getTimeZone(), DATETIME_DISPLAY_FORMAT)),
"${sessionEditUrl}", editUrl,
"${additionalNotes}", "",
"${additionalNotes}", additionalNotes,
"${additionalContactInformation}", "");

EmailWrapper email = getEmptyEmailAddressedToEmail(coOwner.getEmail());
Expand All @@ -151,6 +160,25 @@ private EmailWrapper generateFeedbackSessionOpeningSoonEmailBase(
return email;
}

/**
* Generates the fragment for instructions on how to edit details for feedback session at {@code editUrl}.
*/
private String fillUpEditFeedbackSessionDetailsFragment(String editUrl) {
return Templates.populateTemplate(EmailTemplates.FRAGMENT_OPENING_SOON_EDIT_DETAILS,
"${sessionEditUrl}", editUrl);
}

/**
* Generates the fragment for instructions on how to edit details for feedback session at {@code editUrl} and
* how to join the course at {@code joinUrl}.
*/
private String fillUpJoinCourseBeforeEditFeedbackSessionDetailsFragment(String editUrl, String joinUrl) {
return Templates.populateTemplate(EmailTemplates.FRAGMENT_OPENING_SOON_JOIN_COURSE_BEFORE_EDIT_DETAILS,
"${sessionEditUrl}", editUrl,
"${joinUrl}", joinUrl
);
}

/**
* Generates the feedback session reminder emails for the given {@code session} for {@code students}
* and {@code instructorsToRemind}. In addition, the emails will also be forwarded to {@code instructorsToNotify}.
Expand Down Expand Up @@ -487,11 +515,9 @@ private EmailWrapper generateFeedbackSessionEmailBaseForInstructorReminders(
}

private String generateInstructorJoinReminderFragment(InstructorAttributes instructor) {
String joinUrl = Config.getFrontEndAppUrl(instructor.getRegistrationUrl()).toAbsoluteString();

return Templates.populateTemplate(EmailTemplates.FRAGMENT_INSTRUCTOR_COURSE_JOIN_REMINDER,
"${feedbackAction}", FEEDBACK_ACTION_SUBMIT_EDIT_OR_VIEW,
"${joinUrl}", joinUrl);
"${joinUrl}", getInstructorCourseJoinUrl(instructor));
}

/**
Expand Down Expand Up @@ -878,12 +904,14 @@ private String fillUpStudentRejoinAfterGoogleIdResetFragment(StudentAttributes s
"${supportEmail}", Config.SUPPORT_EMAIL);
}

private String fillUpInstructorJoinFragment(InstructorAttributes instructor) {
String joinUrl = Config.getFrontEndAppUrl(instructor.getRegistrationUrl()).toAbsoluteString();
private String getInstructorCourseJoinUrl(InstructorAttributes instructor) {
return Config.getFrontEndAppUrl(instructor.getRegistrationUrl()).toAbsoluteString();
}

private String fillUpInstructorJoinFragment(InstructorAttributes instructor) {
return Templates.populateTemplate(EmailTemplates.USER_COURSE_JOIN,
"${joinFragment}", EmailTemplates.FRAGMENT_INSTRUCTOR_COURSE_JOIN,
"${joinUrl}", joinUrl);
"${joinUrl}", getInstructorCourseJoinUrl(instructor));
}

private String fillUpInstructorRejoinAfterGoogleIdResetFragment(InstructorAttributes instructor) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/ownerEmailFragment-editDetails.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<p>
<ul>
<li>
<strong>To edit details of this session,</strong> please visit <a href="${sessionEditUrl}">${sessionEditUrl}</a>
</li>
<li>
No other action is needed if you deem the session details to be correct.
</li>
</ul>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<p>
<strong>To "join" the course, please go to this Web address: </strong>
<a href="${joinUrl}">${joinUrl}</a>
</p>
<p>
After joining the course, you can edit details of the above session at <a href="${sessionEditUrl}">${sessionEditUrl}</a>.
<ul>
<li>
If prompted to log in when joining the course, use your Google account to log in.
If you do not have a Google account, please create one from the <a href="https://accounts.google.com/NewAccount">Google Accounts page</a>.
</li>
<li>
The above link to join the course is unique to you. Please do not share it with others.
</li>
<li>
No other action is needed if you deem the session details to be correct.
</li>
</ul>
</p>
14 changes: 3 additions & 11 deletions src/main/resources/ownerEmailTemplate-sessionOpeningSoon.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,10 @@
</tr>
</table>
</div>
<p>
<ul>
<li>
<strong>To edit details of this session,</strong> please visit <a href="${sessionEditUrl}">${sessionEditUrl}</a>
</li>
<li>
No other action is needed if you deem the session details to be correct.
</li>
</ul>
</p>

${additionalNotes}

<p>
Regards,
<br>TEAMMATES Team.
</p>
</p>
19 changes: 14 additions & 5 deletions src/test/java/teammates/logic/api/EmailGeneratorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,23 @@ public void testGenerateFeedbackSessionEmails() throws Exception {
subject = String.format(EmailType.FEEDBACK_OPENING_SOON.getSubject(), course.getName(),
session.getFeedbackSessionName());

// this instructor email has been given co-owner privileges in the test file
InstructorAttributes coOwner1 =
// this instructor email has been given co-owner privileges in the test file but has not joined
InstructorAttributes coOwnerNotJoined =
instructorsLogic.getInstructorForEmail(course.getId(), "[email protected]");

assertTrue(coOwner1.hasCoownerPrivileges());
assertTrue(coOwnerNotJoined.hasCoownerPrivileges());

verifyEmailReceivedCorrectly(emails, coOwner1.getEmail(), subject,
"/sessionOpeningSoonEmailForCoOwner.html");
verifyEmailReceivedCorrectly(emails, coOwnerNotJoined.getEmail(), subject,
"/sessionOpeningSoonEmailForCoOwnerNotJoined.html");

// this instructor email has been given co-owner privileges in the test file and has joined
InstructorAttributes coOwnerJoined =
instructorsLogic.getInstructorForEmail(course.getId(), "[email protected]");

assertTrue(coOwnerJoined.hasCoownerPrivileges());

verifyEmailReceivedCorrectly(emails, coOwnerJoined.getEmail(), subject,
"/sessionOpeningSoonEmailForCoOwnerJoined.html");

______TS("feedback session published alerts");

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p>Hello Instructor Not Yet Joined Course 1,</p>
<p>Hello Instructor1 Course1,</p>



Expand Down Expand Up @@ -62,6 +62,7 @@
</tr>
</table>
</div>

<p>
<ul>
<li>
Expand All @@ -76,4 +77,4 @@
<p>
Regards,
<br>TEAMMATES Team.
</p>
</p>
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<p>Hello Instructor Not Yet Joined Course 1,</p>



<p>
Heads up! The following feedback session is due to open soon.
<div>
<table style="max-width:600px;border:1px solid black;">
<tr>
<td style="padding:5px;">
<strong>
Course:
</strong>
</td>
<td style="padding:5px;">
[idOfTypicalCourse1] Typical Course 1 with 2 Evals
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Feedback Session Name:
</strong>
</td>
<td style="padding:5px;">
First feedback session
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Session Start Time:
</strong>
</td>
<td style="padding:5px;">
Sun, 01 Apr 2012, 11:59 PM SAST
</td>
</tr>

<tr>
<td style="padding:5px;">
<strong>
Deadline:
</strong>
</td>
<td style="padding:5px;">
Fri, 30 Apr 2027, 11:59 PM SAST
</td>
</tr>

<tr>
<td style="padding:5px;vertical-align:top">
<strong>
Session Instructions:
</strong>
</td>
<td style="padding:5px;">
Please please fill in the following questions.
</td>
</tr>
</table>
</div>

<p>
<strong>To "join" the course, please go to this Web address: </strong>
<a href="http://localhost:4200/web/join?key=${regkey.enc}&entitytype=instructor">http://localhost:4200/web/join?key=${regkey.enc}&entitytype=instructor</a>
</p>
<p>
After joining the course, you can edit details of the above session at <a href="http://localhost:4200/web/instructor/sessions/edit?courseid=idOfTypicalCourse1&fsname=First%20feedback%20session">http://localhost:4200/web/instructor/sessions/edit?courseid=idOfTypicalCourse1&fsname=First%20feedback%20session</a>.
<ul>
<li>
If prompted to log in when joining the course, use your Google account to log in.
If you do not have a Google account, please create one from the <a href="https://accounts.google.com/NewAccount">Google Accounts page</a>.
</li>
<li>
The above link to join the course is unique to you. Please do not share it with others.
</li>
<li>
No other action is needed if you deem the session details to be correct.
</li>
</ul>
</p>

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

0 comments on commit a69b068

Please sign in to comment.