Skip to content

Commit

Permalink
add installation brand name to subject of verify email message #3941
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jun 21, 2017
1 parent 9708f57 commit 8ee962e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

public class UserNotification implements Serializable {
public enum Type {
ASSIGNROLE, REVOKEROLE, CREATEDV, CREATEDS, CREATEACC, MAPLAYERUPDATED, MAPLAYERDELETEFAILED, SUBMITTEDDS, RETURNEDDS, PUBLISHEDDS, REQUESTFILEACCESS, GRANTFILEACCESS, REJECTFILEACCESS, FILESYSTEMIMPORT, CHECKSUMIMPORT, CHECKSUMFAIL
ASSIGNROLE, REVOKEROLE, CREATEDV, CREATEDS, CREATEACC, MAPLAYERUPDATED, MAPLAYERDELETEFAILED, SUBMITTEDDS, RETURNEDDS, PUBLISHEDDS, REQUESTFILEACCESS, GRANTFILEACCESS, REJECTFILEACCESS, FILESYSTEMIMPORT, CHECKSUMIMPORT, CHECKSUMFAIL, CONFIRMEMAIL
};

private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package edu.harvard.iq.dataverse.confirmemail;

import edu.harvard.iq.dataverse.Dataverse;
import edu.harvard.iq.dataverse.DataverseServiceBean;
import edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser;
import edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean;
import edu.harvard.iq.dataverse.MailServiceBean;
import edu.harvard.iq.dataverse.UserNotification;
import edu.harvard.iq.dataverse.authorization.providers.shib.ShibAuthenticationProvider;
import edu.harvard.iq.dataverse.util.BundleUtil;
import edu.harvard.iq.dataverse.util.MailUtil;
import edu.harvard.iq.dataverse.util.SystemConfig;
import java.sql.Timestamp;
import java.util.Arrays;
Expand Down Expand Up @@ -38,6 +42,8 @@ public class ConfirmEmailServiceBean {
@EJB
SystemConfig systemConfig;

@EJB DataverseServiceBean dataverseService;

@PersistenceContext(unitName = "VDCNet-ejbPU")
private EntityManager em;

Expand Down Expand Up @@ -102,11 +108,20 @@ private void sendLinkOnEmailChange(AuthenticatedUser aUser, String confirmationU

try {
String toAddress = aUser.getEmail();
/**
* @todo Move this to Bundle.properties.
*/
String subject = BundleUtil.getStringFromBundle("notification.email.verifyEmail.subject");
mailService.sendSystemEmail(toAddress, subject, messageBody);
try {
Dataverse rootDataverse = dataverseService.findRootDataverse();
if (rootDataverse != null) {
String rootDataverseName = rootDataverse.getName();
// FIXME: consider refactoring this into MailServiceBean.sendNotificationEmail. Then we might need
UserNotification userNotification = new UserNotification();
userNotification.setType(UserNotification.Type.CONFIRMEMAIL);
String subject = MailUtil.getSubjectTextBasedOnNotification(userNotification, rootDataverseName);
logger.fine("sending email to " + toAddress + " with this subject: " + subject);
mailService.sendSystemEmail(toAddress, subject, messageBody);
}
} catch (Exception e) {
logger.info("The root dataverse is not present. Don't send a notification to dataverseAdmin.");
}
} catch (Exception ex) {
/**
* @todo get more specific about the exception that's thrown when
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/util/MailUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public static String getSubjectTextBasedOnNotification(UserNotification userNoti
return BundleUtil.getStringFromBundle("notification.email.import.filesystem.subject", rootDvNameAsList);
case CHECKSUMIMPORT:
return BundleUtil.getStringFromBundle("notification.email.import.checksum.subject", rootDvNameAsList);
case CONFIRMEMAIL:
return BundleUtil.getStringFromBundle("notification.email.verifyEmail.subject", rootDvNameAsList);
}
return "";
}
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/util/MailUtilTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,10 @@ public void testSubjectChecksumImport() {
userNotification.setType(UserNotification.Type.CHECKSUMIMPORT);
assertEquals("LibraScholar: Your file checksum job has completed", MailUtil.getSubjectTextBasedOnNotification(userNotification, rootDataverseName));
}

@Test
public void testSubjectConfirmEmail() {
userNotification.setType(UserNotification.Type.CONFIRMEMAIL);
assertEquals("LibraScholar: Verify your email address", MailUtil.getSubjectTextBasedOnNotification(userNotification, rootDataverseName));
}
}

0 comments on commit 8ee962e

Please sign in to comment.