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);
}
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());
}
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));
}
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());
}
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());
}
Aggregations