Search in sources :

Example 26 with InstructorPrivileges

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

the class CoursesLogic method createCourseAndInstructor.

/**
 * Creates a Course object and an Instructor object for the Course.
 */
public void createCourseAndInstructor(String instructorGoogleId, String courseId, String courseName, String courseTimeZone) throws InvalidParametersException, EntityAlreadyExistsException {
    AccountAttributes courseCreator = accountsLogic.getAccount(instructorGoogleId);
    Assumption.assertNotNull("Trying to create a course for a non-existent instructor :" + instructorGoogleId, courseCreator);
    Assumption.assertTrue("Trying to create a course for a person who doesn't have instructor privileges :" + instructorGoogleId, courseCreator.isInstructor);
    createCourse(courseId, courseName, courseTimeZone);
    /* Create the initial instructor for the course */
    InstructorPrivileges privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    InstructorAttributes instructor = InstructorAttributes.builder(instructorGoogleId, courseId, courseCreator.name, courseCreator.email).withPrivileges(privileges).build();
    try {
        instructorsLogic.createInstructor(instructor);
    } catch (EntityAlreadyExistsException | InvalidParametersException e) {
        // roll back the transaction
        coursesDb.deleteCourse(courseId);
        String errorMessage = "Unexpected exception while trying to create instructor for a new course " + System.lineSeparator() + instructor.toString() + System.lineSeparator() + TeammatesException.toStringWithStackTrace(e);
        Assumption.fail(errorMessage);
    }
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) EntityAlreadyExistsException(teammates.common.exception.EntityAlreadyExistsException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 27 with InstructorPrivileges

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

the class InstructorAttributes method sanitizeForSaving.

@Override
public void sanitizeForSaving() {
    googleId = SanitizationHelper.sanitizeGoogleId(googleId);
    name = SanitizationHelper.sanitizeForHtml(SanitizationHelper.sanitizeName(name));
    email = SanitizationHelper.sanitizeEmail(email);
    courseId = SanitizationHelper.sanitizeTitle(courseId);
    if (role == null) {
        role = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    } else {
        role = SanitizationHelper.sanitizeForHtml(SanitizationHelper.sanitizeName(role));
    }
    if (displayedName == null) {
        displayedName = Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER;
    } else {
        displayedName = SanitizationHelper.sanitizeForHtml(SanitizationHelper.sanitizeName(displayedName));
    }
    if (privileges == null) {
        privileges = new InstructorPrivileges(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_COOWNER);
    }
}
Also used : InstructorPrivileges(teammates.common.datatransfer.InstructorPrivileges)

Example 28 with InstructorPrivileges

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

the class InstructorCourseInstructorEditSaveAction method updateBasicInstructorAttributes.

/**
 * Edits an existing instructor's basic information.
 * This consists of everything apart from custom privileges.
 *
 * @param courseId              Id of the course the instructor is being added to.
 * @param instructorId          Id of the instructor.
 * @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 The edited instructor with updated basic info, and its old custom privileges (if applicable)
 */
private InstructorAttributes updateBasicInstructorAttributes(String courseId, String instructorId, String instructorName, String instructorEmail, String instructorRole, boolean isDisplayedToStudents, String displayedName) {
    InstructorAttributes instructorToEdit = null;
    if (instructorId == null) {
        instructorToEdit = logic.getInstructorForEmail(courseId, instructorEmail);
    } else {
        instructorToEdit = logic.getInstructorForGoogleId(courseId, instructorId);
    }
    instructorToEdit.name = SanitizationHelper.sanitizeName(instructorName);
    instructorToEdit.email = SanitizationHelper.sanitizeEmail(instructorEmail);
    instructorToEdit.role = SanitizationHelper.sanitizeName(instructorRole);
    instructorToEdit.displayedName = SanitizationHelper.sanitizeName(displayedName);
    instructorToEdit.isDisplayedToStudents = isDisplayedToStudents;
    instructorToEdit.privileges = new InstructorPrivileges(instructorToEdit.role);
    return instructorToEdit;
}
Also used : 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