Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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. CONFIRMEMAIL may be the only type where we don't want an in-app notification.
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.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this warrant more than info? I'd at least put this at warn

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meh, as we discussed in person, anything higher than "fine" is shown. I think "info" is high enough.

}
} 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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I just mentioned to @sekmiller some day it might be nice to associate these bundle keys with the UserNotification object. Maybe you just call userNotification.getEmailSubject() or something. Out of scope for now but something to consider for the future.

}
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));
}
}