Search in sources :

Example 21 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorPrivilegesTest method testUpdatePrivilegeInCourseLevel.

@Test
public void testUpdatePrivilegeInCourseLevel() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, false);
    Map<String, Boolean> courseLevelPrivileges = privileges.getCourseLevelPrivileges();
    assertFalse(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    String invalidPrivilegeName = "invalidPrivilegeName";
    privileges.updatePrivilege(invalidPrivilegeName, false);
    courseLevelPrivileges = privileges.getCourseLevelPrivileges();
    assertFalse(courseLevelPrivileges.containsKey(invalidPrivilegeName));
    assertFalse(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertTrue(courseLevelPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 22 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorPrivilegesTest method testUpdatePrivilegesInSessionLevel.

@Test
public void testUpdatePrivilegesInSessionLevel() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    String sectionId = "sectionId";
    String sessionId = "sessionId";
    Map<String, Boolean> privilegeMap = new LinkedHashMap<>();
    privilegeMap.put(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    privilegeMap.put(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS, false);
    privileges.updatePrivileges(sectionId, sessionId, privilegeMap);
    assertEquals(1, privileges.getSessionLevelPrivileges().size());
    assertTrue(privileges.getSessionLevelPrivileges().containsKey(sectionId));
    assertEquals(1, privileges.getSessionLevelPrivileges().get(sectionId).size());
    assertTrue(privileges.getSessionLevelPrivileges().get(sectionId).containsKey(sessionId));
    Map<String, Boolean> sessionPrivileges = privileges.getSessionLevelPrivileges().get(sectionId).get(sessionId);
    assertEquals(2, sessionPrivileges.size());
    assertFalse(sessionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertFalse(sessionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    String invalidPrivilegeName = "invalidPrivilegeName";
    privilegeMap.put(invalidPrivilegeName, false);
    privileges.updatePrivileges(sectionId, sessionId, privilegeMap);
    sessionPrivileges = privileges.getSessionLevelPrivileges().get(sectionId).get(sessionId);
    assertEquals(2, sessionPrivileges.size());
    assertFalse(sessionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertFalse(sessionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 23 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorPrivilegesTest method testAddSectionWithDefaultPrivilegesToSectionLevel.

@Test
public void testAddSectionWithDefaultPrivilegesToSectionLevel() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    String sectionId = "sectionId";
    String sectionId2 = "sectionId2";
    privileges.addSectionWithDefaultPrivileges(sectionId);
    assertEquals(1, privileges.getSectionLevelPrivileges().size());
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId));
    privileges.addSectionWithDefaultPrivileges(sectionId);
    assertEquals(1, privileges.getSectionLevelPrivileges().size());
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId));
    privileges.addSectionWithDefaultPrivileges(sectionId2);
    assertEquals(2, privileges.getSectionLevelPrivileges().size());
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId));
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId2));
// TODO: more checking for this and the method follows
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 24 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorPrivilegesTest method testValidatePrivileges.

@Test
public void testValidatePrivileges() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, false);
    privileges.validatePrivileges();
    assertTrue(privileges.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    // restore courseLevel to pre-validate
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, false);
    String sectionName = "section";
    privileges.addSectionWithDefaultPrivileges(sectionName);
    privileges.validatePrivileges();
    assertTrue(privileges.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(privileges.isAllowedForPrivilege(sectionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, false);
    privileges.updatePrivilege(sectionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    privileges.updatePrivilege(sectionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, false);
    String sessionName = "session";
    privileges.addSessionWithDefaultPrivileges(sectionName, sessionName);
    privileges.validatePrivileges();
    assertTrue(privileges.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(privileges.isAllowedForPrivilege(sectionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(privileges.isAllowedForPrivilege(sectionName, sessionName, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 25 with InstructorPrivileges

use of teammates.common.datatransfer.InstructorPrivileges in project teammates by TEAMMATES.

the class InstructorCourseEditPageUiTest method testDeleteInstructorAction.

private void testDeleteInstructorAction() {
    ______TS("delete instructor then cancel");
    courseEditPage.clickDeleteInstructorLinkAndCancel(1);
    assertNotNull(BackDoor.getInstructorByGoogleId(instructorId, courseId));
    ______TS("delete instructor successfully");
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    String expectedMsg = "The instructor has been deleted from the course.";
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(expectedMsg);
    ______TS("delete all other instructors");
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    courseEditPage.clickDeleteInstructorLinkAndConfirm(2);
    ______TS("test the only registered instructor with the privilege to modify instructors cannot be deleted");
    // Create an registered instructor with all privileges except modifying instructors
    InstructorPrivileges privilege = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    privilege.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, false);
    InstructorAttributes instructor = InstructorAttributes.builder("InsCrsEdit.reg", courseId, "Teammates Reg", "InsCrsEdit.reg@gmail.tmt").withDisplayedName("Teammates Reg").withRole(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_CUSTOM).withPrivileges(privilege).build();
    BackDoor.createInstructor(instructor);
    // Create an unregistered instructor with co-owner privilege
    courseEditPage.addNewInstructor("Unreg Instructor", "InstructorCourseEditEmail@gmail.tmt");
    // Delete own instructor role
    courseEditPage.clickDeleteInstructorLinkAndConfirm(2);
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETE_NOT_ALLOWED);
    // Delete other instructors
    courseEditPage.clickDeleteInstructorLinkAndConfirm(3);
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED);
    courseEditPage.clickDeleteInstructorLinkAndConfirm(1);
    courseEditPage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED);
    ______TS("delete own instructor role and redirect to courses page");
    // Create another registered instructor with co-owner privilege
    BackDoor.createInstructor(testData.instructors.get("InsCrsEdit.coord"));
    courseEditPage = getCourseEditPage();
    // Delete own instructor role
    courseEditPage.clickDeleteInstructorLinkAndConfirm(2);
    InstructorCoursesPage coursesPage = courseEditPage.changePageType(InstructorCoursesPage.class);
    coursesPage.waitForAjaxLoadCoursesSuccess();
    coursesPage.waitForTextsForAllStatusMessagesToUserEquals(Const.StatusMessages.COURSE_INSTRUCTOR_DELETED, Const.StatusMessages.COURSE_EMPTY);
    // Restore own instructor role to ensure remaining test cases work properly
    BackDoor.createInstructor(testData.instructors.get("InsCrsEdit.test"));
}
Also used : InstructorCoursesPage(teammates.test.pageobjects.InstructorCoursesPage) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Aggregations

InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)28 Test (org.testng.annotations.Test)21 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)14 InvalidParametersException (teammates.common.exception.InvalidParametersException)5 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)3 LinkedHashMap (java.util.LinkedHashMap)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 Instructor (teammates.storage.entity.Instructor)2 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)1 InstructorCoursesPage (teammates.test.pageobjects.InstructorCoursesPage)1