Skip to content

Commit

Permalink
SAK-44134 resolve issue with locked calendar event caused by bad Date…
Browse files Browse the repository at this point in the history
…Manager edit (sakaiproject#9067)
  • Loading branch information
ottenhoff authored Mar 3, 2021
1 parent ceabf85 commit afbe731
Showing 1 changed file with 20 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -931,6 +931,8 @@ public DateManagerValidation validateCalendarEvents(String siteId, JSONArray cal
List<Object> updates = new ArrayList<>();
String toolTitle = toolManager.getTool(DateManagerConstants.COMMON_ID_CALENDAR).getTitle();
Calendar c = getCalendar();
CalendarEventEdit calendarEvent = null;

if (c != null) {
boolean canUpdate = calendarService.allowEditCalendar(c.getReference());
if (!canUpdate) {
Expand All @@ -952,12 +954,13 @@ public DateManagerValidation validateCalendarEvents(String siteId, JSONArray cal
Instant dueDate = userTimeService.parseISODateInUserTimezone((String)jsonEvent.get("due_date")).toInstant();
boolean errored = false;
if (openDate == null) {
errors.add(new DateManagerError("open_date", rb.getString("error.open.date.not.found"), "calendarEvents", toolTitle, idx));
errored = true;
errored = errors.add(new DateManagerError("open_date", rb.getString("error.open.date.not.found"), "calendarEvents", toolTitle, idx));
}
if (dueDate == null) {
errors.add(new DateManagerError("due_date", rb.getString("error.due.date.not.found"), "calendarEvents", toolTitle, idx));
errored = true;
else if (dueDate == null) {
errored = errors.add(new DateManagerError("due_date", rb.getString("error.due.date.not.found"), "calendarEvents", toolTitle, idx));
}
else if (dueDate.isBefore(openDate)) {
errored = errors.add(new DateManagerError("open_date", rb.getString("error.open.date.before.due.date"), "calendarEvents", toolTitle, idx));
}
if (errored) {
continue;
Expand All @@ -967,22 +970,24 @@ public DateManagerValidation validateCalendarEvents(String siteId, JSONArray cal
if (!canUpdate) {
errors.add(new DateManagerError("calendar", rb.getString("error.event.permission"), "calendarEvents", toolTitle, idx));
}
CalendarEventEdit calendarEvent = c.getEditEvent(eventId, CalendarService.EVENT_MODIFY_CALENDAR);
if (calendarEvent == null) {
errors.add(new DateManagerError("calendar", rb.getFormattedMessage("error.item.not.found", new Object[]{rb.getString("tool.calendar.item.name")}), "calendarEvents", toolTitle, idx));
continue;
}
else {
calendarEvent = c.getEditEvent(eventId, CalendarService.EVENT_MODIFY_CALENDAR);
if (calendarEvent == null) {
errors.add(new DateManagerError("calendar", rb.getFormattedMessage("error.item.not.found", new Object[]{rb.getString("tool.calendar.item.name")}), "calendarEvents", toolTitle, idx));
continue;
}

DateManagerUpdate update = new DateManagerUpdate(calendarEvent, openDate, dueDate, null);
if (!update.openDate.isBefore(update.dueDate)) {
errors.add(new DateManagerError("open_date", rb.getString("error.open.date.before.due.date"), "calendarEvents", toolTitle, idx));
continue;
updates.add(new DateManagerUpdate(calendarEvent, openDate, dueDate, null));
}
updates.add(update);

} catch (Exception ex) {
errors.add(new DateManagerError("open_date", rb.getString("error.uncaught"), "calendarEvents", toolTitle, idx));
log.error("Cannot edit event {}", eventId);

// Clear out the lock
if (c != null && calendarEvent != null) {
c.cancelEvent(calendarEvent);
}
}
}

Expand Down

0 comments on commit afbe731

Please sign in to comment.