use of teammates.common.datatransfer.attributes.InstructorAttributes in project teammates by TEAMMATES.
the class InstructorCourseInstructorEditSaveAction method execute.
@Override
protected ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
String instructorId = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ID);
String instructorName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME);
Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_NAME, instructorName);
String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_EMAIL, instructorEmail);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
InstructorAttributes instructorToEdit = extractUpdatedInstructor(courseId, instructorId, instructorName, instructorEmail);
updateToEnsureValidityOfInstructorsForTheCourse(courseId, instructorToEdit);
try {
if (instructorId == null) {
logic.updateInstructorByEmail(instructorEmail, instructorToEdit);
} else {
logic.updateInstructorByGoogleId(instructorId, instructorToEdit);
}
statusToUser.add(new StatusMessage(String.format(Const.StatusMessages.COURSE_INSTRUCTOR_EDITED, instructorName), StatusMessageColor.SUCCESS));
statusToAdmin = "Instructor <span class=\"bold\"> " + instructorName + "</span>" + " for Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Name: " + instructorName + "<br>New Email: " + instructorEmail;
} catch (InvalidParametersException e) {
setStatusForException(e);
}
/* Create redirection to 'Edit' page with corresponding course id */
RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE);
result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
return result;
}
use of teammates.common.datatransfer.attributes.InstructorAttributes in project teammates by TEAMMATES.
the class InstructorCourseInstructorEditSaveAction method extractUpdatedInstructor.
/**
* Creates a new instructor representing the updated instructor with all information filled in,
* using request parameters.
* This includes basic information as well as custom privileges (if applicable).
*
* @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.
* @return The updated instructor with all relevant info filled in.
*/
private InstructorAttributes extractUpdatedInstructor(String courseId, String instructorId, String instructorName, String instructorEmail) {
String instructorRole = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ROLE_NAME);
Assumption.assertPostParamNotNull(Const.ParamsNames.INSTRUCTOR_ROLE_NAME, instructorRole);
boolean isDisplayedToStudents = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_IS_DISPLAYED_TO_STUDENT) != null;
String displayedName = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_DISPLAY_NAME);
if (displayedName == null || displayedName.isEmpty()) {
displayedName = InstructorAttributes.DEFAULT_DISPLAY_NAME;
}
instructorRole = SanitizationHelper.sanitizeName(instructorRole);
displayedName = SanitizationHelper.sanitizeName(displayedName);
InstructorAttributes instructorToEdit = updateBasicInstructorAttributes(courseId, instructorId, instructorName, instructorEmail, instructorRole, isDisplayedToStudents, displayedName);
if (instructorRole.equals(Const.InstructorPermissionRoleNames.INSTRUCTOR_PERMISSION_ROLE_CUSTOM)) {
updateInstructorCourseLevelPrivileges(instructorToEdit);
}
updateInstructorWithSectionLevelPrivileges(courseId, instructorToEdit);
instructorToEdit.privileges.validatePrivileges();
return instructorToEdit;
}
use of teammates.common.datatransfer.attributes.InstructorAttributes in project teammates by TEAMMATES.
the class InstructorCourseInstructorEditSaveAction method updateToEnsureValidityOfInstructorsForTheCourse.
/**
* Checks if there are any other registered instructors that can modify instructors.
* If there are none, the instructor currently being edited will be granted the privilege
* of modifying instructors automatically.
*
* @param courseId Id of the course.
* @param instructorToEdit Instructor that will be edited.
* This may be modified within the method.
*/
private void updateToEnsureValidityOfInstructorsForTheCourse(String courseId, InstructorAttributes instructorToEdit) {
List<InstructorAttributes> instructors = logic.getInstructorsForCourse(courseId);
int numOfInstrCanModifyInstructor = 0;
InstructorAttributes instrWithModifyInstructorPrivilege = null;
for (InstructorAttributes instructor : instructors) {
if (instructor.isAllowedForPrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR)) {
numOfInstrCanModifyInstructor++;
instrWithModifyInstructorPrivilege = instructor;
}
}
boolean isLastRegInstructorWithPrivilege = numOfInstrCanModifyInstructor <= 1 && instrWithModifyInstructorPrivilege != null && (!instrWithModifyInstructorPrivilege.isRegistered() || instrWithModifyInstructorPrivilege.googleId.equals(instructorToEdit.googleId));
if (isLastRegInstructorWithPrivilege) {
instructorToEdit.privileges.updatePrivilege(Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR, true);
}
}
use of teammates.common.datatransfer.attributes.InstructorAttributes in project teammates by TEAMMATES.
the class InstructorCourseRemindAction method execute.
@Override
public ActionResult execute() throws EntityDoesNotExistException {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
CourseAttributes course = logic.getCourse(courseId);
if (course == null) {
throw new EntityDoesNotExistException("Course with ID " + courseId + " does not exist!");
}
String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
String instructorEmail = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
boolean isSendingToStudent = studentEmail != null;
boolean isSendingToInstructor = instructorEmail != null;
if (isSendingToStudent) {
gateKeeper.verifyAccessible(instructor, course, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
} else if (isSendingToInstructor) {
gateKeeper.verifyAccessible(instructor, course, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_INSTRUCTOR);
} else {
// this is sending registration emails to all students in the course and we will check if the instructor
// canmodifystudent for course level since for modifystudent privilege there is only course level setting for now
gateKeeper.verifyAccessible(instructor, course, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
}
/* Process sending emails and setup status to be shown to user and admin */
Map<String, JoinEmailData> emailDataMap = new TreeMap<>();
String redirectUrl = "";
if (isSendingToStudent) {
taskQueuer.scheduleCourseRegistrationInviteToStudent(courseId, studentEmail, false);
StudentAttributes studentData = logic.getStudentForEmail(courseId, studentEmail);
if (studentData == null) {
throw new EntityDoesNotExistException("Student with email " + studentEmail + " does not exist " + "in course " + courseId + "!");
}
emailDataMap.put(studentEmail, new JoinEmailData(studentData.getName(), extractStudentRegistrationKey(studentData)));
statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_REMINDER_SENT_TO + studentEmail, StatusMessageColor.SUCCESS));
redirectUrl = Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE;
} else if (isSendingToInstructor) {
taskQueuer.scheduleCourseRegistrationInviteToInstructor(loggedInUser.googleId, instructorEmail, courseId);
InstructorAttributes instructorData = logic.getInstructorForEmail(courseId, instructorEmail);
if (instructorData == null) {
throw new EntityDoesNotExistException("Instructor with email " + instructorEmail + " does not exist " + "in course " + courseId + "!");
}
emailDataMap.put(instructorEmail, new JoinEmailData(instructorData.getName(), StringHelper.encrypt(instructorData.key)));
statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_REMINDER_SENT_TO + instructorEmail, StatusMessageColor.SUCCESS));
redirectUrl = Const.ActionURIs.INSTRUCTOR_COURSE_EDIT_PAGE;
} else {
List<StudentAttributes> studentDataList = logic.getUnregisteredStudentsForCourse(courseId);
for (StudentAttributes student : studentDataList) {
taskQueuer.scheduleCourseRegistrationInviteToStudent(course.getId(), student.getEmail(), false);
emailDataMap.put(student.getEmail(), new JoinEmailData(student.getName(), extractStudentRegistrationKey(student)));
}
statusToUser.add(new StatusMessage(Const.StatusMessages.COURSE_REMINDERS_SENT, StatusMessageColor.SUCCESS));
redirectUrl = Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE;
}
statusToAdmin = generateStatusToAdmin(emailDataMap, courseId);
/* Create redirection with URL based on type of sending email */
RedirectResult response = createRedirectResult(redirectUrl);
response.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
return response;
}
use of teammates.common.datatransfer.attributes.InstructorAttributes in project teammates by TEAMMATES.
the class InstructorCourseStudentDeleteAllAction method execute.
@Override
public ActionResult execute() {
String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
logic.deleteAllStudentsInCourse(courseId);
statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENTS_DELETED, StatusMessageColor.SUCCESS));
statusToAdmin = "All the Students " + "in Course <span class=\"bold\">[" + courseId + "]</span> are deleted.";
RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE);
result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
return result;
}
Aggregations