Skip to content

Commit

Permalink
[TEAMMATES#11571] Rename sanitize methods (TEAMMATES#11735)
Browse files Browse the repository at this point in the history
* Rename sanitize methods

* Rename usages from new code

Co-authored-by: Samuel Fang <[email protected]>
  • Loading branch information
jayasting98 and samuelfangjw authored Apr 16, 2022
1 parent 1f563e2 commit 3ad3f78
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,26 +121,26 @@ public FeedbackSessionAttributes getCopy() {
* Creates a copy that uses the specific deadline for the given student.
*
* @param studentEmail The email address of the given student.
* @return The sanitized copy of this object for the given student.
* @return The copy of this object for the given student.
*/
public FeedbackSessionAttributes sanitizeForStudent(String studentEmail) {
FeedbackSessionAttributes sanitizedCopy = getCopy();
sanitizedCopy.deadlineSupplier = () -> sanitizedCopy.studentDeadlines.getOrDefault(studentEmail, endTime);
sanitizedCopy.userEmail = studentEmail;
return sanitizedCopy;
public FeedbackSessionAttributes getCopyForStudent(String studentEmail) {
FeedbackSessionAttributes copy = getCopy();
copy.deadlineSupplier = () -> copy.studentDeadlines.getOrDefault(studentEmail, endTime);
copy.userEmail = studentEmail;
return copy;
}

/**
* Creates a copy that uses the specific deadline for the given instructor.
*
* @param instructorEmail The email address of the given instructor.
* @return The sanitized copy of this object for the given instructor.
* @return The copy of this object for the given instructor.
*/
public FeedbackSessionAttributes sanitizeForInstructor(String instructorEmail) {
FeedbackSessionAttributes sanitizedCopy = getCopy();
sanitizedCopy.deadlineSupplier = () -> sanitizedCopy.instructorDeadlines.getOrDefault(instructorEmail, endTime);
sanitizedCopy.userEmail = instructorEmail;
return sanitizedCopy;
public FeedbackSessionAttributes getCopyForInstructor(String instructorEmail) {
FeedbackSessionAttributes copy = getCopy();
copy.deadlineSupplier = () -> copy.instructorDeadlines.getOrDefault(instructorEmail, endTime);
copy.userEmail = instructorEmail;
return copy;
}

public String getCourseId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (studentAttributes == null) {
throw new EntityNotFoundException("Student does not exist.");
}
session = session.sanitizeForStudent(studentAttributes.getEmail());
session = session.getCopyForStudent(studentAttributes.getEmail());

gateKeeper.verifyAnswerableForStudent(question);
verifySessionOpenExceptForModeration(session);
Expand All @@ -71,7 +71,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (instructorAsFeedbackParticipant == null) {
throw new EntityNotFoundException("Instructor does not exist.");
}
session = session.sanitizeForInstructor(instructorAsFeedbackParticipant.getEmail());
session = session.getCopyForInstructor(instructorAsFeedbackParticipant.getEmail());

gateKeeper.verifyAnswerableForInstructor(question);
verifySessionOpenExceptForModeration(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
verifyNotPreview();

checkAccessControlForStudentFeedbackSubmission(student, session);
session = session.sanitizeForStudent(student.getEmail());
session = session.getCopyForStudent(student.getEmail());
verifySessionOpenExceptForModeration(session);
gateKeeper.verifyOwnership(frc,
question.getGiverType() == FeedbackParticipantType.TEAMS
Expand All @@ -56,7 +56,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
verifyNotPreview();

checkAccessControlForInstructorFeedbackSubmission(instructorAsFeedbackParticipant, session);
session = session.sanitizeForInstructor(instructorAsFeedbackParticipant.getEmail());
session = session.getCopyForInstructor(instructorAsFeedbackParticipant.getEmail());
verifySessionOpenExceptForModeration(session);
gateKeeper.verifyOwnership(frc, instructorAsFeedbackParticipant.getEmail());
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ public JsonResult execute() {
private FeedbackSessionData getStudentFeedbackSessionData(FeedbackSessionAttributes session) {
StudentAttributes student = getStudentOfCourseFromRequest(session.getCourseId());
String email = student.getEmail();
return new FeedbackSessionData(session.sanitizeForStudent(email));
return new FeedbackSessionData(session.getCopyForStudent(email));
}

private FeedbackSessionData getInstructorFeedbackSessionData(FeedbackSessionAttributes session) {
InstructorAttributes instructor = getInstructorOfCourseFromRequest(session.getCourseId());
String email = instructor.getEmail();
return new FeedbackSessionData(session.sanitizeForInstructor(email));
return new FeedbackSessionData(session.getCopyForInstructor(email));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public JsonResult execute() {

if (!userInfo.isAdmin) {
sessions = sessions.stream()
.map(session -> session.sanitizeForStudent(emailAddress))
.map(session -> session.getCopyForStudent(emailAddress))
.collect(Collectors.toList());
}

Expand All @@ -108,7 +108,7 @@ public JsonResult execute() {
assert student != null;
String emailAddress = student.getEmail();
feedbackSessionAttributes = feedbackSessionAttributes.stream()
.map(instructorSession -> instructorSession.sanitizeForStudent(emailAddress))
.map(instructorSession -> instructorSession.getCopyForStudent(emailAddress))
.collect(Collectors.toList());
} else if (entityType.equals(Const.EntityType.INSTRUCTOR)) {
instructors = Collections.singletonList(logic.getInstructorForGoogleId(courseId, userInfo.getId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (studentAttributes == null) {
throw new EntityNotFoundException("Student does not exist.");
}
feedbackSession = feedbackSession.sanitizeForStudent(studentAttributes.getEmail());
feedbackSession = feedbackSession.getCopyForStudent(studentAttributes.getEmail());
verifySessionOpenExceptForModeration(feedbackSession);
checkAccessControlForStudentFeedbackSubmission(studentAttributes, feedbackSession);
break;
Expand All @@ -70,7 +70,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (instructorAttributes == null) {
throw new EntityNotFoundException("Instructor does not exist.");
}
feedbackSession = feedbackSession.sanitizeForInstructor(instructorAttributes.getEmail());
feedbackSession = feedbackSession.getCopyForInstructor(instructorAttributes.getEmail());
verifySessionOpenExceptForModeration(feedbackSession);
checkAccessControlForInstructorFeedbackSubmission(instructorAttributes, feedbackSession);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (student == null) {
throw new EntityNotFoundException("Student does not exist.");
}
session = session.sanitizeForStudent(student.getEmail());
session = session.getCopyForStudent(student.getEmail());

gateKeeper.verifyAnswerableForStudent(question);
verifySessionOpenExceptForModeration(session);
Expand All @@ -70,7 +70,7 @@ void checkSpecificAccessControl() throws UnauthorizedAccessException {
if (instructorAsFeedbackParticipant == null) {
throw new EntityNotFoundException("Instructor does not exist.");
}
session = session.sanitizeForInstructor(instructorAsFeedbackParticipant.getEmail());
session = session.getCopyForInstructor(instructorAsFeedbackParticipant.getEmail());

gateKeeper.verifyAnswerableForInstructor(question);
verifySessionOpenExceptForModeration(session);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,20 +297,20 @@ public void testGetCopy() {
}

@Test
public void testSanitizeForStudent() {
public void testGetCopyForStudent() {
DataBundle typicalDataBundle = getTypicalDataBundle();
FeedbackSessionAttributes session1InCourse1 = typicalDataBundle.feedbackSessions
.get("session1InCourse1");

StudentAttributes student1InCourse1 = typicalDataBundle.students.get("student1InCourse1");
StudentAttributes student3InCourse1 = typicalDataBundle.students.get("student3InCourse1");

FeedbackSessionAttributes sanitizedSession1InCourse1 = session1InCourse1.sanitizeForStudent(
FeedbackSessionAttributes sanitizedSession1InCourse1 = session1InCourse1.getCopyForStudent(
student1InCourse1.getEmail());
assertEquals(sanitizedSession1InCourse1.getEndTime(), sanitizedSession1InCourse1.getDeadline());
assertEquals(student1InCourse1.getEmail(), sanitizedSession1InCourse1.getUserEmail());

sanitizedSession1InCourse1 = session1InCourse1.sanitizeForStudent(student3InCourse1.getEmail());
sanitizedSession1InCourse1 = session1InCourse1.getCopyForStudent(student3InCourse1.getEmail());
assertEquals(sanitizedSession1InCourse1.getStudentDeadlines().get(student3InCourse1.getEmail()),
sanitizedSession1InCourse1.getDeadline());
assertEquals(student3InCourse1.getEmail(), sanitizedSession1InCourse1.getUserEmail());
Expand All @@ -319,20 +319,20 @@ public void testSanitizeForStudent() {
}

@Test
public void testSanitizeForInstructor() {
public void testGetCopyForInstructor() {
DataBundle typicalDataBundle = getTypicalDataBundle();
FeedbackSessionAttributes session1InCourse1 = typicalDataBundle.feedbackSessions
.get("session1InCourse1");

InstructorAttributes helperOfCourse1 = typicalDataBundle.instructors.get("helperOfCourse1");
InstructorAttributes instructor1OfCourse1 = typicalDataBundle.instructors.get("instructor1OfCourse1");

FeedbackSessionAttributes sanitizedSession1InCourse1 = session1InCourse1.sanitizeForInstructor(
FeedbackSessionAttributes sanitizedSession1InCourse1 = session1InCourse1.getCopyForInstructor(
helperOfCourse1.getEmail());
assertEquals(sanitizedSession1InCourse1.getEndTime(), sanitizedSession1InCourse1.getDeadline());
assertEquals(helperOfCourse1.getEmail(), sanitizedSession1InCourse1.getUserEmail());

sanitizedSession1InCourse1 = session1InCourse1.sanitizeForInstructor(instructor1OfCourse1.getEmail());
sanitizedSession1InCourse1 = session1InCourse1.getCopyForInstructor(instructor1OfCourse1.getEmail());
assertEquals(sanitizedSession1InCourse1.getInstructorDeadlines().get(instructor1OfCourse1.getEmail()),
sanitizedSession1InCourse1.getDeadline());
assertEquals(instructor1OfCourse1.getEmail(), sanitizedSession1InCourse1.getUserEmail());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ protected void testExecute_asStudentWithDeadlines_shouldHaveCorrectSubmissionSta
.withEndTime(newEndTime)
.build());
List<FeedbackSessionAttributes> expectedSessions = sessionsInCourse1.stream()
.map(session -> session.sanitizeForStudent(emailAddress))
.map(session -> session.getCopyForStudent(emailAddress))
.collect(Collectors.toList());
int expectedSession2InCourse1Index = expectedSessions.indexOf(session2InCourse1);
FeedbackSessionAttributes expectedSession2InCourse1 = expectedSessions.get(expectedSession2InCourse1Index);
Expand Down

0 comments on commit 3ad3f78

Please sign in to comment.