From 98f152e1b95db21475056684992705c372f65d74 Mon Sep 17 00:00:00 2001 From: Piumal Rathnayake Date: Thu, 5 Aug 2021 06:28:40 +0530 Subject: [PATCH 1/4] Prevent mentors from applying to themselves (#192) --- .travis.yml | 1 + .../org/sefglobal/scholarx/service/MentorService.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index e1c4bd87..62be52cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,6 +10,7 @@ before_script: - mkdir -p src/main/resources/static - cp -r scholarx-frontend/dist/. src/main/resources/static/ - sudo rm -R scholarx-frontend + - cp src/main/resources/application.yml.example src/main/resources/application.yml script: - mvn clean install deploy: diff --git a/src/main/java/org/sefglobal/scholarx/service/MentorService.java b/src/main/java/org/sefglobal/scholarx/service/MentorService.java index 690775ef..be4f33e1 100644 --- a/src/main/java/org/sefglobal/scholarx/service/MentorService.java +++ b/src/main/java/org/sefglobal/scholarx/service/MentorService.java @@ -93,6 +93,7 @@ public Mentor updateState(long id, EnrolmentState enrolmentState) * @throws ResourceNotFoundException is thrown if the applying {@link Mentor} doesn't exist * @throws ResourceNotFoundException is thrown if the applying user's {@link Profile} doesn't exist * @throws BadRequestException is thrown if the applying {@link Mentor} is not in applicable state + * @throws BadRequestException is thrown if the applying {@link Mentor} is the same user */ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee) throws ResourceNotFoundException, BadRequestException { @@ -118,6 +119,13 @@ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee) throw new ResourceNotFoundException(msg); } + if (optionalMentor.get().getProfile().getId() == optionalProfile.get().getId()) { + String msg = "Error, Unable to apply as a mentee. " + + "Mentor and mentee can't be the same person."; + log.error(msg); + throw new BadRequestException(msg); + } + mentee.setProfile(optionalProfile.get()); mentee.setProgram(optionalMentor.get().getProgram()); mentee.setMentor(optionalMentor.get()); From b277f6f497aabe81cbbfdd8bf403610b3dd377b2 Mon Sep 17 00:00:00 2001 From: Piumal Rathnayake Date: Fri, 6 Aug 2021 13:29:47 +0530 Subject: [PATCH 2/4] Prevent mentors from applying as mentees for the same program (#195) --- .../org/sefglobal/scholarx/service/MentorService.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sefglobal/scholarx/service/MentorService.java b/src/main/java/org/sefglobal/scholarx/service/MentorService.java index be4f33e1..1f7a56f3 100644 --- a/src/main/java/org/sefglobal/scholarx/service/MentorService.java +++ b/src/main/java/org/sefglobal/scholarx/service/MentorService.java @@ -93,7 +93,7 @@ public Mentor updateState(long id, EnrolmentState enrolmentState) * @throws ResourceNotFoundException is thrown if the applying {@link Mentor} doesn't exist * @throws ResourceNotFoundException is thrown if the applying user's {@link Profile} doesn't exist * @throws BadRequestException is thrown if the applying {@link Mentor} is not in applicable state - * @throws BadRequestException is thrown if the applying {@link Mentor} is the same user + * @throws BadRequestException is thrown if the applying user is already a {@link Mentor} */ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee) throws ResourceNotFoundException, BadRequestException { @@ -119,9 +119,12 @@ public Mentee applyAsMentee(long mentorId, long profileId, Mentee mentee) throw new ResourceNotFoundException(msg); } - if (optionalMentor.get().getProfile().getId() == optionalProfile.get().getId()) { + Optional alreadyRegisteredMentor = mentorRepository + .findByProfileIdAndProgramId(profileId, optionalMentor.get().getProgram().getId()); + if (alreadyRegisteredMentor.isPresent() && + alreadyRegisteredMentor.get().getState().equals(EnrolmentState.APPROVED)) { String msg = "Error, Unable to apply as a mentee. " + - "Mentor and mentee can't be the same person."; + "Profile with id: " + profileId + " is already registered as a mentor."; log.error(msg); throw new BadRequestException(msg); } From d86795eaf77da60c7b956a9aea0e75464cb4f1e4 Mon Sep 17 00:00:00 2001 From: Heshan Andrews <45477334+Gravewalker666@users.noreply.github.com> Date: Sat, 7 Aug 2021 22:01:34 +0530 Subject: [PATCH 3/4] Fix email notification bug (#196) Prevented from quering for the state in seprate thread which is started in the update state function to send the emails separately --- .../org/sefglobal/scholarx/service/ProgramService.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/sefglobal/scholarx/service/ProgramService.java b/src/main/java/org/sefglobal/scholarx/service/ProgramService.java index 69c24f7b..57ec015e 100644 --- a/src/main/java/org/sefglobal/scholarx/service/ProgramService.java +++ b/src/main/java/org/sefglobal/scholarx/service/ProgramService.java @@ -123,9 +123,10 @@ public Program updateProgram(long id, Program program) throws ResourceNotFoundEx public Program updateState(long id) throws ResourceNotFoundException { Optional program = programRepository.findById(id); + final ProgramState nextState = program.get().getState().next(); Thread thread = new Thread(() -> { try { - switch (program.get().getState().next()) { + switch (nextState) { case MENTEE_APPLICATION: programUtil.sendMenteeApplicationEmails(id, program); break; @@ -139,7 +140,8 @@ public Program updateState(long id) throws ResourceNotFoundException { programUtil.sendMentorConfirmationEmails(id, program); break; } - } catch (Exception ignored) { + } catch (Exception exception) { + log.error("Email service error: ", exception); } }); thread.start(); @@ -151,7 +153,6 @@ public Program updateState(long id) throws ResourceNotFoundException { throw new ResourceNotFoundException(msg); } - ProgramState nextState = program.get().getState().next(); if (ProgramState.ONGOING.equals(nextState)) { List approvedMenteeList = menteeRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED); for (Mentee mentee : approvedMenteeList) { From f21bdf906bd7dd7f38657b6f5d9ab57d2e9f5ec7 Mon Sep 17 00:00:00 2001 From: Gayanga Kuruppu <50499511+cmdrGuyson@users.noreply.github.com> Date: Tue, 10 Aug 2021 12:50:10 +0530 Subject: [PATCH 4/4] Update notification email content (#199) --- .../scholarx/service/EmailService.java | 3 +- .../sefglobal/scholarx/util/ProgramUtil.java | 65 ++++++- src/main/resources/templates/scholarx.html | 169 +++++++++++++++--- 3 files changed, 202 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/sefglobal/scholarx/service/EmailService.java b/src/main/java/org/sefglobal/scholarx/service/EmailService.java index a2ee98c6..eb83e295 100644 --- a/src/main/java/org/sefglobal/scholarx/service/EmailService.java +++ b/src/main/java/org/sefglobal/scholarx/service/EmailService.java @@ -17,7 +17,7 @@ public EmailService(EmailUtil emailUtil) { this.emailUtil = emailUtil; } - public Email sendEmail(String emailAddress, String subject, String message) throws IOException, MessagingException { + public Email sendEmail(String emailAddress, String subject, String message, boolean showButton) throws IOException, MessagingException { Email email = new Email(); email.setEmail(emailAddress); email.setSubject(subject); @@ -27,6 +27,7 @@ public Email sendEmail(String emailAddress, String subject, String message) thro model.put("emailAddress", emailAddress); model.put("subject", subject); model.put("message", message); + model.put("showButton", showButton); email.setProps(model); emailUtil.sendSimpleMessage(email); diff --git a/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java b/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java index 15e6e6ed..00d5f8f9 100644 --- a/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java +++ b/src/main/java/org/sefglobal/scholarx/util/ProgramUtil.java @@ -1,5 +1,6 @@ package org.sefglobal.scholarx.util; +import org.apache.commons.lang.StringUtils; import org.sefglobal.scholarx.model.Mentee; import org.sefglobal.scholarx.model.Mentor; import org.sefglobal.scholarx.model.Program; @@ -30,26 +31,75 @@ public void sendMenteeApplicationEmails(long id, Optional program) thro String message; for (Mentor mentor : mentors) { - message = "You have been " + mentor.getState().name().toLowerCase(); - emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message); + + if (mentor.getState().name().equals("APPROVED")) { + + message = "Dear " + mentor.getProfile().getFirstName() + ",

" + + "Congratulations!
You have been selected by the " + + "ScholarX committee to be a mentor of the " + program.get().getTitle() + + " program. We will soon open up the program for students to " + + "apply and keep you posted on the progress via email. Until " + + "then, read more about student experience " + + "here and reach out to us via " + + "sustainableedufoundation@gmail.com " + + "for any clarifications."; + + emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false); + + } else if (mentor.getState().name().equals("REJECTED")) { + + message = "Dear " + mentor.getProfile().getFirstName() + ",

" + + "Thank you very much for taking your time to apply for the " + program.get().getTitle() + " program. " + + "However, due to the competitive nature of the mentor applications, your application " + + "did not make it to the final list of mentors for the program. We encourage you to try " + + "again next year and follow us on our social media channels for future programs. " + + "If you have any clarifications, please reach out to us via " + + "sustainableedufoundation@gmail.com"; + + emailService.sendEmail(mentor.getProfile().getEmail(), StringUtils.capitalize(mentor.getState().name()), message, false); + + } } } public void sendMenteeSelectionEmails(long id, Optional program) throws IOException, MessagingException { List approvedMentors = mentorRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED); + List mentees = menteeRepository.findAllByProgramId(id); - String message = "You can approve or reject your mentees by visiting the dashboard"; + // Notify mentors for (Mentor mentor : approvedMentors) { - emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message); + + String message = "Dear " + mentor.getProfile().getFirstName() + ",

" + + "You have student applications waiting to be reviewed. You can approve or reject your mentees " + + "by visiting the ScholarX dashboard."; + + emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true); + } + + // Notify mentees + for (Mentee mentee : mentees) { + String message = "Dear " + mentee.getProfile().getFirstName() + ",

" + + "Thank you very much for applying to the " + program.get().getTitle() + " program. Your application has been received. " + + "Mentors will soon review your applications and we will keep you posted on the progress via email. " + + "Until then, read more about student experience here and reach out to us via " + + "sustainableedufoundation@gmail.com " + + "for any clarifications."; + + emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, false); } } public void sendOnGoingEmails(long id, Optional program) throws IOException, MessagingException { List approvedMentors = mentorRepository.findAllByProgramIdAndState(id, EnrolmentState.APPROVED); - String message = "You can check your mentees by visiting the dashboard"; for (Mentor mentor : approvedMentors) { - emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message); + + String message = "Dear " + mentor.getProfile().getFirstName() + ",

" + + "Congratulations!
Students have accepted you as their mentor. " + + "You can check your mentees and their contact details by visiting the ScholarX dashboard. " + + "Please make the first contact with them as we have instructed them to wait for your email."; + + emailService.sendEmail(mentor.getProfile().getEmail(), program.get().getTitle(), message, true); } } @@ -57,8 +107,9 @@ public void sendMentorConfirmationEmails(long id, Optional program) thr List mentees = menteeRepository.findAllByProgramId(id); String message = "You can check your mentor by visiting the dashboard"; + for (Mentee mentee : mentees) { - emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message); + emailService.sendEmail(mentee.getProfile().getEmail(), program.get().getTitle(), message, true); } } } diff --git a/src/main/resources/templates/scholarx.html b/src/main/resources/templates/scholarx.html index 816e7777..d0cf81b7 100644 --- a/src/main/resources/templates/scholarx.html +++ b/src/main/resources/templates/scholarx.html @@ -1,68 +1,181 @@ - + + ScholarX email template - + - -
- + + +
+
-
- +
+ - - -
- + +
+ +
+

-

- -
- -
-

-

- View Dashboard -

+

+

+ Best regards,
+ Dharana Jayawardane,
+ Program Manager,
+ ScholarX,
+ Sustainable Education Foundation +

+

+ + View Dashboard + +

-

- f - t +

+

+ + facebook-icon + + + facebook-icon + + + facebook-icon + + + facebook-icon + +

+

+ © Sustainable Education Foundation - SEF 2021

-

© Sustainable Education Foundation - SEF 2021

@@ -71,4 +184,6 @@
+ +