Search in sources :

Example 86 with InstructorAttributes

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;
}
Also used : InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 87 with InstructorAttributes

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;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 88 with InstructorAttributes

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);
    }
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 89 with InstructorAttributes

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;
}
Also used : List(java.util.List) TreeMap(java.util.TreeMap) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 90 with InstructorAttributes

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;
}
Also used : InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)325 Test (org.testng.annotations.Test)127 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)84 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)77 ArrayList (java.util.ArrayList)58 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)47 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)46 RedirectResult (teammates.ui.controller.RedirectResult)46 StatusMessage (teammates.common.util.StatusMessage)34 ShowPageResult (teammates.ui.controller.ShowPageResult)31 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)30 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)29 HashMap (java.util.HashMap)25 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)24 InvalidParametersException (teammates.common.exception.InvalidParametersException)24 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)20 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)18 EmailWrapper (teammates.common.util.EmailWrapper)15 InstructorPrivileges (teammates.common.datatransfer.InstructorPrivileges)14 DataBundle (teammates.common.datatransfer.DataBundle)13