Skip to content

Commit

Permalink
SAK-50886 Calendar: should not import events with broken urls or NPEs (
Browse files Browse the repository at this point in the history
  • Loading branch information
csev authored Feb 15, 2025
1 parent d4aa22b commit 446d530
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9733,6 +9733,7 @@ private void addAssignmentIdToCalendar(Assignment assignment, Calendar c, Calend
CalendarEventEdit edit = c.getEditEvent(e.getId(), org.sakaiproject.calendar.api.CalendarService.EVENT_ADD_CALENDAR);

edit.setField(CalendarConstants.NEW_ASSIGNMENT_DUEDATE_CALENDAR_ASSIGNMENT_ID, assignment.getId());
edit.setField(CalendarConstants.EVENT_OWNED_BY_TOOL_ID, AssignmentConstants.TOOL_ID);
edit.setField(AssignmentConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED, assignmentService.getUsersLocalDateTimeString(assignment.getOpenDate()));

c.commitEvent(edit);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ public class CalendarConstants {

public final static String NEW_ASSIGNMENT_DUEDATE_CALENDAR_ASSIGNMENT_ID = "new_assignment_duedate_calendar_assignment_id";
public final static String NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED = "new_assignment_open_date_announced";
public final static String EVENT_OWNED_BY_TOOL_ID = "event_owned_by_tool_id";
}
14 changes: 13 additions & 1 deletion calendar/calendar-impl/impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,23 @@
<groupId>org.sakaiproject.edu-services.course-management</groupId>
<artifactId>coursemanagement-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.msgcntr</groupId>
<artifactId>messageforums-api</artifactId>
</dependency>
<dependency>
<groupId>org.sakaiproject.samigo</groupId>
<artifactId>samigo-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<dependency>
<groupId>org.sakaiproject.assignment</groupId>
<artifactId>sakai-assignment-api</artifactId>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>sakai-calendar-hbm</artifactId>
<version>${project.version}</version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
import org.sakaiproject.util.*;
import org.sakaiproject.util.cover.LinkMigrationHelper;

import org.sakaiproject.assignment.api.AssignmentServiceConstants;
import org.sakaiproject.api.app.messageforums.DiscussionForumService;
import org.sakaiproject.samigo.util.SamigoConstants;

/**
* <p>
* BaseCalendarService is an base implementation of the CalendarService. Extension classes implement object creation, access and storage.
Expand Down Expand Up @@ -1587,6 +1591,8 @@ public String merge(String siteId, Element root, String archivePath, String from
String newId = getUniqueId();
element3.setAttribute("id", newId);

if ( ! shouldMergeEvent(element3) ) continue;

// get the attachment kids
NodeList children5 = element3.getChildNodes();
final int length5 = children5.getLength();
Expand Down Expand Up @@ -1636,6 +1642,50 @@ public String merge(String siteId, Element root, String archivePath, String from
return results.toString();
}

/*
* Look at the properties of the event and determine if it should be merged or ignored
*/
private boolean shouldMergeEvent(Element el) {
NodeList nodeList = el.getElementsByTagName("property");

for (int i = 0; i < nodeList.getLength(); i++) {
Element prop = (Element) nodeList.item(i);
String name = prop.getAttribute("name");
String value = prop.getAttribute("value");
if ("BASE64".equalsIgnoreCase(prop.getAttribute("enc"))) {
value = Xml.decodeAttribute(prop, "value");
}

if ( StringUtils.contains(name, CalendarConstants.EVENT_OWNED_BY_TOOL_ID) &&
(StringUtils.contains(value, AssignmentServiceConstants.ASSIGNMENT_TOOL_ID) ||
StringUtils.contains(value, DiscussionForumService.FORUMS_TOOL_ID ) ||
StringUtils.contains(value, SamigoConstants.TOOL_ID) ) ) {
log.debug("Not importing assignment event from tool {}", value);
return false;
}

// Do not import events associated with an assignment - backwards compatibility
if ( StringUtils.contains(name, CalendarConstants.NEW_ASSIGNMENT_DUEDATE_CALENDAR_ASSIGNMENT_ID) ||
StringUtils.contains(name, CalendarConstants.NEW_ASSIGNMENT_OPEN_DATE_ANNOUNCED) ) {
log.debug("Not importing assignment event {}", value);
return false;
}

// Samigo does not mark its events, but the notification message is consitent - backwards compatibility
if ( StringUtils.equals(name, "CHEF:description") && StringUtils.contains(value, "samigo-app/servlet/Login")) {
log.debug("Not importing samigo event based on description containing Samigo launch URL");
return false;
}

// Discussion topic deadlines include calendar-url values inevitably pointing to the wrong place - backwards compatibility
if ( StringUtils.equals(name, "CHEF:calendar-url") && StringUtils.contains(value, "portal/site")) {
log.debug("Not importing discussion topic deadline event based on calendar-url {}", value);
return false;
}
}
return true;
}

public Map<String, String> transferCopyEntities(String fromContext, String toContext, List<String> resourceIds, List<String> options) {

Map<String, String> transversalMap = new HashMap<String, String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@
import org.sakaiproject.calendar.api.Calendar;
import org.sakaiproject.calendar.api.CalendarEventEdit;
import org.sakaiproject.calendar.api.CalendarService;
import org.sakaiproject.calendar.api.CalendarConstants;
import org.sakaiproject.component.app.messageforums.dao.hibernate.DBMembershipItemImpl;
import org.sakaiproject.component.app.messageforums.dao.hibernate.util.comparator.ForumBySortIndexAscAndCreatedDateDesc;
import org.sakaiproject.component.cover.ComponentManager;
Expand Down Expand Up @@ -2301,6 +2302,7 @@ private void processActionSendToCalendar(MutableEntity forumItem) {
begin.setType(getResourceBundleString("sendOpenCloseToCalendar.type"));
begin.setGroupAccess(allowedGroups, false);
begin.setRange(this.timeService.newTimeRange(openDate.getTime(), 0));
begin.setField(CalendarConstants.EVENT_OWNED_BY_TOOL_ID, FORUMS_TOOL_ID);
targetCalendar.commitEvent(begin);
} else { //if there is a Calendar event for the current forum item, but the open date is cleared, we interpret this as a removal.
targetCalendar.removeEvent(begin);
Expand All @@ -2313,6 +2315,7 @@ private void processActionSendToCalendar(MutableEntity forumItem) {
begin.setType(getResourceBundleString("sendOpenCloseToCalendar.type"));
begin.setGroupAccess(allowedGroups, false);
begin.setRange(this.timeService.newTimeRange(openDate.getTime(), 0));
begin.setField(CalendarConstants.EVENT_OWNED_BY_TOOL_ID, FORUMS_TOOL_ID);
targetCalendar.commitEvent(begin);
}
if (calendarEndId != null) {
Expand All @@ -2329,6 +2332,7 @@ private void processActionSendToCalendar(MutableEntity forumItem) {
end.setType(getResourceBundleString("sendOpenCloseToCalendar.type"));
end.setGroupAccess(allowedGroups, false);
end.setRange(this.timeService.newTimeRange(closeDate.getTime(), 0));
end.setField(CalendarConstants.EVENT_OWNED_BY_TOOL_ID, FORUMS_TOOL_ID);
targetCalendar.commitEvent(end);
} else { //if there is a Calendar record for the closing, but no close date, we interpret it as a removal.
targetCalendar.removeEvent(end);
Expand All @@ -2341,6 +2345,7 @@ private void processActionSendToCalendar(MutableEntity forumItem) {
end.setType(getResourceBundleString("sendOpenCloseToCalendar.type"));
end.setGroupAccess(allowedGroups, false);
end.setRange(this.timeService.newTimeRange(closeDate.getTime(), 0));
end.setField(CalendarConstants.EVENT_OWNED_BY_TOOL_ID, FORUMS_TOOL_ID);
targetCalendar.commitEvent(end);
}
if (begin != null) { //put the Calendar entry for Open in the Forum data.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.sakaiproject.calendar.api.CalendarEvent;
import org.sakaiproject.calendar.api.CalendarEventEdit;
import org.sakaiproject.calendar.api.CalendarService;
import org.sakaiproject.calendar.api.CalendarConstants;
import org.sakaiproject.component.cover.ServerConfigurationService;
import org.sakaiproject.entity.cover.EntityManager;
import org.sakaiproject.exception.IdUnusedException;
Expand All @@ -49,6 +50,7 @@
import org.sakaiproject.tool.assessment.integration.helper.ifc.CalendarServiceHelper;
import org.sakaiproject.tool.assessment.services.assessment.PublishedAssessmentService;
import org.sakaiproject.tool.cover.ToolManager;
import org.sakaiproject.samigo.util.SamigoConstants;

@Slf4j
public class CalendarServiceHelperImpl implements CalendarServiceHelper {
Expand Down Expand Up @@ -127,6 +129,7 @@ public String addCalendarEvent(String siteId, String title, String desc, long da
CalendarEventEdit edit = calendar.getEditEvent(event.getId(), CalendarService.EVENT_ADD_CALENDAR);

edit.setDescriptionFormatted(desc);
edit.setField(CalendarConstants.EVENT_OWNED_BY_TOOL_ID, SamigoConstants.TOOL_ID);

calendar.commitEvent(edit);
}
Expand Down

0 comments on commit 446d530

Please sign in to comment.