Search in sources :

Example 6 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testConstructor.

@Test
public void testConstructor() {
    InstructorPrivileges privileges = new InstructorPrivileges();
    InstructorPrivileges privileges1 = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    privileges.setDefaultPrivilegesForCoowner();
    assertEquals(privileges, privileges1);
    privileges.setDefaultPrivilegesForManager();
    privileges1 = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER);
    assertEquals(privileges, privileges1);
    privileges.setDefaultPrivilegesForObserver();
    privileges1 = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER);
    assertEquals(privileges, privileges1);
    privileges.setDefaultPrivilegesForTutor();
    privileges1 = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_TUTOR);
    assertEquals(privileges, privileges1);
    privileges.setDefaultPrivilegesForCustom();
    privileges1 = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_CUSTOM);
    assertEquals(privileges, privileges1);
    privileges1 = new InstructorPrivileges("random string");
    assertEquals(privileges, privileges1);
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 7 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testSetDefault.

@Test
public void testSetDefault() {
    InstructorPrivileges privileges = new InstructorPrivileges();
    Map<String, Boolean> courseLevelMap;
    // co-owner: all true
    privileges.setDefaultPrivilegesForCoowner();
    courseLevelMap = privileges.getCourseLevelPrivileges();
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    String invalidKey = "invalid key";
    assertNull(courseLevelMap.get(invalidKey));
    assertTrue(privileges.getSessionLevelPrivileges().isEmpty());
    // manager: only one false
    privileges.setDefaultPrivilegesForManager();
    courseLevelMap = privileges.getCourseLevelPrivileges();
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    // observer: view only
    privileges.setDefaultPrivilegesForObserver();
    courseLevelMap = privileges.getCourseLevelPrivileges();
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    // tutor
    privileges.setDefaultPrivilegesForTutor();
    courseLevelMap = privileges.getCourseLevelPrivileges();
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertTrue(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    // helper
    privileges.setDefaultPrivilegesForCustom();
    courseLevelMap = privileges.getCourseLevelPrivileges();
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertFalse(courseLevelMap.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 8 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testUpdatePrivilegeInSessionLevel.

@Test
public void testUpdatePrivilegeInSessionLevel() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    String sectionId = "sectionId";
    String sessionId = "sessionId";
    privileges.updatePrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS, false);
    privileges.updatePrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS, false);
    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";
    privileges.updatePrivilege(sectionId, sessionId, invalidPrivilegeName, false);
    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) Test(org.testng.annotations.Test)

Example 9 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testAddSessionWithDefaultPrivilegesToSessionLevel.

@Test
public void testAddSessionWithDefaultPrivilegesToSessionLevel() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    String sectionId = "sectionId";
    String sectionId2 = "sectionId2";
    String sessionId = "sessionId";
    String sessionId2 = "sessionId2";
    privileges.addSessionWithDefaultPrivileges(sectionId, sessionId);
    privileges.addSessionWithDefaultPrivileges(sectionId, sessionId);
    privileges.addSessionWithDefaultPrivileges(sectionId, sessionId2);
    privileges.addSessionWithDefaultPrivileges(sectionId2, sessionId);
    assertEquals(2, privileges.getSessionLevelPrivileges().size());
    assertTrue(privileges.getSessionLevelPrivileges().containsKey(sectionId));
    assertTrue(privileges.getSessionLevelPrivileges().containsKey(sectionId2));
    assertEquals(2, privileges.getSessionLevelPrivileges().get(sectionId).size());
    assertEquals(1, privileges.getSessionLevelPrivileges().get(sectionId2).size());
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 10 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testUpdatePrivilegesInSectionLevel.

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

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