Skip to content

Commit

Permalink
fix: add location to ics attached to emails - EXO-73977 (#710)
Browse files Browse the repository at this point in the history
This fix adds the Location attribute to the ics file generated by the server when sending email notifications.
  • Loading branch information
ahamdi authored Oct 16, 2024
1 parent b3dfd65 commit 8dfe414
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.*;
import java.nio.charset.Charset;
import java.time.*;
import java.util.*;
Expand Down Expand Up @@ -38,6 +37,7 @@
import org.exoplatform.commons.utils.CommonsUtils;
import org.exoplatform.commons.utils.HTMLEntityEncoder;
import org.exoplatform.container.ExoContainerContext;
import org.exoplatform.portal.branding.BrandingService;
import org.exoplatform.portal.config.UserPortalConfigService;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
Expand Down Expand Up @@ -902,13 +902,13 @@ public static String getWebConferenceLink(Event event) {
}
public static final void addIcsFile(NotificationInfo notification, MessageInfo messageInfo, ZoneId timeZone) {
IdentityManager identityManager = ExoContainerContext.getService(IdentityManager.class);
BrandingService brandingService = ExoContainerContext.getService(BrandingService.class);
SpaceService spaceService = ExoContainerContext.getService(SpaceService.class);
String ownerId = notification.getValueOwnerParameter(STORED_PARAMETER_EVENT_OWNER_ID);
Identity identity = identityManager.getIdentity(ownerId);
Space space = identity!=null ? spaceService.getSpaceByPrettyName(identity.getRemoteId()) : null;
String spaceName = space == null ? null : space.getDisplayName();
String eventConference = notification.getValueOwnerParameter(TEMPLATE_VARIABLE_EVENT_CONFERENCE);
String eventCreator = notification.getValueOwnerParameter(STORED_PARAMETER_EVENT_CREATOR);
Attachment attachment = new Attachment();
/* Generate unique identifier */
UidGenerator ug = new RandomUidGenerator();
Expand All @@ -927,13 +927,32 @@ public static final void addIcsFile(NotificationInfo notification, MessageInfo m
vEvent.getProperties().add(uid);
/* Create calendar */
net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
calendar.getProperties().add(new ProdId("PRODID:-//eXo Plaform//EN"));
calendar.getProperties().add(new ProdId("PRODID:-//"+ brandingService.getSiteName() + "//" + brandingService.getCompanyName() + "//EN"));
calendar.getProperties().add(Version.VERSION_2_0);
calendar.getProperties().add(CalScale.GREGORIAN);
Organizer organizer = new Organizer(URI.create("[email protected]"));
organizer.getParameters().add(new Cn(eventCreator));
calendar.getProperties().add(organizer);

String eventModifierId = notification.getValueOwnerParameter(STORED_PARAMETER_MODIFIER_IDENTITY_ID);
String eventCreator = notification.getValueOwnerParameter(STORED_PARAMETER_EVENT_CREATOR);
Identity eventCreatorIdentity = identityManager.getIdentity(eventModifierId);
if(eventCreatorIdentity != null) {
Organizer organizer = new Organizer(URI.create(eventCreatorIdentity.getProfile().getEmail()));
organizer.getParameters().add(new Cn(eventCreatorIdentity.getProfile().getFullName()));
vEvent.getProperties().add(organizer);
}
String location = notification.getValueOwnerParameter(STORED_PARAMETER_EVENT_LOCATION);
if(StringUtils.isNotBlank(location)) {
vEvent.getProperties().add(new Location(location));
}
URI eventUrl;
String eventURIParam = notification.getValueOwnerParameter(STORED_PARAMETER_EVENT_URL);
if(StringUtils.isNotBlank(eventURIParam)) {
try {
eventUrl = new URI(eventURIParam);
vEvent.getProperties().add(new Url(eventUrl));
} catch (URISyntaxException use) {
// Nothing to do, we simply ignore the URL
}
}
HTMLEntityEncoder htmlEntityEncoder = HTMLEntityEncoder.getInstance();
Locale userLocale = Locale.of(Utils.getUserLanguage(notification.getTo()));
String htmlContent = "<html><body>" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3297,7 +3297,8 @@ public void testAddIcsFile() throws IOException {
notification.with(STORED_PARAMETER_EVENT_TITLE, "eventSummary")
.with(STORED_PARAMETER_EVENT_CREATOR, "Root Root")
.with(STORED_PARAMETER_EVENT_START_DATE, AgendaDateUtils.toRFC3339Date(start))
.with(STORED_PARAMETER_EVENT_END_DATE, AgendaDateUtils.toRFC3339Date(end));
.with(STORED_PARAMETER_EVENT_END_DATE, AgendaDateUtils.toRFC3339Date(end))
.with(STORED_PARAMETER_EVENT_LOCATION, "eXo office, Earth");

MessageInfo messageInfo = new MessageInfo();
addIcsFile(notification, messageInfo, dstTimeZone);
Expand Down

0 comments on commit 8dfe414

Please sign in to comment.