Search in sources :

Example 1 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class AdminInstructorAccountAddAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    AdminHomePageData data = new AdminHomePageData(account, sessionToken);
    data.instructorName = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME).trim();
    data.instructorEmail = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL).trim();
    data.instructorInstitution = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION).trim();
    data.isInstructorAddingResultForAjax = true;
    data.statusForAjax = "";
    data.instructorName = data.instructorName.trim();
    data.instructorEmail = data.instructorEmail.trim();
    data.instructorInstitution = data.instructorInstitution.trim();
    try {
        logic.verifyInputForAdminHomePage(data.instructorName, data.instructorInstitution, data.instructorEmail);
    } catch (InvalidParametersException e) {
        data.statusForAjax = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
        data.isInstructorAddingResultForAjax = false;
        statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.DANGER));
        return createAjaxResult(data);
    }
    String courseId = null;
    try {
        courseId = importDemoData(data);
    } catch (Exception e) {
        String retryUrl = Const.ActionURIs.ADMIN_INSTRUCTORACCOUNT_ADD;
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_NAME, data.instructorName);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_EMAIL, data.instructorEmail);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_INSTITUTION, data.instructorInstitution);
        retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.SESSION_TOKEN, data.getSessionToken());
        StringBuilder errorMessage = new StringBuilder(100);
        String retryLink = "<a href=" + retryUrl + ">Exception in Importing Data, Retry</a>";
        errorMessage.append(retryLink);
        statusToUser.add(new StatusMessage(errorMessage.toString(), StatusMessageColor.DANGER));
        String message = "<span class=\"text-danger\">Servlet Action failure in AdminInstructorAccountAddAction" + "<br>" + e.getClass() + ": " + TeammatesException.toStringWithStackTrace(e) + "<br></span>";
        errorMessage.append("<br>").append(message);
        statusToUser.add(new StatusMessage("<br>" + message, StatusMessageColor.DANGER));
        statusToAdmin = message;
        data.isInstructorAddingResultForAjax = false;
        data.statusForAjax = errorMessage.toString();
        return createAjaxResult(data);
    }
    List<InstructorAttributes> instructorList = logic.getInstructorsForCourse(courseId);
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructorList.get(0).key)).withInstructorInstitution(data.instructorInstitution).toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorList.get(0).email, data.instructorName, joinLink);
    try {
        emailSender.sendEmail(email);
    } catch (EmailSendingException e) {
        log.severe("Instructor welcome email failed to send: " + TeammatesException.toStringWithStackTrace(e));
    }
    data.statusForAjax = "Instructor " + SanitizationHelper.sanitizeForHtml(data.instructorName) + " has been successfully created " + "<a href=" + joinLink + ">" + Const.JOIN_LINK + "</a>";
    statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.SUCCESS));
    statusToAdmin = "A New Instructor <span class=\"bold\">" + SanitizationHelper.sanitizeForHtmlTag(data.instructorName) + "</span> has been created.<br>" + "<span class=\"bold\">Id: </span>" + "ID will be assigned when the verification link was clicked and confirmed" + "<br>" + "<span class=\"bold\">Email: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorEmail) + "<span class=\"bold\">Institution: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorInstitution);
    return createAjaxResult(data);
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AdminHomePageData(teammates.ui.pagedata.AdminHomePageData) EmailSendingException(teammates.common.exception.EmailSendingException) InvalidParametersException(teammates.common.exception.InvalidParametersException) EntityDoesNotExistException(teammates.common.exception.EntityDoesNotExistException) EmailSendingException(teammates.common.exception.EmailSendingException) TeammatesException(teammates.common.exception.TeammatesException) InvalidParametersException(teammates.common.exception.InvalidParametersException) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 2 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class CourseJoinAuthenticatedAbstractAction method sendCourseRegisteredEmail.

protected void sendCourseRegisteredEmail(String name, String emailAddress, boolean isInstructor, String courseId) {
    CourseAttributes course = logic.getCourse(courseId);
    EmailWrapper email = new EmailGenerator().generateUserCourseRegisteredEmail(name, emailAddress, account.googleId, isInstructor, course);
    try {
        emailSender.sendEmail(email);
    } catch (EmailSendingException e) {
        log.severe("User course register email failed to send: " + TeammatesException.toStringWithStackTrace(e));
    }
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailSendingException(teammates.common.exception.EmailSendingException) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) EmailWrapper(teammates.common.util.EmailWrapper)

Example 3 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateFeedbackSessionEmails_testSanitization.

@Test
public void testGenerateFeedbackSessionEmails_testSanitization() throws IOException {
    FeedbackSessionAttributes session = fsLogic.getFeedbackSession("Normal feedback session name", "idOfTestingSanitizationCourse");
    CourseAttributes course = coursesLogic.getCourse(session.getCourseId());
    StudentAttributes student1 = studentsLogic.getStudentForEmail(course.getId(), "normal@sanitization.tmt");
    InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail(course.getId(), "instructor1@sanitization.tmt");
    ______TS("feedback session opening emails: sanitization required");
    List<EmailWrapper> emails = new EmailGenerator().generateFeedbackSessionOpeningEmails(session);
    assertEquals(2, emails.size());
    String subject = String.format(EmailType.FEEDBACK_OPENING.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionOpeningEmailTestingSanitzationForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionOpeningEmailTestingSanitizationForInstructor.html");
    ______TS("feedback session closed alerts: sanitization required");
    emails = new EmailGenerator().generateFeedbackSessionClosedEmails(session);
    assertEquals(2, emails.size());
    subject = String.format(EmailType.FEEDBACK_CLOSED.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmailReceivedCorrectly(emails, student1.email, subject, "/sessionClosedEmailTestingSanitizationForStudent.html");
    verifyEmailReceivedCorrectly(emails, instructor1.email, subject, "/sessionClosedEmailTestingSanitizationForInstructor.html");
    ______TS("feedback sessions summary of course email: sanitization required");
    EmailWrapper email = new EmailGenerator().generateFeedbackSessionSummaryOfCourse(session.getCourseId(), student1);
    subject = String.format(EmailType.STUDENT_EMAIL_CHANGED.getSubject(), course.getName(), course.getId());
    verifyEmail(email, student1.email, subject, "/summaryOfFeedbackSessionsOfCourseEmailTestingSanitizationForStudent.html");
    ______TS("feedback session submission email: sanitization required");
    Instant time = TimeHelper.parseInstant("2016-09-04 05:30 AM +0000");
    email = new EmailGenerator().generateFeedbackSubmissionConfirmationEmailForInstructor(session, instructor1, time);
    subject = String.format(EmailType.FEEDBACK_SUBMISSION_CONFIRMATION.getSubject(), course.getName(), session.getFeedbackSessionName());
    verifyEmail(email, instructor1.email, subject, "/sessionSubmissionConfirmationEmailTestingSanitization.html");
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) EmailGenerator(teammates.logic.api.EmailGenerator) Instant(java.time.Instant) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Example 4 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateInstructorJoinEmail_testSanitization.

@Test
public void testGenerateInstructorJoinEmail_testSanitization() throws IOException {
    ______TS("instructor new account email: sanitization required");
    InstructorAttributes instructor1 = instructorsLogic.getInstructorForEmail("idOfTestingSanitizationCourse", "instructor1@sanitization.tmt");
    String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructor1.key)).withInstructorInstitution("Test Institute").toAbsoluteString();
    EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructor1.email, instructor1.name, joinLink);
    // InstructorAttributes sanitizes name before saving
    String subject = String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), SanitizationHelper.sanitizeForHtml(instructor1.name));
    verifyEmail(email, instructor1.email, subject, "/instructorNewAccountEmailTestingSanitization.html");
    assertEquals(email.getBcc(), Config.SUPPORT_EMAIL);
    ______TS("instructor course join email: sanitization required");
    AccountAttributes inviter = dataBundle.accounts.get("instructor1OfTestingSanitizationCourse");
    CourseAttributes course = coursesLogic.getCourse("idOfTestingSanitizationCourse");
    email = new EmailGenerator().generateInstructorCourseJoinEmail(inviter, instructor1, course);
    subject = String.format(EmailType.INSTRUCTOR_COURSE_JOIN.getSubject(), course.getName(), course.getId());
    verifyEmail(email, instructor1.email, subject, "/instructorCourseJoinEmailTestingSanitization.html");
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) EmailWrapper(teammates.common.util.EmailWrapper) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) Test(org.testng.annotations.Test)

Example 5 with EmailGenerator

use of teammates.logic.api.EmailGenerator in project teammates by TEAMMATES.

the class EmailGeneratorTest method testGenerateAdminEmail.

@Test
public void testGenerateAdminEmail() {
    String recipient = "recipient@email.com";
    String content = "Generic content";
    String subject = "Generic subject";
    EmailWrapper email = new EmailGenerator().generateAdminEmail(content, subject, recipient);
    // Do not use verify email since the content is not based on any template
    assertEquals(recipient, email.getRecipient());
    assertEquals(subject, email.getSubject());
    assertEquals(Config.EMAIL_SENDERNAME, email.getSenderName());
    assertEquals(Config.EMAIL_SENDEREMAIL, email.getSenderEmail());
    assertEquals(Config.EMAIL_REPLYTO, email.getReplyTo());
    assertEquals(content, email.getContent());
}
Also used : EmailGenerator(teammates.logic.api.EmailGenerator) EmailWrapper(teammates.common.util.EmailWrapper) Test(org.testng.annotations.Test)

Aggregations

EmailWrapper (teammates.common.util.EmailWrapper)24 EmailGenerator (teammates.logic.api.EmailGenerator)24 TeammatesException (teammates.common.exception.TeammatesException)12 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)10 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)10 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)10 Test (org.testng.annotations.Test)9 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)9 ArrayList (java.util.ArrayList)3 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)3 EmailSendingException (teammates.common.exception.EmailSendingException)3 StatusMessage (teammates.common.util.StatusMessage)3 Instant (java.time.Instant)2 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)2 InvalidParametersException (teammates.common.exception.InvalidParametersException)2 AppLogLine (com.google.appengine.api.log.AppLogLine)1 AdminEmailAttributes (teammates.common.datatransfer.attributes.AdminEmailAttributes)1 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)1 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)1 FeedbackQuestionDetails (teammates.common.datatransfer.questions.FeedbackQuestionDetails)1