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