diff --git a/distro/changelog.xml b/distro/changelog.xml index 4ea58c5..49f5a24 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,5 +1,9 @@ + + Invite emails are now sent via Email Templates Library + removed ASL Session, ported to gCube Client Context diff --git a/src/main/java/org/gcube/portal/invites/InvitesManager.java b/src/main/java/org/gcube/portal/invites/InvitesManager.java index 0a56f1a..713b732 100644 --- a/src/main/java/org/gcube/portal/invites/InvitesManager.java +++ b/src/main/java/org/gcube/portal/invites/InvitesManager.java @@ -11,14 +11,16 @@ import javax.mail.internet.AddressException; import javax.servlet.http.HttpServletRequest; import org.gcube.common.portal.PortalContext; -import org.gcube.common.portal.mailing.EmailNotification; import org.gcube.portal.databook.server.DBCassandraAstyanaxImpl; import org.gcube.portal.databook.server.DatabookStore; import org.gcube.portal.databook.shared.Invite; import org.gcube.portal.databook.shared.InviteOperationResult; import org.gcube.portal.databook.shared.InviteStatus; +import org.gcube.portal.mailing.message.EmailAddress; import org.gcube.portal.mailing.message.Recipient; +import org.gcube.portal.mailing.message.RecipientType; import org.gcube.portal.mailing.service.EmailTemplateService; +import org.gcube.portal.mailing.templates.TemplateUserHasInvited; import org.gcube.portal.mailing.templates.TemplatedJoinMeInvite; import org.gcube.vomanagement.usermanagement.exception.GroupRetrievalFault; import org.gcube.vomanagement.usermanagement.exception.UserManagementSystemException; @@ -80,8 +82,8 @@ public class InvitesManager { try { String vreName = PortalContext.getConfiguration().getCurrentGroupName(request); result = store.saveInvite(invite); - emailResult = sendInviteEmail(request, vreName, portalSenderEmail, portalURL, name, lastName, email, vreDescription); - notifyInviteSent(request, username, currScope, invite, vreName); + emailResult = sendInviteEmail(request, currUser, vreName, name, email, vreDescription); + notifyInviteSent(request, currUser, currScope, invite, vreName); } catch (AddressException e) { _log.error("Email not valid " + e.getMessage()); @@ -94,16 +96,13 @@ public class InvitesManager { private Boolean sendInviteEmail( HttpServletRequest request, + GCubeUser currUser, String vreName, - String portalSenderEmail, - String portalURL, String name, - String lastName, String email, String vreDescription) { PortalContext pContext = PortalContext.getConfiguration(); - GCubeUser currUser = pContext.getCurrentUser(request); String gatewayURL = pContext.getGatewayURL(request); String gatewayName = pContext.getGatewayName(request); @@ -112,14 +111,14 @@ public class InvitesManager { String subject = "Join me on " + vreName + " VRE"; long groupId = PortalContext.getConfiguration().getCurrentGroupId(request); - final String linkToAcceptInvite = portalURL + PortalContext.getConfiguration().getSiteLandingPagePath(request)+"/explore?siteId="+groupId; - final String linkToCreateAccount = portalURL + "/?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&saveLastPath=false&_58_struts_action=%2Flogin%2Fcreate_account"; + final String linkToAcceptInvite = gatewayURL + PortalContext.getConfiguration().getSiteLandingPagePath(request)+"/explore?siteId="+groupId; + final String linkToCreateAccount = gatewayURL + "/?p_p_id=58&p_p_lifecycle=0&p_p_state=maximized&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&saveLastPath=false&_58_struts_action=%2Flogin%2Fcreate_account"; EmailTemplateService.send( subject, new TemplatedJoinMeInvite(gatewayName, gatewayURL, currUser, name, vreName, vreDescription, linkToAcceptInvite, linkToCreateAccount), request, - new Recipient(email)); + new Recipient(email), new Recipient(new EmailAddress(currUser.getEmail()), RecipientType.CC)); _log.debug("Join Me Invite email message sent successfully to " + email ); @@ -130,6 +129,31 @@ public class InvitesManager { } return true; } + /** + * + * @param request + * @param username + * @param scope + * @param invite + * @param vreName + */ + public static void notifyInviteSent(HttpServletRequest request, GCubeUser currUser, String scope, Invite invite, String vreName) { + + List adminRecipients = new ArrayList<>(); + for (String email : getAdministratorsEmails(scope)) { + adminRecipients.add(new Recipient(email)); + } + String gatewayURL = PortalContext.getConfiguration().getGatewayURL(request); + String gatewayName = PortalContext.getConfiguration().getGatewayName(request); + + String subject = new StringBuffer("invite was sent on ").append(vreName).append(" by ").append(invite.getSenderFullName()).toString(); + EmailTemplateService.send( + subject, + new TemplateUserHasInvited(currUser, invite.getInvitedEmail(), vreName, gatewayName, gatewayURL), + request, + adminRecipients.toArray(new Recipient[adminRecipients.size()])); + } + private static ArrayList getAdministratorsEmails(String scope) { LiferayUserManager userManager = new LiferayUserManager(); @@ -173,27 +197,5 @@ public class InvitesManager { return adminEmailsList; } - /** - * - * @param scope . - * @param optionalMessage . - */ - public static void notifyInviteSent(HttpServletRequest request, String username, String scope, Invite invite, String vreName) { - - ArrayList adminEmails = getAdministratorsEmails(scope); - StringBuffer body = new StringBuffer(); - body.append("

Dear manager of "+ scope +",
this email message was automatically generated by " + PortalContext.getConfiguration().getGatewayURL(request) +" to inform you that "); - body.append("

"); - body.append("

"); - body.append(""+invite.getSenderFullName() + " (" + invite.getSenderUserId() +") has invited " + invite.getInvitedEmail() + " to the following environment:"); - body.append("

"); - body.append("" + scope+""); - body.append("

"); - - String[] allMails = new String[adminEmails.size()]; - adminEmails.toArray(allMails); - EmailNotification mailToAdmin = new EmailNotification(allMails , "An invite was sent on " + vreName + " by " + invite.getSenderFullName(), body.toString(), request); - mailToAdmin.sendEmail(); - } - + }