Search in sources :

Example 1 with InstructorsDb

use of teammates.storage.api.InstructorsDb in project teammates by TEAMMATES.

the class FeedbackResponsesLogicTest method testIsNameVisibleTo.

private void testIsNameVisibleTo() {
    ______TS("testIsNameVisibleTo");
    InstructorAttributes instructor = dataBundle.instructors.get("instructor1OfCourse1");
    StudentAttributes student = dataBundle.students.get("student1InCourse1");
    StudentAttributes student2 = dataBundle.students.get("student2InCourse1");
    StudentAttributes student3 = dataBundle.students.get("student3InCourse1");
    StudentAttributes student5 = dataBundle.students.get("student5InCourse1");
    FeedbackQuestionAttributes fq = getQuestionFromDatastore("qn3InSession1InCourse1");
    FeedbackResponseAttributes fr = getResponseFromDatastore("response1ForQ3S1C1");
    CourseRoster roster = new CourseRoster(new StudentsDb().getStudentsForCourse(fq.courseId), new InstructorsDb().getInstructorsForCourse(fq.courseId));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, instructor.email, UserRole.INSTRUCTOR, true, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, instructor.email, UserRole.INSTRUCTOR, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    ______TS("test if visible to own team members");
    fr.giver = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    ______TS("test if visible to receiver/reciever team members");
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER);
    fr.recipient = student.team;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.STUDENTS;
    fr.recipient = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student2.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER_TEAM_MEMBERS);
    fr.recipient = student.team;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student3.email, UserRole.STUDENT, false, roster));
    fq.recipientType = FeedbackParticipantType.STUDENTS;
    fr.recipient = student.email;
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student.email, UserRole.STUDENT, false, roster));
    assertTrue(frLogic.isNameVisibleToUser(fq, fr, student2.email, UserRole.STUDENT, false, roster));
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.email, UserRole.STUDENT, false, roster));
    ______TS("test anonymous team recipients");
    // Only members of the recipient team should be able to see the recipient name
    fq.recipientType = FeedbackParticipantType.TEAMS;
    fq.showRecipientNameTo.clear();
    fq.showRecipientNameTo.add(FeedbackParticipantType.RECEIVER);
    fq.showResponsesTo.add(FeedbackParticipantType.STUDENTS);
    fr.recipient = "Team 1.1";
    assertFalse(frLogic.isNameVisibleToUser(fq, fr, student5.email, UserRole.STUDENT, false, roster));
    ______TS("null question");
    assertFalse(frLogic.isNameVisibleToUser(null, fr, student.email, UserRole.STUDENT, false, roster));
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) CourseRoster(teammates.common.datatransfer.CourseRoster) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StudentsDb(teammates.storage.api.StudentsDb) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 2 with InstructorsDb

use of teammates.storage.api.InstructorsDb in project teammates by TEAMMATES.

the class InstructorSearchTest method allTests.

@Test
public void allTests() throws Exception {
    InstructorsDb instructorsDb = new InstructorsDb();
    InstructorAttributes ins1InCourse1 = dataBundle.instructors.get("instructor1OfCourse1");
    InstructorAttributes ins2InCourse1 = dataBundle.instructors.get("instructor2OfCourse1");
    InstructorAttributes helperInCourse1 = dataBundle.instructors.get("helperOfCourse1");
    InstructorAttributes ins1InCourse2 = dataBundle.instructors.get("instructor1OfCourse2");
    InstructorAttributes ins2InCourse2 = dataBundle.instructors.get("instructor2OfCourse2");
    InstructorAttributes ins3InCourse2 = dataBundle.instructors.get("instructor3OfCourse2");
    InstructorAttributes insInArchivedCourse = dataBundle.instructors.get("instructorOfArchivedCourse");
    InstructorAttributes insInUnregCourse = dataBundle.instructors.get("instructor5");
    InstructorAttributes ins1InTestingSanitizationCourse = dataBundle.instructors.get("instructor1OfTestingSanitizationCourse");
    ins1InTestingSanitizationCourse.sanitizeForSaving();
    ______TS("success: search for instructors in whole system; query string does not match anyone");
    InstructorSearchResultBundle results = instructorsDb.searchInstructorsInWholeSystem("non-existent");
    verifySearchResults(results);
    ______TS("success: search for instructors in whole system; empty query string does not match anyone");
    results = instructorsDb.searchInstructorsInWholeSystem("");
    verifySearchResults(results);
    ______TS("success: search for instructors in whole system; query string matches some instructors");
    results = instructorsDb.searchInstructorsInWholeSystem("instructor1");
    verifySearchResults(results, ins1InCourse1, ins1InCourse2, ins1InTestingSanitizationCourse);
    ______TS("success: search for instructors in whole system; query string should be case-insensitive");
    results = instructorsDb.searchInstructorsInWholeSystem("InStRuCtOr2");
    verifySearchResults(results, ins2InCourse1, ins2InCourse2);
    ______TS("success: search for instructors in whole system; instructors in archived courses should be included");
    results = instructorsDb.searchInstructorsInWholeSystem("archived");
    verifySearchResults(results, insInArchivedCourse);
    ______TS("success: search for instructors in whole system; instructors in unregistered course should be included");
    results = instructorsDb.searchInstructorsInWholeSystem("instructor5");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by course id");
    results = instructorsDb.searchInstructorsInWholeSystem("idOfUnregisteredCourse");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by course name");
    results = instructorsDb.searchInstructorsInWholeSystem("idOfTypicalCourse2");
    verifySearchResults(results, ins1InCourse2, ins2InCourse2, ins3InCourse2);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their name");
    results = instructorsDb.searchInstructorsInWholeSystem("\"Instructor 5 of CourseNoRegister\"");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their email");
    results = instructorsDb.searchInstructorsInWholeSystem("instructor2@course2.tmt");
    verifySearchResults(results, ins2InCourse2);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their google id");
    results = instructorsDb.searchInstructorsInWholeSystem("idOfInstructor5");
    verifySearchResults(results, insInUnregCourse);
    ______TS("success: search for instructors in whole system; instructors should be searchable by their role");
    results = instructorsDb.searchInstructorsInWholeSystem("Custom");
    verifySearchResults(results, helperInCourse1);
    ______TS("success: search for instructors in whole system; instructors should be searchable by displayed name");
    // create a new instructor with unique displayed name to test that field
    // current displayed names in data bundle are either helper or instructor, which matches on many other fields
    InstructorAttributes assistantProf = helperInCourse1.getCopy();
    String displayedName = "Assistant Prof Smith";
    assistantProf.displayedName = displayedName;
    instructorsDb.updateInstructorByEmail(assistantProf);
    results = instructorsDb.searchInstructorsInWholeSystem(displayedName);
    verifySearchResults(results, assistantProf);
    ______TS("success: search for instructors in whole system; deleted instructors no longer searchable");
    instructorsDb.deleteInstructor(ins1InCourse1.courseId, ins1InCourse1.email);
    results = instructorsDb.searchInstructorsInWholeSystem("instructor1");
    verifySearchResults(results, ins1InCourse2, ins1InTestingSanitizationCourse);
    ______TS("success: search for instructors in whole system; instructors created without searchability unsearchable");
    instructorsDb.createEntitiesWithoutExistenceCheck(Arrays.asList(ins1InCourse1));
    results = instructorsDb.searchInstructorsInWholeSystem("instructor1");
    verifySearchResults(results, ins1InCourse2, ins1InTestingSanitizationCourse);
    ______TS("success: search for instructors in whole system; deleting instructor without deleting document:" + "document deleted during search, instructor unsearchable");
    instructorsDb.deleteEntity(ins2InCourse1);
    results = instructorsDb.searchInstructorsInWholeSystem("instructor2");
    verifySearchResults(results, ins2InCourse2);
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) InstructorSearchResultBundle(teammates.common.datatransfer.InstructorSearchResultBundle) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 3 with InstructorsDb

use of teammates.storage.api.InstructorsDb in project teammates by TEAMMATES.

the class InstructorCourseJoinActionTest method testExecuteAndPostProcess.

@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    InstructorsDb instrDb = new InstructorsDb();
    // Reassign to let "key" variable in "instructor" not to be null
    instructor = instrDb.getInstructorForGoogleId(instructor.courseId, instructor.googleId);
    String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    ______TS("Invalid key, redirect for confirmation again");
    String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
    InstructorCourseJoinAction confirmAction = getAction(submissionParams);
    ShowPageResult pageResult = getShowPageResult(confirmAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "idOfInstructor1OfCourse1", invalidEncryptedKey), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    String expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + invalidEncryptedKey;
    AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
    ______TS("Already registered instructor, redirect straight to authentication page");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
    confirmAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(confirmAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN_AUTHENTICATED, StringHelper.encrypt(instructor.key), false, "idOfInstructor1OfCourse1"), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("", redirectResult.getStatusMessage());
    expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(instructor.key);
    AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
    ______TS("Typical case: unregistered instructor, redirect to confirmation page");
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAT.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAT.instr";
    AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    gaeSimulation.loginUser(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    confirmAction = getAction(submissionParams);
    pageResult = getShowPageResult(confirmAction);
    assertEquals(getPageResultDestination(Const.ViewURIs.INSTRUCTOR_COURSE_JOIN_CONFIRMATION, false, "ICJAT.instr", StringHelper.encrypt(newInstructor.key)), pageResult.getDestinationWithParams());
    assertFalse(pageResult.isError);
    assertEquals("", pageResult.getStatusMessage());
    expectedLogSegment = "Action Instructor Clicked Join Link" + "<br>Google ID: " + instructor.googleId + "<br>Key: " + StringHelper.encrypt(newInstructor.key);
    AssertHelper.assertContains(expectedLogSegment, confirmAction.getLogMessage());
}
Also used : InstructorsDb(teammates.storage.api.InstructorsDb) ShowPageResult(teammates.ui.controller.ShowPageResult) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorCourseJoinAction(teammates.ui.controller.InstructorCourseJoinAction) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 4 with InstructorsDb

use of teammates.storage.api.InstructorsDb in project teammates by TEAMMATES.

the class InstructorCourseJoinAuthenticatedActionTest method testExecuteAndPostProcess.

@SuppressWarnings("deprecation")
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
    InstructorAttributes instructor = typicalBundle.instructors.get("instructor1OfCourse1");
    InstructorsDb instrDb = new InstructorsDb();
    instructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    String invalidEncryptedKey = StringHelper.encrypt("invalidKey");
    gaeSimulation.loginAsInstructor(instructor.googleId);
    ______TS("Failure: Invalid key");
    String[] submissionParams = new String[] { Const.ParamsNames.REGKEY, invalidEncryptedKey };
    InstructorCourseJoinAuthenticatedAction joinAction = getAction(submissionParams);
    RedirectResult redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, true, "idOfInstructor1OfCourse1", invalidEncryptedKey), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals("You have used an invalid join link: " + Const.ActionURIs.INSTRUCTOR_COURSE_JOIN + "?key=" + invalidEncryptedKey, redirectResult.getStatusMessage());
    String expectedLogSegment = "Servlet Action Failure : You have used an invalid join link: " + Const.ActionURIs.INSTRUCTOR_COURSE_JOIN + "?key=" + invalidEncryptedKey + "<br><br>Action Instructor Joins Course<br>" + "Google ID: idOfInstructor1OfCourse1<br>Key : invalidKey";
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure: Instructor already registered");
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, instructor.courseId, true, "idOfInstructor1OfCourse1", StringHelper.encrypt(instructor.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(instructor.googleId + " has already joined this course", redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : " + instructor.googleId + " has already joined this course" + "<br><br>Action Instructor Joins Course<br>Google ID: " + instructor.googleId + "<br>Key : " + instructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure: the current key has been registered by another account");
    InstructorAttributes instructor2 = typicalBundle.instructors.get("instructor2OfCourse1");
    instructor2 = instrDb.getInstructorForGoogleId(instructor2.courseId, instructor2.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(instructor2.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, instructor2.courseId, true, "idOfInstructor1OfCourse1", StringHelper.encrypt(instructor2.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    AssertHelper.assertContains("The join link used belongs to a different user", redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : The join link used belongs to a different user";
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Typical case: authenticate for new instructor with corresponding key");
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor", "ICJAAT.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAAT.instr";
    AccountAttributes newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    InstructorAttributes newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    gaeSimulation.loginUser(instructor.googleId);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, "idOfTypicalCourse1", false, "ICJAAT.instr", StringHelper.encrypt(newInstructor.key)), redirectResult.getDestinationWithParams());
    assertFalse(redirectResult.isError);
    assertEquals("", redirectResult.getStatusMessage());
    InstructorAttributes retrievedInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    assertEquals(instructor.googleId, retrievedInstructor.googleId);
    expectedLogSegment = "Action Instructor Joins Course<br>Google ID: " + instructor.googleId + "<br>Key : " + newInstructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
    ______TS("Failure case: the current unused key is not for this account ");
    String currentLoginId = instructor.googleId;
    instructor = InstructorAttributes.builder(null, instructor.courseId, "New Instructor 2", "ICJAAT2.instr@email.com").build();
    InstructorsLogic.inst().createInstructor(instructor);
    instructor.googleId = "ICJAAT2.instr";
    newInstructorAccount = AccountAttributes.builder().withGoogleId(instructor.googleId).withName(instructor.name).withEmail(instructor.email).withInstitute("TEAMMATES Test Institute 5").withIsInstructor(false).withDefaultStudentProfileAttributes(instructor.googleId).build();
    AccountsLogic.inst().createAccount(newInstructorAccount);
    newInstructor = instrDb.getInstructorForEmail(instructor.courseId, instructor.email);
    submissionParams = new String[] { Const.ParamsNames.REGKEY, StringHelper.encrypt(newInstructor.key) };
    joinAction = getAction(submissionParams);
    redirectResult = getRedirectResult(joinAction);
    assertEquals(getPageResultDestination(Const.ActionURIs.INSTRUCTOR_HOME_PAGE, "idOfTypicalCourse1", true, "ICJAAT.instr", StringHelper.encrypt(newInstructor.key)), redirectResult.getDestinationWithParams());
    assertTrue(redirectResult.isError);
    assertEquals(String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, currentLoginId), redirectResult.getStatusMessage());
    expectedLogSegment = "Servlet Action Failure : " + String.format(Const.StatusMessages.JOIN_COURSE_GOOGLE_ID_BELONGS_TO_DIFFERENT_USER, currentLoginId) + "<br><br>Action Instructor Joins Course<br>Google ID: " + currentLoginId + "<br>Key : " + newInstructor.key;
    AssertHelper.assertContains(expectedLogSegment, joinAction.getLogMessage());
}
Also used : InstructorCourseJoinAuthenticatedAction(teammates.ui.controller.InstructorCourseJoinAuthenticatedAction) InstructorsDb(teammates.storage.api.InstructorsDb) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) RedirectResult(teammates.ui.controller.RedirectResult) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Aggregations

InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)4 InstructorsDb (teammates.storage.api.InstructorsDb)4 Test (org.testng.annotations.Test)3 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)2 RedirectResult (teammates.ui.controller.RedirectResult)2 CourseRoster (teammates.common.datatransfer.CourseRoster)1 InstructorSearchResultBundle (teammates.common.datatransfer.InstructorSearchResultBundle)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)1 StudentsDb (teammates.storage.api.StudentsDb)1 InstructorCourseJoinAction (teammates.ui.controller.InstructorCourseJoinAction)1 InstructorCourseJoinAuthenticatedAction (teammates.ui.controller.InstructorCourseJoinAuthenticatedAction)1 ShowPageResult (teammates.ui.controller.ShowPageResult)1