Search in sources :

Example 16 with InstructorPrivileges

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

the class InstructorAttributesTest method testSanitizeForSaving.

@Test
public void testSanitizeForSaving() {
    String googleId = "valid.googleId";
    String courseId = "courseId";
    String name = "name";
    String email = "email@google.com";
    String roleName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    String displayedName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder(googleId, courseId, name, email).withRole(roleName).withDisplayedName(displayedName).withPrivileges(privileges).build();
    instructor.sanitizeForSaving();
    assertEquals(privileges, instructor.privileges);
    instructor.role = null;
    instructor.displayedName = null;
    instructor.privileges = null;
    instructor.sanitizeForSaving();
    assertEquals(privileges, instructor.privileges);
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 17 with InstructorPrivileges

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

the class InstructorAttributesTest method testToEntity.

@Override
@Test
public void testToEntity() {
    String googleId = "valid.googleId";
    String courseId = "courseId";
    String name = "name";
    String email = "email@google.com";
    String roleName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    String displayedName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder(googleId, courseId, name, email).withRole(roleName).withDisplayedName(displayedName).withPrivileges(privileges).build();
    String key = "randomKey";
    instructor.key = key;
    Instructor entity = instructor.toEntity();
    assertEquals(key, entity.getRegistrationKey());
}
Also used : Instructor(teammates.storage.entity.Instructor) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 18 with InstructorPrivileges

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

the class InstructorAttributesTest method testIsAllowedForPrivilege.

@Test
public void testIsAllowedForPrivilege() {
    String googleId = "valid.googleId";
    String courseId = "courseId";
    String name = "name";
    String email = "email@google.com";
    String roleName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    String displayedName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER);
    InstructorAttributes instructor = InstructorAttributes.builder(googleId, courseId, name, email).withRole(roleName).withDisplayedName(displayedName).withPrivileges(privileges).build();
    assertFalse(instructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    instructor.privileges = null;
    assertTrue(instructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    String sectionId = "sectionId";
    String sessionId = "sessionId";
    assertTrue(instructor.isAllowedForPrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    instructor.privileges = null;
    assertTrue(instructor.isAllowedForPrivilege(sectionId, sessionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 19 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testUpdatePrivilegeInSectionLevel.

@Test
public void testUpdatePrivilegeInSectionLevel() {
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    String sectionId = "sectionId";
    privileges.updatePrivilege(sectionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS, false);
    assertEquals(1, privileges.getSectionLevelPrivileges().size());
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId));
    privileges.updatePrivilege(sectionId, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, false);
    Map<String, Boolean> sectionPrivileges = privileges.getSectionLevelPrivileges().get(sectionId);
    assertEquals(1, privileges.getSectionLevelPrivileges().size());
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId));
    assertNull(sectionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE));
    assertFalse(sectionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS));
    assertNull(sectionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_SESSION_IN_SECTIONS));
    assertNull(sectionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS));
    assertNull(sectionPrivileges.get(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS));
    String invalidPrivilegeName = "invalidPrivilegeName";
    privileges.updatePrivilege(sectionId, invalidPrivilegeName, false);
    assertEquals(1, privileges.getSectionLevelPrivileges().size());
    assertTrue(privileges.getSectionLevelPrivileges().containsKey(sectionId));
    assertEquals(1, privileges.getSectionLevelPrivileges().get(sectionId).size());
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) Test(org.testng.annotations.Test)

Example 20 with InstructorPrivileges

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

the class InstructorPrivilegesTest method testHasDefaultPrivileges.

@Test
public void testHasDefaultPrivileges() {
    InstructorPrivileges coownerPrivileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    assertTrue(coownerPrivileges.hasCoownerPrivileges());
    assertFalse(coownerPrivileges.hasManagerPrivileges());
    assertFalse(coownerPrivileges.hasObserverPrivileges());
    assertFalse(coownerPrivileges.hasTutorPrivileges());
    InstructorPrivileges managerPrivileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER);
    assertTrue(managerPrivileges.hasManagerPrivileges());
    assertFalse(managerPrivileges.hasCoownerPrivileges());
    assertFalse(managerPrivileges.hasObserverPrivileges());
    assertFalse(managerPrivileges.hasTutorPrivileges());
    InstructorPrivileges observerPrivileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER);
    assertTrue(observerPrivileges.hasObserverPrivileges());
    assertFalse(observerPrivileges.hasCoownerPrivileges());
    assertFalse(observerPrivileges.hasManagerPrivileges());
    assertFalse(observerPrivileges.hasTutorPrivileges());
    InstructorPrivileges tutorPrivileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_TUTOR);
    assertTrue(tutorPrivileges.hasTutorPrivileges());
    assertFalse(tutorPrivileges.hasCoownerPrivileges());
    assertFalse(tutorPrivileges.hasManagerPrivileges());
    assertFalse(tutorPrivileges.hasObserverPrivileges());
    InstructorPrivileges nonDefaultPrivileges = new InstructorPrivileges();
    nonDefaultPrivileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, true);
    nonDefaultPrivileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT, true);
    nonDefaultPrivileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, false);
    nonDefaultPrivileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION, false);
    assertFalse(nonDefaultPrivileges.hasCoownerPrivileges());
    assertFalse(nonDefaultPrivileges.hasManagerPrivileges());
    assertFalse(nonDefaultPrivileges.hasObserverPrivileges());
    assertFalse(nonDefaultPrivileges.hasTutorPrivileges());
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) 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