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

Add Google Calendar link to email templates sent out with deadlines #1

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c871abb
Edit email templates
itstrueitstrueitsrealitsreal Jun 16, 2024
e8d47cf
Add google calendar link to EmailGenerator.java
itstrueitstrueitsrealitsreal Jun 17, 2024
7839bd3
Remove unused imports
itstrueitstrueitsrealitsreal Jun 17, 2024
43fc6f0
Fix failing tests
itstrueitstrueitsrealitsreal Jun 22, 2024
5c16a66
Fix indentation of template
itstrueitstrueitsrealitsreal Jun 22, 2024
c266fb9
Fix failing tests
itstrueitstrueitsrealitsreal Jun 23, 2024
352380d
Fix failing tests
itstrueitstrueitsrealitsreal Jun 23, 2024
956a762
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
eb3bcc9
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
c16ce56
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
810fee5
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
72f03ea
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
d35d94b
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
3ed526a
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
cc2c197
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
c2fbf33
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
4ef6028
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
366bf5b
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
59e5b6e
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
f896393
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
9e7825a
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
f897add
Fix failing tests
itstrueitstrueitsrealitsreal Jun 24, 2024
574d93a
Fix failing tests
itstrueitstrueitsrealitsreal Jun 25, 2024
a9ddb4e
Fix failing tests
itstrueitstrueitsrealitsreal Jun 25, 2024
cd63bae
Revert "Fix failing tests"
itstrueitstrueitsrealitsreal Jun 25, 2024
4814d1e
Revert "Fix failing tests"
itstrueitstrueitsrealitsreal Jun 25, 2024
1c4be4e
Reverting to the state of commit f897addc
itstrueitstrueitsrealitsreal Jun 25, 2024
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 @@ -11,6 +11,7 @@
import teammates.it.test.BaseTestCaseWithSqlDatabaseAccess;
import teammates.storage.sqlapi.AccountRequestsDb;
import teammates.storage.sqlentity.AccountRequest;
import teammates.test.TestProperties;

/**
* SUT: {@link AccountRequestsDb}.
Expand Down Expand Up @@ -239,6 +240,9 @@ public void testSqlInjectionInDeleteAccountRequest() throws Exception {

@Test
public void testSqlInjectionSearchAccountRequestsInWholeSystem() throws Exception {
if (!TestProperties.isSearchServiceActive()) {
return;
}
______TS("SQL Injection test in searchAccountRequestsInWholeSystem");

AccountRequest accountRequest =
Expand Down
33 changes: 33 additions & 0 deletions src/main/java/teammates/common/util/TimeHelper.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package teammates.common.util;

import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.time.Instant;
import java.time.OffsetDateTime;
Expand Down Expand Up @@ -162,4 +164,35 @@ public static Instant parseInstant(String dateTimeString) {
}
}

/**
* Generates a Google Calendar link with the given time, title, optional description, and time zone.
* @param instant The start time of the event.
* @param timeZone The ID of the time zone to be used for time formatting.
* @param title The title of the event.
* @param description The optional description of the event. Can be null or empty.
* @return The URL to create a Google Calendar event.
*/
public static String getGoogleCalendarLink(Instant instant, String timeZone, String title, String description) {
if (instant == null || timeZone == null || title == null) {
return "";
}

ZonedDateTime zonedDateTime = instant.atZone(ZoneId.of(timeZone));

// Define formatter with the Google Calendar expected format
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd'T'HHmmss'Z'")
.withZone(ZoneId.of(timeZone));

String startTime = formatter.format(zonedDateTime);
String endTime = formatter.format(zonedDateTime);

// URL encode title and optionally description to ensure special characters are handled properly
String encodedTitle = URLEncoder.encode(title, StandardCharsets.UTF_8);
String encodedDescription = (description != null) ? URLEncoder.encode(description, StandardCharsets.UTF_8) : "";

// Construct the Google Calendar URL
return String.format(
"https://www.google.com/calendar/render?action=TEMPLATE&text=%s&details=%s&dates=%s/%s",
encodedTitle, encodedDescription, startTime, endTime);
}
}
27 changes: 22 additions & 5 deletions src/main/java/teammates/logic/api/EmailGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public final class EmailGenerator {
private static final String DATETIME_DISPLAY_FORMAT = "EEE, dd MMM yyyy, hh:mm a z";

private static final long SESSION_LINK_RECOVERY_DURATION_IN_DAYS = 90;
private static final String FEEDBACK_DEADLINE_REMINDER_TITLE = "Feedback Session Deadline";

private static final EmailGenerator instance = new EmailGenerator();

Expand Down Expand Up @@ -317,7 +318,10 @@ public EmailWrapper generateFeedbackSessionSummaryOfCourse(
"${deadline}", TimeHelper.formatInstant(endTime, fsa.getTimeZone(), DATETIME_DISPLAY_FORMAT)
+ (fsa.isClosed() ? " (Passed)" : ""),
"${submitUrl}", submitUrlHtml,
"${reportUrl}", reportUrlHtml));
"${reportUrl}", reportUrlHtml,
"${googleCalendarLink}", TimeHelper.getGoogleCalendarLink(endTime,
fsa.getTimeZone(), FEEDBACK_DEADLINE_REMINDER_TITLE,
fsa.getFeedbackSessionName())));
}

if (linksFragmentValue.length() == 0) {
Expand Down Expand Up @@ -686,7 +690,11 @@ private EmailWrapper generateDeadlineExtensionEmail(
.replace("${oldEndTime}", SanitizationHelper.sanitizeForHtml(
TimeHelper.formatInstant(oldEndTimeFormatted, session.getTimeZone(), DATETIME_DISPLAY_FORMAT)))
.replace("${newEndTime}", SanitizationHelper.sanitizeForHtml(
TimeHelper.formatInstant(newEndTimeFormatted, session.getTimeZone(), DATETIME_DISPLAY_FORMAT)));
TimeHelper.formatInstant(newEndTimeFormatted, session.getTimeZone(),
DATETIME_DISPLAY_FORMAT))).replace("${googleCalendarLink}",
TimeHelper.getGoogleCalendarLink(newEndTimeFormatted, session.getTimeZone(),
FEEDBACK_DEADLINE_REMINDER_TITLE,
SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName())));
String feedbackAction = FEEDBACK_ACTION_SUBMIT_EDIT_OR_VIEW;

if (isInstructor) {
Expand Down Expand Up @@ -761,7 +769,10 @@ private EmailWrapper generateFeedbackSessionEmailBaseForStudents(
"${submitUrl}", submitUrl,
"${reportUrl}", reportUrl,
"${feedbackAction}", feedbackAction,
"${additionalContactInformation}", additionalContactInformation);
"${additionalContactInformation}", additionalContactInformation,
"${googleCalendarLink}", TimeHelper.getGoogleCalendarLink(endTime,
session.getTimeZone(), FEEDBACK_DEADLINE_REMINDER_TITLE,
SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName())));

EmailWrapper email = getEmptyEmailAddressedToEmail(student.getEmail());
email.setType(type);
Expand Down Expand Up @@ -802,7 +813,10 @@ private EmailWrapper generateFeedbackSessionEmailBaseForInstructors(
"${submitUrl}", submitUrl,
"${reportUrl}", reportUrl,
"${feedbackAction}", feedbackAction,
"${additionalContactInformation}", additionalContactInformation);
"${additionalContactInformation}", additionalContactInformation,
"${googleCalendarLink}", TimeHelper.getGoogleCalendarLink(endTime,
session.getTimeZone(), FEEDBACK_DEADLINE_REMINDER_TITLE,
SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName())));

EmailWrapper email = getEmptyEmailAddressedToEmail(instructor.getEmail());
email.setType(type);
Expand All @@ -828,7 +842,10 @@ private EmailWrapper generateFeedbackSessionEmailBaseForNotifiedInstructors(
"${submitUrl}", "{in the actual email sent to the students, this will be the unique link}",
"${reportUrl}", "{in the actual email sent to the students, this will be the unique link}",
"${feedbackAction}", feedbackAction,
"${additionalContactInformation}", additionalContactInformation);
"${additionalContactInformation}", additionalContactInformation,
"${googleCalendarLink}", TimeHelper.getGoogleCalendarLink(endTime,
session.getTimeZone(), FEEDBACK_DEADLINE_REMINDER_TITLE,
SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName())));

EmailWrapper email = getEmptyEmailAddressedToEmail(instructor.getEmail());
email.setType(type);
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/userEmailTemplate-deadlineExtension.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="${googleCalendarLink}">click here</a>.
</li>
</ul>
</p>

Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/userEmailTemplate-feedbackSession.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="${googleCalendarLink}">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="${googleCalendarLink}">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
To view the responses for this session, please go to this Web address: ${reportUrl}
<br>
<br>
To add this deadline to your Google Calendar, <a href="${googleCalendarLink}">click here</a>.
<br>
<br>
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270501T010000Z/20270501T010000Z">click here</a>.
</li>
</ul>
</p>

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/emails/deadlineExtensionGivenStudent.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270501T010000Z/20270501T010000Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270501T010000Z/20270501T010000Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270501T010000Z/20270501T010000Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270501T235900Z/20270501T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/emails/sessionClosingEmailForStudent.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270501T010000Z/20270501T010000Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=Normal+feedback+session+name&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=Normal+feedback+session+name&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/emails/sessionOpeningEmailForStudent.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=Normal+feedback+session+name&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=Normal+feedback+session+name&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
3 changes: 3 additions & 0 deletions src/test/resources/emails/sessionReminderEmailForStudent.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@
<li>
After submitting, you are encouraged to download the proof of submission, which will contain your latest responses.
</li>
<li>
To add this deadline to your Google Calendar, <a href="https://www.google.com/calendar/render?action=TEMPLATE&text=Feedback+Session+Deadline&details=First+feedback+session&dates=20270430T235900Z/20270430T235900Z">click here</a>.
</li>
</ul>
</p>

Expand Down
Loading
Loading