Search in sources :

Example 1 with InstructorPrivileges

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

the class InstructorCourseInstructorAddAction method createInstructorWithBasicAttributes.

/**
 * Creates a new instructor with basic information.
 * This consists of everything apart from custom privileges.
 *
 * @param courseId              Id of the course the instructor is being added to.
 * @param instructorName        Name of the instructor.
 * @param instructorEmail       Email of the instructor.
 * @param instructorRole        Role of the instructor.
 * @param isDisplayedToStudents Whether the instructor should be visible to students.
 * @param displayedName         Name to be visible to students.
 *                                  Should not be {@code null} even if {@code isDisplayedToStudents} is false.
 * @return An instructor with basic info, excluding custom privileges
 */
private InstructorAttributes createInstructorWithBasicAttributes(String courseId, String instructorName, String instructorEmail, String instructorRole, boolean isDisplayedToStudents, String displayedName) {
    String instrName = SanitizationHelper.sanitizeName(instructorName);
    String instrEmail = SanitizationHelper.sanitizeEmail(instructorEmail);
    String instrRole = SanitizationHelper.sanitizeName(instructorRole);
    String instrDisplayedName = SanitizationHelper.sanitizeName(displayedName);
    InstructorPrivileges privileges = new InstructorPrivileges(instructorRole);
    return InstructorAttributes.builder(null, courseId, instrName, instrEmail).withRole(instrRole).withIsDisplayedToStudents(isDisplayedToStudents).withDisplayedName(instrDisplayedName).withPrivileges(privileges).build();
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges)

Example 2 with InstructorPrivileges

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

the class Logic method addInstructor.

/**
 * Add an instructor for a course. <br>
 * Preconditions: <br>
 * * All parameters are non-null.
 */
@Deprecated
public void addInstructor(String courseId, String name, String email, String role) throws InvalidParametersException, EntityAlreadyExistsException {
    Assumption.assertNotNull(courseId);
    Assumption.assertNotNull(name);
    Assumption.assertNotNull(email);
    InstructorAttributes instructor = InstructorAttributes.builder(null, courseId, name, email).withRole(role).withPrivileges(new InstructorPrivileges(role)).build();
    instructorsLogic.createInstructor(instructor);
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 3 with InstructorPrivileges

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

the class InstructorsDbTest method testUpdateInstructorByEmail.

@Test
public void testUpdateInstructorByEmail() throws Exception {
    InstructorAttributes instructorToEdit = instructorsDb.getInstructorForEmail("idOfTypicalCourse1", "instructor1@course1.tmt");
    ______TS("Success: update an instructor");
    instructorToEdit.googleId = "new-id";
    instructorToEdit.name = "New Name";
    instructorToEdit.isArchived = true;
    instructorToEdit.role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER;
    instructorToEdit.isDisplayedToStudents = false;
    instructorToEdit.displayedName = "New Displayed Name";
    instructorToEdit.privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER);
    instructorsDb.updateInstructorByEmail(instructorToEdit);
    InstructorAttributes instructorUpdated = instructorsDb.getInstructorForEmail(instructorToEdit.courseId, instructorToEdit.email);
    assertEquals("new-id", instructorUpdated.googleId);
    assertEquals("New Name", instructorUpdated.name);
    assertTrue(instructorUpdated.isArchived);
    assertEquals(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_OBSERVER, instructorUpdated.role);
    assertFalse(instructorUpdated.isDisplayedToStudents);
    assertEquals("New Displayed Name", instructorUpdated.displayedName);
    assertTrue(instructorUpdated.hasObserverPrivileges());
    // Verifying less privileged 'Observer' role did not return false positive in case old 'CoOwner' role is unchanged.
    assertFalse(instructorUpdated.hasCoownerPrivileges());
    ______TS("Failure: invalid parameters");
    instructorToEdit.googleId = "invalid id";
    instructorToEdit.name = "";
    instructorToEdit.role = "invalid role";
    try {
        instructorsDb.updateInstructorByEmail(instructorToEdit);
        signalFailureToDetectException();
    } catch (InvalidParametersException e) {
        AssertHelper.assertContains(getPopulatedErrorMessage(FieldValidator.GOOGLE_ID_ERROR_MESSAGE, instructorToEdit.googleId, FieldValidator.GOOGLE_ID_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.GOOGLE_ID_MAX_LENGTH) + System.lineSeparator() + getPopulatedEmptyStringErrorMessage(FieldValidator.SIZE_CAPPED_NON_EMPTY_STRING_ERROR_MESSAGE_EMPTY_STRING, FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.PERSON_NAME_MAX_LENGTH) + System.lineSeparator() + String.format(FieldValidator.ROLE_ERROR_MESSAGE, instructorToEdit.role), e.getMessage());
    }
    ______TS("Failure: non-existent entity");
    instructorToEdit.googleId = "idOfInstructor4";
    instructorToEdit.name = "New Name 2";
    instructorToEdit.email = "newEmail@email.tmt";
    instructorToEdit.role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER;
    try {
        instructorsDb.updateInstructorByEmail(instructorToEdit);
        signalFailureToDetectException();
    } catch (EntityDoesNotExistException e) {
        AssertHelper.assertContains(EntitiesDb.ERROR_UPDATE_NON_EXISTENT_ACCOUNT, e.getMessage());
    }
    ______TS("Failure: null parameters");
    try {
        instructorsDb.updateInstructorByEmail(null);
        signalFailureToDetectException();
    } catch (AssertionError e) {
        assertEquals(Const.StatusCodes.DBLEVEL_NULL_INPUT, e.getMessage());
    }
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) Test(org.testng.annotations.Test)

Example 4 with InstructorPrivileges

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

the class InstructorAttributesTest method testBuilderWithNullArguments.

@Test
public void testBuilderWithNullArguments() {
    InstructorAttributes instructorWithNullValues = InstructorAttributes.builder(null, null, null, null).withRole(null).withDisplayedName(null).withIsArchived(null).withPrivileges((InstructorPrivileges) null).build();
    // No default values for required params
    assertNull(instructorWithNullValues.googleId);
    assertNull(instructorWithNullValues.courseId);
    assertNull(instructorWithNullValues.name);
    assertNull(instructorWithNullValues.email);
    // Check default values for optional params
    assertEquals(DEFAULT_ROLE_NAME, instructorWithNullValues.role);
    assertEquals(DEFAULT_DISPLAYED_NAME, instructorWithNullValues.displayedName);
    assertEquals(DEFAULT_PRIVILEGES, instructorWithNullValues.privileges);
    assertFalse(instructorWithNullValues.isArchived);
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) Test(org.testng.annotations.Test)

Example 5 with InstructorPrivileges

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

the class InstructorAttributesTest method testIsEqualToAnotherInstructor.

@Test
public void testIsEqualToAnotherInstructor() {
    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();
    InstructorPrivileges privileges2 = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_MANAGER);
    InstructorAttributes instructor2 = InstructorAttributes.builder(googleId, courseId, name, email).withRole(roleName).withDisplayedName(displayedName).withPrivileges(privileges2).build();
    assertTrue(instructor.isEqualToAnotherInstructor(instructor2));
    instructor2.privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, true);
    assertFalse(instructor.isEqualToAnotherInstructor(instructor2));
    instructor2.privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_COURSE, false);
    assertTrue(instructor.isEqualToAnotherInstructor(instructor2));
// TODO: find ways to test this method more thoroughly
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) 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