From a69b0685b445d9f497b58f3e2b53f825d4c9aead Mon Sep 17 00:00:00 2001
From: Josiah Khoo <42318848+josiahkhoo@users.noreply.github.com>
Date: Thu, 4 Nov 2021 23:53:40 +0800
Subject: [PATCH] [#11450] 'Session opening soon' alerts to instructors: Also
give the join link if applicable (#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
---
.../java/teammates/common/util/Templates.java | 4 +
.../teammates/logic/api/EmailGenerator.java | 44 +++++++--
.../ownerEmailFragment-editDetails.html | 10 +++
...lFragment-joinCourseBeforeEditDetails.html | 19 ++++
...ownerEmailTemplate-sessionOpeningSoon.html | 14 +--
.../logic/api/EmailGeneratorTest.java | 19 ++--
...sionOpeningSoonEmailForCoOwnerJoined.html} | 5 +-
...onOpeningSoonEmailForCoOwnerNotJoined.html | 89 +++++++++++++++++++
8 files changed, 178 insertions(+), 26 deletions(-)
create mode 100644 src/main/resources/ownerEmailFragment-editDetails.html
create mode 100644 src/main/resources/ownerEmailFragment-joinCourseBeforeEditDetails.html
rename src/test/resources/emails/{sessionOpeningSoonEmailForCoOwner.html => sessionOpeningSoonEmailForCoOwnerJoined.html} (97%)
create mode 100644 src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerNotJoined.html
diff --git a/src/main/java/teammates/common/util/Templates.java b/src/main/java/teammates/common/util/Templates.java
index 67b6d5c92b1..15da613606e 100644
--- a/src/main/java/teammates/common/util/Templates.java
+++ b/src/main/java/teammates/common/util/Templates.java
@@ -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");
}
}
diff --git a/src/main/java/teammates/logic/api/EmailGenerator.java b/src/main/java/teammates/logic/api/EmailGenerator.java
index 9bae762860e..bd345be0aae 100644
--- a/src/main/java/teammates/logic/api/EmailGenerator.java
+++ b/src/main/java/teammates/logic/api/EmailGenerator.java
@@ -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()),
@@ -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());
@@ -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}.
@@ -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));
}
/**
@@ -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) {
diff --git a/src/main/resources/ownerEmailFragment-editDetails.html b/src/main/resources/ownerEmailFragment-editDetails.html
new file mode 100644
index 00000000000..582f3e40637
--- /dev/null
+++ b/src/main/resources/ownerEmailFragment-editDetails.html
@@ -0,0 +1,10 @@
+
+
+ -
+ To edit details of this session, please visit ${sessionEditUrl}
+
+ -
+ No other action is needed if you deem the session details to be correct.
+
+
+
diff --git a/src/main/resources/ownerEmailFragment-joinCourseBeforeEditDetails.html b/src/main/resources/ownerEmailFragment-joinCourseBeforeEditDetails.html
new file mode 100644
index 00000000000..9d1c91c6303
--- /dev/null
+++ b/src/main/resources/ownerEmailFragment-joinCourseBeforeEditDetails.html
@@ -0,0 +1,19 @@
+
+ To "join" the course, please go to this Web address:
+ ${joinUrl}
+
+
+ After joining the course, you can edit details of the above session at ${sessionEditUrl}.
+
+ -
+ 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 Google Accounts page.
+
+ -
+ The above link to join the course is unique to you. Please do not share it with others.
+
+ -
+ No other action is needed if you deem the session details to be correct.
+
+
+
diff --git a/src/main/resources/ownerEmailTemplate-sessionOpeningSoon.html b/src/main/resources/ownerEmailTemplate-sessionOpeningSoon.html
index 2261d10fe44..8621ee2fdf7 100644
--- a/src/main/resources/ownerEmailTemplate-sessionOpeningSoon.html
+++ b/src/main/resources/ownerEmailTemplate-sessionOpeningSoon.html
@@ -62,18 +62,10 @@
-
-
- -
- To edit details of this session, please visit ${sessionEditUrl}
-
- -
- No other action is needed if you deem the session details to be correct.
-
-
-
+
+${additionalNotes}
Regards,
TEAMMATES Team.
-
\ No newline at end of file
+
diff --git a/src/test/java/teammates/logic/api/EmailGeneratorTest.java b/src/test/java/teammates/logic/api/EmailGeneratorTest.java
index c8e0a5ad262..2d536e4df55 100644
--- a/src/test/java/teammates/logic/api/EmailGeneratorTest.java
+++ b/src/test/java/teammates/logic/api/EmailGeneratorTest.java
@@ -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(), "instructorNotYetJoinedCourse1@email.tmt");
- 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(), "instructor1@course1.tmt");
+
+ assertTrue(coOwnerJoined.hasCoownerPrivileges());
+
+ verifyEmailReceivedCorrectly(emails, coOwnerJoined.getEmail(), subject,
+ "/sessionOpeningSoonEmailForCoOwnerJoined.html");
______TS("feedback session published alerts");
diff --git a/src/test/resources/emails/sessionOpeningSoonEmailForCoOwner.html b/src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerJoined.html
similarity index 97%
rename from src/test/resources/emails/sessionOpeningSoonEmailForCoOwner.html
rename to src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerJoined.html
index 7d9b788b22a..11fce98f85d 100644
--- a/src/test/resources/emails/sessionOpeningSoonEmailForCoOwner.html
+++ b/src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerJoined.html
@@ -1,4 +1,4 @@
-Hello Instructor Not Yet Joined Course 1,
+Hello Instructor1 Course1,
@@ -62,6 +62,7 @@
+
-
@@ -76,4 +77,4 @@
Regards,
TEAMMATES Team.
-
\ No newline at end of file
+
diff --git a/src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerNotJoined.html b/src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerNotJoined.html
new file mode 100644
index 00000000000..7be259d1754
--- /dev/null
+++ b/src/test/resources/emails/sessionOpeningSoonEmailForCoOwnerNotJoined.html
@@ -0,0 +1,89 @@
+Hello Instructor Not Yet Joined Course 1,
+
+
+
+
+ Heads up! The following feedback session is due to open soon.
+
+
+
+
+
+ Course:
+
+ |
+
+ [idOfTypicalCourse1] Typical Course 1 with 2 Evals
+ |
+
+
+
+
+
+ Feedback Session Name:
+
+ |
+
+ First feedback session
+ |
+
+
+
+
+
+ Session Start Time:
+
+ |
+
+ Sun, 01 Apr 2012, 11:59 PM SAST
+ |
+
+
+
+
+
+ Deadline:
+
+ |
+
+ Fri, 30 Apr 2027, 11:59 PM SAST
+ |
+
+
+
+
+
+ Session Instructions:
+
+ |
+
+ Please please fill in the following questions.
+ |
+
+
+
+
+
+ To "join" the course, please go to this Web address:
+ http://localhost:4200/web/join?key=${regkey.enc}&entitytype=instructor
+
+
+ After joining the course, you can edit details of the above session at http://localhost:4200/web/instructor/sessions/edit?courseid=idOfTypicalCourse1&fsname=First%20feedback%20session.
+
+ -
+ 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 Google Accounts page.
+
+ -
+ The above link to join the course is unique to you. Please do not share it with others.
+
+ -
+ No other action is needed if you deem the session details to be correct.
+
+
+
+
+
+ Regards,
+
TEAMMATES Team.
+