Search in sources :

Example 46 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method generateFeedbackSessionEmailBaseForStudents.

private EmailWrapper generateFeedbackSessionEmailBaseForStudents(CourseAttributes course, FeedbackSessionAttributes session, StudentAttributes student, String template, String subject, String feedbackAction, String additionalContactInformation) {
    String submitUrl = Config.getAppUrl(Const.ActionURIs.STUDENT_FEEDBACK_SUBMISSION_EDIT_PAGE).withCourseId(course.getId()).withSessionName(session.getFeedbackSessionName()).withRegistrationKey(StringHelper.encrypt(student.key)).withStudentEmail(student.email).toAbsoluteString();
    String reportUrl = Config.getAppUrl(Const.ActionURIs.STUDENT_FEEDBACK_RESULTS_PAGE).withCourseId(course.getId()).withSessionName(session.getFeedbackSessionName()).withRegistrationKey(StringHelper.encrypt(student.key)).withStudentEmail(student.email).toAbsoluteString();
    String emailBody = Templates.populateTemplate(template, "${userName}", SanitizationHelper.sanitizeForHtml(student.name), "${courseName}", SanitizationHelper.sanitizeForHtml(course.getName()), "${courseId}", SanitizationHelper.sanitizeForHtml(course.getId()), "${feedbackSessionName}", SanitizationHelper.sanitizeForHtml(session.getFeedbackSessionName()), "${deadline}", SanitizationHelper.sanitizeForHtml(session.getEndTimeString()), "${instructorFragment}", "", "${sessionInstructions}", session.getInstructionsString(), "${submitUrl}", submitUrl, "${reportUrl}", reportUrl, "${feedbackAction}", feedbackAction, "${additionalContactInformation}", additionalContactInformation);
    EmailWrapper email = getEmptyEmailAddressedToEmail(student.email);
    email.setSubject(String.format(subject, course.getName(), session.getFeedbackSessionName()));
    email.setContent(emailBody);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 47 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method generateNewInstructorAccountJoinEmail.

/**
 * Generates the new instructor account join email for the given {@code instructor}.
 */
public EmailWrapper generateNewInstructorAccountJoinEmail(String instructorEmail, String instructorName, String joinUrl) {
    String emailBody = Templates.populateTemplate(EmailTemplates.NEW_INSTRUCTOR_ACCOUNT_WELCOME, "${userName}", SanitizationHelper.sanitizeForHtml(instructorName), "${joinUrl}", joinUrl);
    EmailWrapper email = getEmptyEmailAddressedToEmail(instructorEmail);
    email.setBcc(Config.SUPPORT_EMAIL);
    email.setSubject(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), instructorName));
    email.setContent(emailBody);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 48 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class EmailGenerator method getEmptyEmailAddressedToEmail.

private EmailWrapper getEmptyEmailAddressedToEmail(String recipient) {
    EmailWrapper email = new EmailWrapper();
    email.setRecipient(recipient);
    email.setSenderEmail(Config.EMAIL_SENDEREMAIL);
    email.setSenderName(Config.EMAIL_SENDERNAME);
    email.setReplyTo(Config.EMAIL_REPLYTO);
    return email;
}
Also used : EmailWrapper(teammates.common.util.EmailWrapper)

Example 49 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class InstructorCourseStudentDetailsEditSaveAction method execute.

@Override
public ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENT_EMAIL, studentEmail);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId), Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_STUDENT);
    StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
    if (student == null) {
        return redirectWithError(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_EDIT, "Student <span class=\"bold\">" + studentEmail + "</span> in " + "Course <span class=\"bold\">[" + courseId + "]</span> not found.", courseId);
    }
    student.name = getRequestParamValue(Const.ParamsNames.STUDENT_NAME);
    student.email = getRequestParamValue(Const.ParamsNames.NEW_STUDENT_EMAIL);
    student.team = getRequestParamValue(Const.ParamsNames.TEAM_NAME);
    student.section = getRequestParamValue(Const.ParamsNames.SECTION_NAME);
    student.comments = getRequestParamValue(Const.ParamsNames.COMMENTS);
    boolean hasSection = logic.hasIndicatedSections(courseId);
    student.name = SanitizationHelper.sanitizeName(student.name);
    student.email = SanitizationHelper.sanitizeEmail(student.email);
    student.team = SanitizationHelper.sanitizeName(student.team);
    student.section = SanitizationHelper.sanitizeName(student.section);
    student.comments = SanitizationHelper.sanitizeTextField(student.comments);
    try {
        StudentAttributes originalStudentAttribute = logic.getStudentForEmail(courseId, studentEmail);
        student.updateWithExistingRecord(originalStudentAttribute);
        boolean isSectionChanged = student.isSectionChanged(originalStudentAttribute);
        boolean isTeamChanged = student.isTeamChanged(originalStudentAttribute);
        boolean isEmailChanged = student.isEmailChanged(originalStudentAttribute);
        if (isSectionChanged) {
            logic.validateSectionsAndTeams(Arrays.asList(student), courseId);
        } else if (isTeamChanged) {
            logic.validateTeams(Arrays.asList(student), courseId);
        }
        logic.updateStudent(studentEmail, student);
        boolean isSessionSummarySendEmail = getRequestParamAsBoolean(Const.ParamsNames.SESSION_SUMMARY_EMAIL_SEND_CHECK);
        if (isEmailChanged) {
            logic.resetStudentGoogleId(student.email, courseId);
            if (isSessionSummarySendEmail) {
                try {
                    EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(courseId, student);
                    emailSender.sendEmail(email);
                } catch (Exception e) {
                    log.severe("Error while sending session summary email" + TeammatesException.toStringWithStackTrace(e));
                }
            }
        }
        statusToUser.add(new StatusMessage(isSessionSummarySendEmail && isEmailChanged ? Const.StatusMessages.STUDENT_EDITED_AND_EMAIL_SENT : Const.StatusMessages.STUDENT_EDITED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Student <span class=\"bold\">" + studentEmail + "'s</span> details in " + "Course <span class=\"bold\">[" + courseId + "]</span> edited.<br>" + "New Email: " + student.email + "<br>New Team: " + student.team + "<br>" + "Comments: " + student.comments;
        RedirectResult result = createRedirectResult(Const.ActionURIs.INSTRUCTOR_COURSE_DETAILS_PAGE);
        result.addResponseParam(Const.ParamsNames.COURSE_ID, courseId);
        return result;
    } catch (InvalidParametersException | EnrollException e) {
        setStatusForException(e);
        String newEmail = student.email;
        student.email = studentEmail;
        boolean isOpenOrPublishedEmailSentForTheCourse = logic.isOpenOrPublishedEmailSentForTheCourse(courseId);
        InstructorCourseStudentDetailsEditPageData data = new InstructorCourseStudentDetailsEditPageData(account, sessionToken, student, newEmail, hasSection, isOpenOrPublishedEmailSentForTheCourse);
        return createShowPageResult(Const.ViewURIs.INSTRUCTOR_COURSE_STUDENT_EDIT, data);
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EnrollException(teammates.common.exception.EnrollException) InstructorCourseStudentDetailsEditPageData(teammates.ui.pagedata.InstructorCourseStudentDetailsEditPageData) InvalidParametersException(teammates.common.exception.InvalidParametersException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) EnrollException(teammates.common.exception.EnrollException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) TeammatesException(teammates.common.exception.TeammatesException) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) StatusMessage(teammates.common.util.StatusMessage)

Example 50 with EmailWrapper

use of teammates.common.util.EmailWrapper in project teammates by TEAMMATES.

the class FeedbackSubmissionEditSaveAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    setAdditionalParameters();
    verifyAccessibleForSpecificUser();
    String userEmailForCourse = getUserEmailForCourse();
    data = new FeedbackSubmissionEditPageData(account, student, sessionToken);
    data.bundle = getDataBundle(userEmailForCourse);
    Assumption.assertNotNull("Feedback session " + feedbackSessionName + " does not exist in " + courseId + ".", data.bundle);
    checkAdditionalConstraints();
    setStatusToAdmin();
    if (!isSessionOpenForSpecificUser(data.bundle.feedbackSession)) {
        isError = true;
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_SUBMISSIONS_NOT_OPEN, StatusMessageColor.WARNING));
        return createSpecificRedirectResult();
    }
    String userTeamForCourse = getUserTeamForCourse();
    String userSectionForCourse = getUserSectionForCourse();
    int numOfQuestionsToGet = data.bundle.questionResponseBundle.size();
    for (int questionIndx = 1; questionIndx <= numOfQuestionsToGet; questionIndx++) {
        String totalResponsesForQuestion = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_RESPONSETOTAL + "-" + questionIndx);
        if (totalResponsesForQuestion == null) {
            // question has been skipped (not displayed).
            continue;
        }
        List<FeedbackResponseAttributes> responsesForQuestion = new ArrayList<>();
        String questionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx);
        FeedbackQuestionAttributes questionAttributes = data.bundle.getQuestionAttributes(questionId);
        if (questionAttributes == null) {
            statusToUser.add(new StatusMessage("The feedback session or questions may have changed " + "while you were submitting. Please check your responses " + "to make sure they are saved correctly.", StatusMessageColor.WARNING));
            isError = true;
            log.warning("Question not found. (deleted or invalid id passed?) id: " + questionId + " index: " + questionIndx);
            continue;
        }
        FeedbackQuestionDetails questionDetails = questionAttributes.getQuestionDetails();
        int numOfResponsesToGet = Integer.parseInt(totalResponsesForQuestion);
        Set<String> emailSet = data.bundle.getRecipientEmails(questionAttributes.getId());
        emailSet.add("");
        emailSet = SanitizationHelper.desanitizeFromHtml(emailSet);
        ArrayList<String> responsesRecipients = new ArrayList<>();
        List<String> errors = new ArrayList<>();
        for (int responseIndx = 0; responseIndx < numOfResponsesToGet; responseIndx++) {
            FeedbackResponseAttributes response = extractFeedbackResponseData(requestParameters, questionIndx, responseIndx, questionAttributes);
            if (response.feedbackQuestionType != questionAttributes.questionType) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_WRONG_QUESTION_TYPE, questionIndx));
            }
            boolean isExistingResponse = response.getId() != null;
            // came from the original set of existing responses loaded on the submission page
            if (isExistingResponse && !isExistingResponseValid(response)) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_INVALID_ID, questionIndx));
                continue;
            }
            responsesRecipients.add(response.recipient);
            // if the answer is not empty but the recipient is empty
            if (response.recipient.isEmpty() && !response.responseMetaData.getValue().isEmpty()) {
                errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSES_MISSING_RECIPIENT, questionIndx));
            }
            if (response.responseMetaData.getValue().isEmpty()) {
                // deletes the response since answer is empty
                addToPendingResponses(response);
            } else {
                response.giver = questionAttributes.giverType.isTeam() ? userTeamForCourse : userEmailForCourse;
                response.giverSection = userSectionForCourse;
                responsesForQuestion.add(response);
            }
        }
        List<String> questionSpecificErrors = questionDetails.validateResponseAttributes(responsesForQuestion, data.bundle.recipientList.get(questionId).size());
        errors.addAll(questionSpecificErrors);
        if (!emailSet.containsAll(responsesRecipients)) {
            errors.add(String.format(Const.StatusMessages.FEEDBACK_RESPONSE_INVALID_RECIPIENT, questionIndx));
        }
        if (errors.isEmpty()) {
            for (FeedbackResponseAttributes response : responsesForQuestion) {
                addToPendingResponses(response);
            }
        } else {
            List<StatusMessage> errorMessages = new ArrayList<>();
            for (String error : errors) {
                errorMessages.add(new StatusMessage(error, StatusMessageColor.DANGER));
            }
            statusToUser.addAll(errorMessages);
            isError = true;
        }
    }
    saveNewReponses(responsesToSave);
    deleteResponses(responsesToDelete);
    updateResponses(responsesToUpdate);
    if (!isError) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.FEEDBACK_RESPONSES_SAVED, StatusMessageColor.SUCCESS));
    }
    if (isUserRespondentOfSession()) {
        appendRespondent();
    } else {
        removeRespondent();
    }
    boolean isSubmissionEmailRequested = "on".equals(getRequestParamValue(Const.ParamsNames.SEND_SUBMISSION_EMAIL));
    if (!isError && isSendSubmissionEmail && isSubmissionEmailRequested) {
        FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
        Assumption.assertNotNull(session);
        String user = account == null ? null : account.googleId;
        String unregisteredStudentEmail = student == null ? null : student.email;
        String unregisteredStudentRegisterationKey = student == null ? null : student.key;
        StudentAttributes student = null;
        InstructorAttributes instructor = null;
        if (user != null) {
            student = logic.getStudentForGoogleId(courseId, user);
            instructor = logic.getInstructorForGoogleId(courseId, user);
        }
        if (student == null && unregisteredStudentEmail != null) {
            student = StudentAttributes.builder("", unregisteredStudentEmail, unregisteredStudentEmail).withKey(unregisteredStudentRegisterationKey).build();
        }
        Assumption.assertFalse(student == null && instructor == null);
        try {
            EmailWrapper email = instructor == null ? new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForStudent(session, student, Instant.now()) : new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor, Instant.now());
            emailSender.sendEmail(email);
        } catch (EmailSendingException e) {
            log.severe("Submission confirmation email failed to send: " + TeammatesException.toStringWithStackTrace(e));
        }
    }
    // TODO: Refactor to AjaxResult so status messages do not have to be passed by session
    return createSpecificRedirectResult();
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) FeedbackQuestionDetails(teammates.common.datatransfer.questions.FeedbackQuestionDetails) ArrayList(java.util.ArrayList) FeedbackSubmissionEditPageData(teammates.ui.pagedata.FeedbackSubmissionEditPageData) EmailSendingException(teammates.common.exception.EmailSendingException) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)

Aggregations

EmailWrapper (teammates.common.util.EmailWrapper)55 EmailGenerator (teammates.logic.api.EmailGenerator)24 Test (org.testng.annotations.Test)20 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)15 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)15 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)13 TeammatesException (teammates.common.exception.TeammatesException)13 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)12 ArrayList (java.util.ArrayList)6 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)4 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)3 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)3 EmailSendingException (teammates.common.exception.EmailSendingException)3 NullPostParameterException (teammates.common.exception.NullPostParameterException)3 StatusMessage (teammates.common.util.StatusMessage)3 RedirectResult (teammates.ui.controller.RedirectResult)3 Instant (java.time.Instant)2 DataBundle (teammates.common.datatransfer.DataBundle)2 FeedbackNumericalScaleQuestionDetails (teammates.common.datatransfer.questions.FeedbackNumericalScaleQuestionDetails)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2