<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[12241] CalendarServer/trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/12241">12241</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-01-06 13:40:02 -0800 (Mon, 06 Jan 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Allow event splitting at arbitrary recurrence-ids in the future. Add a calverify command to support a manual
split of a specific event.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkcalendarservertoolscalverifypy">CalendarServer/trunk/calendarserver/tools/calverify.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertoolstesttest_calverifypy">CalendarServer/trunk/calendarserver/tools/test/test_calverify.py</a></li>
<li><a href="#CalendarServertrunktwistedcaldavicalpy">CalendarServer/trunk/twistedcaldav/ical.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingicalsplitterpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_icalsplitterpy">CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkcalendarservertoolscalverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/calverify.py (12240 => 12241)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/calverify.py        2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py        2014-01-06 21:40:02 UTC (rev 12241)
</span><span class="lines">@@ -72,6 +72,9 @@
</span><span class="cx"> from twistedcaldav.util import normalizationLookup
</span><span class="cx">
</span><span class="cx"> from txdav.caldav.icalendarstore import ComponentUpdateState
</span><ins>+from txdav.caldav.datastore.scheduling.icalsplitter import iCalSplitter
+from txdav.caldav.datastore.scheduling.implicit import ImplicitScheduler
+from txdav.caldav.datastore.sql import CalendarStoreFeatures
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
</span><span class="cx"> from txdav.common.icommondatastore import InternalDataStoreError
</span><span class="cx">
</span><span class="lines">@@ -206,7 +209,7 @@
</span><span class="cx"> if not hasattr(Component, "maxAlarmCounts"):
</span><span class="cx"> Component.hasDuplicateAlarms = new_hasDuplicateAlarms
</span><span class="cx">
</span><del>-VERSION = "10"
</del><ins>+VERSION = "11"
</ins><span class="cx">
</span><span class="cx"> def printusage(e=None):
</span><span class="cx"> if e:
</span><span class="lines">@@ -240,6 +243,7 @@
</span><span class="cx"> with either --ical or --mismatch.
</span><span class="cx"> --double : detect double-bookings.
</span><span class="cx"> --dark-purge : purge room/resource events with invalid organizer
</span><ins>+--split : split recurring event
</ins><span class="cx">
</span><span class="cx"> --nuke PATH|RID : remove specific calendar resources - can
</span><span class="cx"> only be used by itself. PATH is the full
</span><span class="lines">@@ -275,6 +279,10 @@
</span><span class="cx"> --summary : report only which GUIDs have double-bookings - no details.
</span><span class="cx"> --days : number of days ahead to scan [DEFAULT: 365]
</span><span class="cx">
</span><ins>+Options for --double:
+If none of (--no-organizer, --invalid-organizer, --disabled-organizer) is present, it
+will default to (--invalid-organizer, --disabled-organizer).
+
</ins><span class="cx"> Options for --dark-purge:
</span><span class="cx">
</span><span class="cx"> --uuid : only scan specified calendar homes. Can be a partial GUID
</span><span class="lines">@@ -285,9 +293,12 @@
</span><span class="cx"> --invalid-organizer : only detect events with an organizer not in the directory
</span><span class="cx"> --disabled-organizer : only detect events with an organizer disabled for calendaring
</span><span class="cx">
</span><del>-If none of (--no-organizer, --invalid-organizer, --disabled-organizer) is present, it
-will default to (--invalid-organizer, --disabled-organizer).
</del><ins>+Options for --split:
</ins><span class="cx">
</span><ins>+--path : URI path to resource to split.
+--rid : UTC date-time where split occurs (YYYYMMDDTHHMMSSZ).
+--summary : only print a list of recurrences in the resource - no splitting.
+
</ins><span class="cx"> CHANGES
</span><span class="cx"> v8: Detects ORGANIZER or ATTENDEE properties with mailto: calendar user
</span><span class="cx"> addresses for users that have valid directory records. Fix is to
</span><span class="lines">@@ -295,6 +306,10 @@
</span><span class="cx">
</span><span class="cx"> v9: Detects double-bookings.
</span><span class="cx">
</span><ins>+v10: Purges data for invalid users.
+
+v11: Allows manual splitting of recurring events.
+
</ins><span class="cx"> """ % (VERSION,)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -319,10 +334,11 @@
</span><span class="cx"> ['missing', 'm', "Show 'orphaned' homes."],
</span><span class="cx"> ['double', 'd', "Detect double-bookings."],
</span><span class="cx"> ['dark-purge', 'p', "Purge room/resource events with invalid organizer."],
</span><ins>+ ['split', 'l', "Split an event."],
</ins><span class="cx"> ['fix', 'x', "Fix problems."],
</span><span class="cx"> ['verbose', 'v', "Verbose logging."],
</span><span class="cx"> ['details', 'V', "Detailed logging."],
</span><del>- ['summary', 'S', "Summary of double-bookings."],
</del><ins>+ ['summary', 'S', "Summary of double-bookings/split."],
</ins><span class="cx"> ['tzid', 't', "Timezone to adjust displayed times to."],
</span><span class="cx">
</span><span class="cx"> ['no-organizer', '', "Detect dark events without an organizer"],
</span><span class="lines">@@ -335,7 +351,9 @@
</span><span class="cx"> ['uuid', 'u', "", "Only check this user."],
</span><span class="cx"> ['uid', 'U', "", "Only this event UID."],
</span><span class="cx"> ['nuke', 'e', "", "Remove event given its path."],
</span><del>- ['days', 'T', "365", "Number of days for scanning events into the future."]
</del><ins>+ ['days', 'T', "365", "Number of days for scanning events into the future."],
+ ['path', '', "", "Split event given its path."],
+ ['rid', '', "", "Split date-time."],
</ins><span class="cx"> ]
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -2670,6 +2688,122 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span><ins>+class EventSplitService(CalVerifyService):
+ """
+ Service which splits a recurring event at a specific date-time value.
+ """
+
+ def title(self):
+ return "Event Split Service"
+
+
+ @inlineCallbacks
+ def doAction(self):
+ """
+ Split a resource using either its path or resource id.
+ """
+
+ self.txn = self.store.newTransaction()
+
+ path = self.options["path"]
+ if path.startswith("/calendars/__uids__/"):
+ try:
+ pathbits = path.split("/")
+ except TypeError:
+ printusage("Not a valid calendar object resource path: %s" % (path,))
+ if len(pathbits) != 6:
+ printusage("Not a valid calendar object resource path: %s" % (path,))
+ homeName = pathbits[3]
+ calendarName = pathbits[4]
+ resourceName = pathbits[5]
+
+ resid = yield self.getResourceID(homeName, calendarName, resourceName)
+ if resid is None:
+ yield self.txn.commit()
+ self.txn = None
+ self.output.write("\n")
+ self.output.write("Path does not exist. Nothing split.\n")
+ returnValue(None)
+ resid = int(resid)
+ else:
+ try:
+ resid = int(path)
+ except ValueError:
+ printusage("path argument must be a calendar object path or an SQL resource-id")
+
+ calendarObj = yield CalendarStoreFeatures(self.txn._store).calendarObjectWithID(self.txn, resid)
+ ical = yield calendarObj.component()
+
+ # Must be the ORGANIZER's copy
+ organizer = ical.getOrganizer()
+ if organizer is None:
+ printusage("Calendar object has no ORGANIZER property - cannot split")
+
+ # Only allow organizers to split
+ scheduler = ImplicitScheduler()
+ is_attendee = (yield scheduler.testAttendeeEvent(calendarObj.calendar(), calendarObj, ical,))
+ if is_attendee:
+ printusage("Calendar object is not owned by the ORGANIZER - cannot split")
+
+ if self.options["summary"]:
+ result = self.doSummary(ical)
+ else:
+ result = yield self.doSplit(resid, calendarObj, ical)
+
+ returnValue(result)
+
+
+ def doSummary(self, ical):
+ """
+ Print a summary of the recurrence instances of the specified event.
+
+ @param ical: calendar to process
+ @type ical: L{Component}
+ """
+ self.output.write("\n---- Calendar resource instances ----\n")
+
+ # Find the instance RECURRENCE-ID where a split is going to happen
+ now = DateTime.getNowUTC()
+ now.offsetDay(1)
+ instances = ical.cacheExpandedTimeRanges(now)
+ instances = sorted(instances.instances.values(), key=lambda x: x.start)
+ for instance in instances:
+ self.output.write(instance.rid.getText() + (" *\n" if instance.overridden else "\n"))
+
+
+ @inlineCallbacks
+ def doSplit(self, resid, calendarObj, ical):
+ rid = self.options["rid"]
+ try:
+ if rid[-1] != "Z":
+ raise ValueError
+ rid = DateTime.parseText(rid)
+ except ValueError:
+ printusage("rid must be a valid UTC date-time value: 'YYYYMMDDTHHMMSSZ'")
+
+ self.output.write("\n---- Splitting calendar resource ----\n")
+
+ # Find actual RECURRENCE-ID of split
+ splitter = iCalSplitter(1024, 14)
+ rid = splitter.whereSplit(ical, break_point=rid, allow_past_the_end=False)
+ if rid is None:
+ printusage("rid is not a valid recurrence instance")
+
+ self.output.write("\n")
+ self.output.write("Actual RECURRENCE-ID: %s.\n" % (rid,))
+
+ oldUID = yield calendarObj.split(rid=rid)
+
+ self.output.write("\n")
+ self.output.write("Split Resource: %s at %s, old UID: %s.\n" % (resid, rid, oldUID,))
+
+ yield self.txn.commit()
+ self.txn = None
+
+ returnValue(oldUID)
+
+
+
</ins><span class="cx"> def main(argv=sys.argv, stderr=sys.stderr, reactor=None):
</span><span class="cx">
</span><span class="cx"> if reactor is None:
</span><span class="lines">@@ -2702,6 +2836,8 @@
</span><span class="cx"> return DoubleBookingService(store, options, output, reactor, config)
</span><span class="cx"> elif options["dark-purge"]:
</span><span class="cx"> return DarkPurgeService(store, options, output, reactor, config)
</span><ins>+ elif options["split"]:
+ return EventSplitService(store, options, output, reactor, config)
</ins><span class="cx"> else:
</span><span class="cx"> printusage("Invalid operation")
</span><span class="cx"> sys.exit(1)
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertoolstesttest_calverifypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py (12240 => 12241)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py        2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py        2014-01-06 21:40:02 UTC (rev 12241)
</span><span class="lines">@@ -20,7 +20,8 @@
</span><span class="cx"> """
</span><span class="cx">
</span><span class="cx"> from calendarserver.tools.calverify import BadDataService, \
</span><del>- SchedulingMismatchService, DoubleBookingService, DarkPurgeService
</del><ins>+ SchedulingMismatchService, DoubleBookingService, DarkPurgeService, \
+ EventSplitService
</ins><span class="cx">
</span><span class="cx"> from pycalendar.datetime import DateTime
</span><span class="cx">
</span><span class="lines">@@ -28,6 +29,7 @@
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx">
</span><span class="cx"> from twistedcaldav.config import config
</span><ins>+from twistedcaldav.ical import normalize_iCalStr
</ins><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><span class="cx">
</span><span class="cx"> from txdav.common.datastore.test.util import populateCalendarsFrom
</span><span class="lines">@@ -2806,3 +2808,322 @@
</span><span class="cx"> self.assertEqual(len(calverify.results["Dark Events"]), 0)
</span><span class="cx"> self.assertTrue("Fix dark events" not in calverify.results)
</span><span class="cx"> self.assertTrue("Fix remove" not in calverify.results)
</span><ins>+
+
+
+class CalVerifyEventPurge(CalVerifyMismatchTestsBase):
+ """
+ Tests calverify for events.
+ """
+
+ # No organizer
+ NO_ORGANIZER_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+CALSCALE:GREGORIAN
+BEGIN:VEVENT
+CREATED:20100303T181216Z
+UID:INVITE_NO_ORGANIZER_ICS
+TRANSP:OPAQUE
+SUMMARY:INVITE_NO_ORGANIZER_ICS
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+DTSTAMP:20100303T181220Z
+SEQUENCE:2
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid attendee
+ VALID_ATTENDEE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_FUTURE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid attendee
+ VALID_ATTENDEE_FUTURE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:INVITE_VALID_ORGANIZER_ICS
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_PAST_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid attendee
+ VALID_ATTENDEE_PAST_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
+SEQUENCE:1
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ # Valid organizer
+ VALID_ORGANIZER_OVERRIDE_ICS = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+BEGIN:VEVENT
+UID:VALID_ORGANIZER_OVERRIDE_ICS
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+BEGIN:VEVENT
+UID:VALID_ORGANIZER_OVERRIDE_ICS
+RECURRENCE-ID:%(now_fwd11)s
+DTSTART:%(now_fwd11)s
+DURATION:PT2H
+ATTENDEE:urn:uuid:%(uuid1)s
+ATTENDEE:urn:uuid:%(uuid2)s
+ORGANIZER:urn:uuid:%(uuid1)s
+RRULE:FREQ=DAILY
+SUMMARY:INVITE_VALID_ORGANIZER_ICS
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+
+ @inlineCallbacks
+ def setUp(self):
+
+ self.subs = {
+ "uuid1" : CalVerifyMismatchTestsBase.uuid1,
+ "uuid2" : CalVerifyMismatchTestsBase.uuid2,
+ }
+
+ self.now = DateTime.getNowUTC()
+ self.now.setHHMMSS(0, 0, 0)
+
+ self.subs["now"] = self.now
+
+ for i in range(30):
+ attrname = "now_back%s" % (i + 1,)
+ setattr(self, attrname, self.now.duplicate())
+ getattr(self, attrname).offsetDay(-(i + 1))
+ self.subs[attrname] = getattr(self, attrname)
+
+ attrname_12h = "now_back%s_12h" % (i + 1,)
+ setattr(self, attrname_12h, getattr(self, attrname).duplicate())
+ getattr(self, attrname_12h).offsetHours(12)
+ self.subs[attrname_12h] = getattr(self, attrname_12h)
+
+ attrname_1 = "now_back%s_1" % (i + 1,)
+ setattr(self, attrname_1, getattr(self, attrname).duplicate())
+ getattr(self, attrname_1).offsetSeconds(-1)
+ self.subs[attrname_1] = getattr(self, attrname_1)
+
+ for i in range(30):
+ attrname = "now_fwd%s" % (i + 1,)
+ setattr(self, attrname, self.now.duplicate())
+ getattr(self, attrname).offsetDay(i + 1)
+ self.subs[attrname] = getattr(self, attrname)
+
+ attrname_12h = "now_fwd%s_12h" % (i + 1,)
+ setattr(self, attrname_12h, getattr(self, attrname).duplicate())
+ getattr(self, attrname_12h).offsetHours(12)
+ self.subs[attrname_12h] = getattr(self, attrname_12h)
+
+ attrname_1 = "now_fwd%s_1" % (i + 1,)
+ setattr(self, attrname_1, getattr(self, attrname).duplicate())
+ getattr(self, attrname_1).offsetSeconds(-1)
+ self.subs[attrname_1] = getattr(self, attrname_1)
+
+ self.requirements = {
+ CalVerifyMismatchTestsBase.uuid1 : {
+ "calendar" : {
+ "invite1.ics" : (self.NO_ORGANIZER_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ "invite2.ics" : (self.VALID_ORGANIZER_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ "invite3.ics" : (self.VALID_ORGANIZER_OVERRIDE_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ },
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuid2 : {
+ "calendar" : {
+ "invite2a.ics" : (self.VALID_ATTENDEE_ICS % self.subs, CalVerifyMismatchTestsBase.metadata,),
+ },
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuid3 : {
+ "calendar" : {},
+ "inbox" : {},
+ },
+ CalVerifyMismatchTestsBase.uuidl1 : {
+ "calendar" : {},
+ "inbox" : {},
+ },
+ }
+
+ yield super(CalVerifyEventPurge, self).setUp()
+
+
+ @inlineCallbacks
+ def test_validSplit(self):
+ """
+ CalVerifyService.doScan without fix for dark events. Make sure it detects
+ as much as it can. Make sure sync-token is not changed.
+ """
+
+ options = {
+ "nuke": False,
+ "missing": False,
+ "ical": False,
+ "mismatch": False,
+ "double": True,
+ "dark-purge": False,
+ "split": True,
+ "path": "/calendars/__uids__/%(uuid1)s/calendar/invite2.ics" % self.subs,
+ "rid": "%(now_fwd11)s" % self.subs,
+ "summary": False,
+ }
+ output = StringIO()
+ calverify = EventSplitService(self._sqlCalendarStore, options, output, reactor, config)
+ oldUID = yield calverify.doAction()
+
+ relsubs = dict(self.subs)
+ relsubs["relID"] = oldUID
+
+ calendar = yield self.calendarUnderTest(home=CalVerifyMismatchTestsBase.uuid1, name="calendar")
+ objs = yield calendar.listObjectResources()
+ self.assertEqual(len(objs), 4)
+ self.assertTrue("invite2.ics" in objs)
+ oldName = filter(lambda x: not x.startswith("invite"), objs)[0]
+
+ obj1 = yield calendar.objectResourceWithName("invite2.ics")
+ ical1 = yield obj1.component()
+ self.assertEqual(normalize_iCalStr(ical1), self.VALID_ORGANIZER_FUTURE_ICS % relsubs)
+
+ obj2 = yield calendar.objectResourceWithName(oldName)
+ ical2 = yield obj2.component()
+ self.assertEqual(normalize_iCalStr(ical2), self.VALID_ORGANIZER_PAST_ICS % relsubs)
+
+ calendar = yield self.calendarUnderTest(home=CalVerifyMismatchTestsBase.uuid2, name="calendar")
+ objs = yield calendar.listObjectResources()
+ self.assertEqual(len(objs), 2)
+ self.assertTrue("invite2a.ics" in objs)
+ oldName = filter(lambda x: not x.startswith("invite"), objs)[0]
+
+ obj1 = yield calendar.objectResourceWithName("invite2a.ics")
+ ical1 = yield obj1.component()
+ self.assertEqual(normalize_iCalStr(ical1), self.VALID_ATTENDEE_FUTURE_ICS % relsubs)
+
+ obj2 = yield calendar.objectResourceWithName(oldName)
+ ical2 = yield obj2.component()
+ self.assertEqual(normalize_iCalStr(ical2), self.VALID_ATTENDEE_PAST_ICS % relsubs)
+
+
+ @inlineCallbacks
+ def test_summary(self):
+ """
+ CalVerifyService.doScan without fix for dark events. Make sure it detects
+ as much as it can. Make sure sync-token is not changed.
+ """
+
+ options = {
+ "nuke": False,
+ "missing": False,
+ "ical": False,
+ "mismatch": False,
+ "double": True,
+ "dark-purge": False,
+ "split": True,
+ "path": "/calendars/__uids__/%(uuid1)s/calendar/invite3.ics" % self.subs,
+ "rid": "%(now_fwd11)s" % self.subs,
+ "summary": True,
+ }
+ output = StringIO()
+ calverify = EventSplitService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+ result = output.getvalue().splitlines()
+ self.assertTrue("%(now)s" % self.subs in result)
+ self.assertTrue("%(now_fwd10)s" % self.subs in result)
+ self.assertTrue("%(now_fwd11)s *" % self.subs in result)
+ self.assertTrue("%(now_fwd12)s" % self.subs in result)
</ins></span></pre></div>
<a id="CalendarServertrunktwistedcaldavicalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/ical.py (12240 => 12241)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/ical.py        2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/twistedcaldav/ical.py        2014-01-06 21:40:02 UTC (rev 12241)
</span><span class="lines">@@ -3645,7 +3645,7 @@
</span><span class="cx"> icalstr = str(icalstr).replace("\r\n ", "")
</span><span class="cx"> icalstr = icalstr.replace("\n ", "")
</span><span class="cx"> icalstr = "\r\n".join([line for line in icalstr.splitlines() if not line.startswith("DTSTAMP")])
</span><del>- return icalstr
</del><ins>+ return icalstr + "\r\n"
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingicalsplitterpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py (12240 => 12241)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py        2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/icalsplitter.py        2014-01-06 21:40:02 UTC (rev 12241)
</span><span class="lines">@@ -83,17 +83,21 @@
</span><span class="cx"> return len(str(ical)) > self.threshold
</span><span class="cx">
</span><span class="cx">
</span><del>- def whereSplit(self, ical):
</del><ins>+ def whereSplit(self, ical, break_point=None, allow_past_the_end=True):
</ins><span class="cx"> """
</span><span class="cx"> Determine where a split is going to happen - i.e., the RECURRENCE-ID.
</span><span class="cx">
</span><span class="cx"> @param ical: the iCalendar object to test
</span><span class="cx"> @type ical: L{Component}
</span><ins>+ @param break_point: the date-time where the break should occur
+ @type break_point: L{DateTime}
</ins><span class="cx">
</span><span class="cx"> @return: recurrence-id of the split
</span><span class="cx"> @rtype: L{DateTime}
</span><span class="cx"> """
</span><span class="cx">
</span><ins>+ break_point = self.past if break_point is None else break_point
+
</ins><span class="cx"> # Find the instance RECURRENCE-ID where a split is going to happen
</span><span class="cx"> now = self.now.duplicate()
</span><span class="cx"> now.offsetDay(1)
</span><span class="lines">@@ -102,13 +106,13 @@
</span><span class="cx"> rid = instances[0].rid
</span><span class="cx"> for instance in instances:
</span><span class="cx"> rid = instance.rid
</span><del>- if instance.start >= self.past:
</del><ins>+ if instance.start >= break_point:
</ins><span class="cx"> break
</span><span class="cx"> else:
</span><del>- # We can get here when splitting and event for overrides only in the past,
</del><ins>+ # We can get here when splitting an event for overrides only in the past,
</ins><span class="cx"> # which happens when splitting an Attendee's copy of an Organizer event
</span><span class="cx"> # where the Organizer event has L{willSplit} == C{True}
</span><del>- rid = self.past
</del><ins>+ rid = break_point if allow_past_the_end else None
</ins><span class="cx">
</span><span class="cx"> return rid
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoreschedulingtesttest_icalsplitterpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py (12240 => 12241)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py        2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/test/test_icalsplitter.py        2014-01-06 21:40:02 UTC (rev 12241)
</span><span class="lines">@@ -63,6 +63,11 @@
</span><span class="cx"> getattr(self, attrname_12h).offsetHours(12)
</span><span class="cx"> self.subs[attrname_12h] = getattr(self, attrname_12h)
</span><span class="cx">
</span><ins>+ attrname_1 = "now_fwd%s_1" % (i + 1,)
+ setattr(self, attrname_1, getattr(self, attrname).duplicate())
+ getattr(self, attrname_1).offsetSeconds(-1)
+ self.subs[attrname_1] = getattr(self, attrname_1)
+
</ins><span class="cx"> self.patch(config, "MaxAllowedInstances", 500)
</span><span class="cx">
</span><span class="cx">
</span><span class="lines">@@ -2018,3 +2023,188 @@
</span><span class="cx"> # Make sure new items won't split again
</span><span class="cx"> self.assertFalse(splitter.willSplit(icalNew), "Failed future will split: %s" % (title,))
</span><span class="cx"> self.assertFalse(splitter.willSplit(icalOld), "Failed past will split: %s" % (title,))
</span><ins>+
+
+ def test_future_split(self):
+
+ data = (
+ (
+ "1.1 - RRULE with override",
+ """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ATTENDEE:mailto:user3@example.com
+ATTENDEE:mailto:user4@example.com
+ATTENDEE:mailto:user5@example.com
+ATTENDEE:mailto:user6@example.com
+ATTENDEE:mailto:user7@example.com
+ATTENDEE:mailto:user8@example.com
+ATTENDEE:mailto:user9@example.com
+ATTENDEE:mailto:user10@example.com
+ATTENDEE:mailto:user11@example.com
+ATTENDEE:mailto:user12@example.com
+ATTENDEE:mailto:user13@example.com
+ATTENDEE:mailto:user14@example.com
+ATTENDEE:mailto:user15@example.com
+ATTENDEE:mailto:user16@example.com
+ATTENDEE:mailto:user17@example.com
+ATTENDEE:mailto:user18@example.com
+ATTENDEE:mailto:user19@example.com
+ATTENDEE:mailto:user20@example.com
+ATTENDEE:mailto:user21@example.com
+ATTENDEE:mailto:user22@example.com
+ATTENDEE:mailto:user23@example.com
+ATTENDEE:mailto:user24@example.com
+ATTENDEE:mailto:user25@example.com
+ORGANIZER:mailto:user1@example.com
+RRULE:FREQ=DAILY
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ORGANIZER:mailto:user1@example.com
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd11)s
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ORGANIZER:mailto:user1@example.com
+END:VEVENT
+END:VCALENDAR
+""",
+ """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ATTENDEE:mailto:user3@example.com
+ATTENDEE:mailto:user4@example.com
+ATTENDEE:mailto:user5@example.com
+ATTENDEE:mailto:user6@example.com
+ATTENDEE:mailto:user7@example.com
+ATTENDEE:mailto:user8@example.com
+ATTENDEE:mailto:user9@example.com
+ATTENDEE:mailto:user10@example.com
+ATTENDEE:mailto:user11@example.com
+ATTENDEE:mailto:user12@example.com
+ATTENDEE:mailto:user13@example.com
+ATTENDEE:mailto:user14@example.com
+ATTENDEE:mailto:user15@example.com
+ATTENDEE:mailto:user16@example.com
+ATTENDEE:mailto:user17@example.com
+ATTENDEE:mailto:user18@example.com
+ATTENDEE:mailto:user19@example.com
+ATTENDEE:mailto:user20@example.com
+ATTENDEE:mailto:user21@example.com
+ATTENDEE:mailto:user22@example.com
+ATTENDEE:mailto:user23@example.com
+ATTENDEE:mailto:user24@example.com
+ATTENDEE:mailto:user25@example.com
+ORGANIZER:mailto:user1@example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY
+END:VEVENT
+BEGIN:VEVENT
+UID:12345-67890
+RECURRENCE-ID:%(now_fwd11)s
+DTSTART:%(now_fwd11)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ORGANIZER:mailto:user1@example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+END:VEVENT
+END:VCALENDAR
+""",
+ """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:%(relID)s
+DTSTART:%(now)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ATTENDEE:mailto:user3@example.com
+ATTENDEE:mailto:user4@example.com
+ATTENDEE:mailto:user5@example.com
+ATTENDEE:mailto:user6@example.com
+ATTENDEE:mailto:user7@example.com
+ATTENDEE:mailto:user8@example.com
+ATTENDEE:mailto:user9@example.com
+ATTENDEE:mailto:user10@example.com
+ATTENDEE:mailto:user11@example.com
+ATTENDEE:mailto:user12@example.com
+ATTENDEE:mailto:user13@example.com
+ATTENDEE:mailto:user14@example.com
+ATTENDEE:mailto:user15@example.com
+ATTENDEE:mailto:user16@example.com
+ATTENDEE:mailto:user17@example.com
+ATTENDEE:mailto:user18@example.com
+ATTENDEE:mailto:user19@example.com
+ATTENDEE:mailto:user20@example.com
+ATTENDEE:mailto:user21@example.com
+ATTENDEE:mailto:user22@example.com
+ATTENDEE:mailto:user23@example.com
+ATTENDEE:mailto:user24@example.com
+ATTENDEE:mailto:user25@example.com
+ORGANIZER:mailto:user1@example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
+END:VEVENT
+BEGIN:VEVENT
+UID:%(relID)s
+RECURRENCE-ID:%(now_fwd10)s
+DTSTART:%(now_fwd10)s
+DURATION:PT1H
+ATTENDEE:mailto:user1@example.com
+ATTENDEE:mailto:user2@example.com
+ORGANIZER:mailto:user1@example.com
+RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
+END:VEVENT
+END:VCALENDAR
+""",
+ ),
+ )
+
+ for title, calendar, split_future, split_past in data:
+ ical = Component.fromString(calendar % self.subs)
+ splitter = iCalSplitter(1024, 14)
+ icalOld, icalNew = splitter.split(ical, rid=DateTime.parseText("%(now_fwd11)s" % self.subs))
+ relsubs = dict(self.subs)
+ relsubs["relID"] = icalOld.resourceUID()
+ self.assertEqual(str(icalNew).replace("\r\n ", ""), split_future.replace("\n", "\r\n") % relsubs, "Failed future: %s" % (title,))
+ self.assertEqual(str(icalOld).replace("\r\n ", ""), split_past.replace("\n", "\r\n") % relsubs, "Failed past: %s" % (title,))
+
+ # Make sure new items won't split again
+ self.assertFalse(splitter.willSplit(icalNew), "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld), "Failed past will split: %s" % (title,))
+
+ ical = Component.fromString(calendar % self.subs)
+ splitter = iCalSplitter(1024, 14)
+ icalOld, icalNew = splitter.split(ical, rid=splitter.whereSplit(ical, break_point=DateTime.parseText("%(now_fwd10_12h)s" % self.subs)))
+ relsubs = dict(self.subs)
+ relsubs["relID"] = icalOld.resourceUID()
+ self.assertEqual(str(icalNew).replace("\r\n ", ""), split_future.replace("\n", "\r\n") % relsubs, "Failed future: %s" % (title,))
+ self.assertEqual(str(icalOld).replace("\r\n ", ""), split_past.replace("\n", "\r\n") % relsubs, "Failed past: %s" % (title,))
+
+ # Make sure new items won't split again
+ self.assertFalse(splitter.willSplit(icalNew), "Failed future will split: %s" % (title,))
+ self.assertFalse(splitter.willSplit(icalOld), "Failed past will split: %s" % (title,))
</ins></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (12240 => 12241)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-01-06 21:15:27 UTC (rev 12240)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-01-06 21:40:02 UTC (rev 12241)
</span><span class="lines">@@ -366,7 +366,7 @@
</span><span class="cx"> @inlineCallbacks
</span><span class="cx"> def calendarObjectWithID(self, txn, rid):
</span><span class="cx"> """
</span><del>- Return all child object resources with the specified UID. Only "owned" resources are returned,
</del><ins>+ Return all child object resources with the specified resource id. Only "owned" resources are returned,
</ins><span class="cx"> no shared resources.
</span><span class="cx">
</span><span class="cx"> @param txn: transaction to use
</span><span class="lines">@@ -378,7 +378,7 @@
</span><span class="cx"> @rtype: L{CalendarObject} or C{None}
</span><span class="cx"> """
</span><span class="cx">
</span><del>- # First find the resource-ids of the (home, parent, object) for each object matching the UID.
</del><ins>+ # First find the resource-ids of the (home, parent, object) for each object matching the resource id.
</ins><span class="cx"> obj = CalendarHome._objectSchema
</span><span class="cx"> bind = CalendarHome._bindSchema
</span><span class="cx"> rows = (yield Select(
</span><span class="lines">@@ -3684,6 +3684,8 @@
</span><span class="cx"> if will:
</span><span class="cx"> notBefore = datetime.datetime.utcnow() + datetime.timedelta(seconds=config.Scheduling.Options.Splitting.Delay)
</span><span class="cx"> work = (yield self._txn.enqueue(CalendarObject.CalendarObjectSplitterWork, resourceID=self._resourceID, notBefore=notBefore))
</span><ins>+
+ # _workItems is used during unit testing only, to track the created work
</ins><span class="cx"> if not hasattr(self, "_workItems"):
</span><span class="cx"> self._workItems = []
</span><span class="cx"> self._workItems.append(work)
</span></span></pre>
</div>
</div>
</body>
</html>