[CalendarServer-changes] [14367] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Wed Feb 4 17:50:31 PST 2015


Revision: 14367
          http://trac.calendarserver.org//changeset/14367
Author:   cdaboo at apple.com
Date:     2015-02-04 17:50:31 -0800 (Wed, 04 Feb 2015)
Log Message:
-----------
Fix unscheduled-split-scheduled scenario. Other splitting clean-up.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
    CalendarServer/trunk/requirements-dev.txt
    CalendarServer/trunk/twistedcaldav/storebridge.py
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py

Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py	2015-02-05 01:48:54 UTC (rev 14366)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py	2015-02-05 01:50:31 UTC (rev 14367)
@@ -2507,8 +2507,8 @@
 UID:INVITE_VALID_ORGANIZER_ICS
 DTSTART:%(now)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RRULE:FREQ=DAILY
 SUMMARY:INVITE_VALID_ORGANIZER_ICS
@@ -2524,8 +2524,8 @@
 UID:INVITE_VALID_ORGANIZER_ICS
 DTSTART:%(now)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RRULE:FREQ=DAILY
 SUMMARY:INVITE_VALID_ORGANIZER_ICS
@@ -2541,8 +2541,8 @@
 UID:INVITE_VALID_ORGANIZER_ICS
 DTSTART:%(now_fwd11)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
 RRULE:FREQ=DAILY
@@ -2560,8 +2560,8 @@
 UID:INVITE_VALID_ORGANIZER_ICS
 DTSTART:%(now_fwd11)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
 RRULE:FREQ=DAILY
@@ -2579,8 +2579,8 @@
 UID:%(uid)s
 DTSTART:%(now)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
 RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
@@ -2598,8 +2598,8 @@
 UID:%(uid)s
 DTSTART:%(now)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
 RRULE:FREQ=DAILY;UNTIL=%(now_fwd11_1)s
@@ -2617,8 +2617,8 @@
 UID:VALID_ORGANIZER_OVERRIDE_ICS
 DTSTART:%(now)s
 DURATION:PT1H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RRULE:FREQ=DAILY
 SUMMARY:INVITE_VALID_ORGANIZER_ICS
@@ -2628,8 +2628,8 @@
 RECURRENCE-ID:%(now_fwd11)s
 DTSTART:%(now_fwd11)s
 DURATION:PT2H
-ATTENDEE:urn:x-uid:%(uuid1)s
-ATTENDEE:urn:x-uid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:x-uid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:x-uid:%(uuid2)s
 ORGANIZER:urn:x-uid:%(uuid1)s
 RRULE:FREQ=DAILY
 SUMMARY:INVITE_VALID_ORGANIZER_ICS

Modified: CalendarServer/trunk/requirements-dev.txt
===================================================================
--- CalendarServer/trunk/requirements-dev.txt	2015-02-05 01:48:54 UTC (rev 14366)
+++ CalendarServer/trunk/requirements-dev.txt	2015-02-05 01:50:31 UTC (rev 14367)
@@ -8,4 +8,4 @@
 q
 tl.eggdeps
 --editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@13420#egg=CalDAVClientLibrary
---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14362#egg=CalDAVTester
+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14366#egg=CalDAVTester

Modified: CalendarServer/trunk/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/storebridge.py	2015-02-05 01:48:54 UTC (rev 14366)
+++ CalendarServer/trunk/twistedcaldav/storebridge.py	2015-02-05 01:50:31 UTC (rev 14367)
@@ -3007,11 +3007,11 @@
 
         try:
             otherStoreObject = yield self._newStoreObject.splitAt(rid, pastUID)
-        except InvalidSplit:
+        except InvalidSplit as e:
             raise HTTPError(ErrorResponse(
                 FORBIDDEN,
                 (calendarserver_namespace, "invalid-split",),
-                "The rid parameter in the request-URI contains an invalid value",
+                str(e),
             ))
 
         other = yield request.locateChildResource(self._parentResource, otherStoreObject.name())

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2015-02-05 01:48:54 UTC (rev 14366)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2015-02-05 01:50:31 UTC (rev 14367)
@@ -2261,7 +2261,9 @@
         self._cachedComponent = None
         self._cachedCommponentPerUser = {}
 
+        self._lockedUID = False
 
+
     @classmethod
     @inlineCallbacks
     def _createInternal(cls, parent, name, component, internal_state, options=None, split_details=None):
@@ -3074,8 +3076,8 @@
                 internal_request=is_internal,
             ))
 
-            # group attendees
-            if scheduler.state == "organizer":
+            # Group attendees - though not during a split
+            if scheduler.state == "organizer" and internal_state != ComponentUpdateState.SPLIT_OWNER:
                 changed = yield self.reconcileGroupAttendees(component, inserting)
                 if changed:
                     yield scheduler.extractAttendees()
@@ -3172,15 +3174,26 @@
 
 
     @inlineCallbacks
-    def _lockUID(self, component, inserting, internal_state):
+    def _lockUID(self, uid, internal_state):
         """
         Create a lock on the component's UID and verify, after getting the lock, that the incoming UID
         meets the requirements of the store.
         """
 
+        if not self._lockedUID and internal_state in (ComponentUpdateState.NORMAL, ComponentUpdateState.SPLIT_OWNER):
+            yield NamedLock.acquire(self._txn, "ImplicitUIDLock:%s" % (hashlib.md5(uid).hexdigest(),))
+            self._lockedUID = True
+
+
+    @inlineCallbacks
+    def _lockAndCheckUID(self, component, inserting, internal_state):
+        """
+        Create a lock on the component's UID and verify, after getting the lock, that the incoming UID
+        meets the requirements of the store.
+        """
+
         new_uid = component.resourceUID()
-        if internal_state == ComponentUpdateState.NORMAL:
-            yield NamedLock.acquire(self._txn, "ImplicitUIDLock:{0}".format(hashlib.md5(new_uid).hexdigest(),))
+        yield self._lockUID(new_uid, internal_state)
 
         # UID conflict check - note we do this after reserving the UID to avoid a race condition where two requests
         # try to write the same calendar data to two different resource URIs.
@@ -3260,9 +3273,27 @@
 
             # Do scheduling only for owner split
             if internal_state == ComponentUpdateState.SPLIT_OWNER:
-                yield self.doImplicitScheduling(component, inserting, internal_state, options, split_details)
+                # UID lock - this will remain active until the end of the current txn
+                yield self._lockAndCheckUID(component, inserting, internal_state)
 
-            self.isScheduleObject = True
+                # Make sure various bits of scheduling meta-data are correctly setup to ensure the
+                # new resource created by a split has the proper state
+                implicit_result = yield self.doImplicitScheduling(component, inserting, internal_state, options, split_details)
+                if isinstance(implicit_result, int):
+                    msg = "Invalid return status code from ImplicitScheduler during split: %s" % (implicit_result,)
+                    log.error(msg)
+                    raise InvalidObjectResourceError(msg)
+
+                self.isScheduleObject, new_component, did_implicit_action, schedule_state = implicit_result
+                if new_component is not None:
+                    component = new_component
+                if did_implicit_action:
+                    self._componentChanged = True
+
+            elif internal_state == ComponentUpdateState.SPLIT_ATTENDEE:
+                # This must always be set since the only time we get is is during scheduling
+                self.isScheduleObject = True
+
             self.processScheduleTags(component, inserting, internal_state)
 
         elif internal_state != ComponentUpdateState.RAW:
@@ -3270,7 +3301,7 @@
             yield self.fullValidation(component, inserting, internal_state)
 
             # UID lock - this will remain active until the end of the current txn
-            yield self._lockUID(component, inserting, internal_state)
+            yield self._lockAndCheckUID(component, inserting, internal_state)
 
             # Preserve private comments
             yield self.preservePrivateComments(component, inserting, internal_state)
@@ -4615,25 +4646,32 @@
         @type pastuid: L{str}
         """
 
+        # Cannot create one with the same UID as this
+        if pastUID and pastUID == self._uid:
+            raise InvalidSplit("Cannot split an event and re-use the same UID.")
+
         # Must be recurring
         component = yield self.component()
         if not component.isRecurring():
-            raise InvalidSplit()
+            raise InvalidSplit("Cannot split a non-recurring event.")
 
         # Cannot be attendee
         organizer = component.getOrganizer()
         organizerAddress = (yield calendarUserFromCalendarUserAddress(organizer, self._txn)) if organizer else None
         if organizer is not None and organizerAddress.record.uid != self.calendar().ownerHome().uid():
-            raise InvalidSplit()
+            raise InvalidSplit("Only organizers can split events.")
 
         # Determine valid split point
         splitter = iCalSplitter(1024, 14)
         rid = splitter.whereSplit(component, break_point=rid, allow_past_the_end=False)
         if rid is None:
-            raise InvalidSplit()
+            raise InvalidSplit("Cannot find a suitable recurrence-id to split at.")
 
         # Do split and return new resource
-        olderObject = yield self.split(rid=rid, olderUID=pastUID)
+        try:
+            olderObject = yield self.split(rid=rid, olderUID=pastUID)
+        except (UIDExistsError, UIDExistsElsewhereError):
+            raise InvalidSplit("Chosen UID exists elsewhere.")
         returnValue(olderObject)
 
 
@@ -4671,7 +4709,7 @@
         """
 
         # First job is to grab a UID lock on this entire series of events
-        yield NamedLock.acquire(self._txn, "ImplicitUIDLock:{0}".format(hashlib.md5(self._uid).hexdigest(),))
+        yield self._lockUID(self._uid, internal_state=ComponentUpdateState.SPLIT_OWNER)
 
         # Find all other calendar objects on this server with the same UID
         if onlyThis:

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2015-02-05 01:48:54 UTC (rev 14366)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2015-02-05 01:50:31 UTC (rev 14367)
@@ -5455,7 +5455,10 @@
 
             responses = ScheduleResponseQueue("REQUEST", responsecode.OK)
             for recipient in recipients:
-                responses.add(recipient, responsecode.OK, reqstatus=iTIPRequestStatus.MESSAGE_DELIVERED)
+                if recipient.startswith("urn:x-uid"):
+                    responses.add(recipient, responsecode.OK, reqstatus=iTIPRequestStatus.MESSAGE_DELIVERED)
+                else:
+                    responses.add(recipient, responsecode.NOT_FOUND, reqstatus=iTIPRequestStatus.INVALID_CALENDAR_USER)
             return succeed(responses)
 
         component = Component.fromString(data % self.subs)
@@ -6867,13 +6870,13 @@
 
         # Get the existing and new object data
         cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
-        self.assertTrue(cobj1.isScheduleObject)
+        self.assertFalse(cobj1.isScheduleObject)
         ical1 = yield cobj1.component()
         relID = ical1.masterComponent().propertyValue("RELATED-TO")
 
         cobj2 = yield self.calendarObjectUnderTest(name=oldname, calendar_name="calendar", home="user01")
         self.assertTrue(cobj2 is not None)
-        self.assertTrue(cobj2.isScheduleObject)
+        self.assertFalse(cobj2.isScheduleObject)
         ical2 = yield cobj2.component()
         newUID = ical2.masterComponent().propertyValue("UID")
 
@@ -7013,7 +7016,57 @@
         self.assertEqual(normalize_iCalStr(ical_inbox), normalize_iCalStr(data_inbox2) % relsubs, "Failed inbox: %s" % (title,))
 
 
+    @inlineCallbacks
+    def test_calendarObjectSplit_splitat_no_same_uid(self):
+        """
+        Test that user triggered splitting of calendar objects does not work if the specified UID is the same
+        as the resource being split.
+        """
 
+        yield self._setupSplitAt()
+
+        # Update it
+        cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+        yield self.failUnlessFailure(cobj.splitAt(DateTime.parseText("%(now_back14)s" % self.subs), pastUID="12345-67890"), InvalidSplit)
+
+
+    @inlineCallbacks
+    def test_calendarObjectSplit_splitat_no_existing_uid(self):
+        """
+        Test that user triggered splitting of calendar objects does not work if the specified UID is the same
+        as another resource.
+        """
+
+        data_existing = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890-existing
+DTSTART:%(now_back28)s
+DURATION:PT1H
+DTSTAMP:20051222T210507Z
+RRULE:FREQ=DAILY;COUNT=50
+SUMMARY:1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+ 1234567890123456789012345678901234567890
+END:VEVENT
+END:VCALENDAR
+"""
+
+        yield self._setupSplitAt()
+
+        calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+        component = Component.fromString(data_existing % self.subs)
+        yield calendar.createCalendarObjectWithName("data2.ics", component)
+        yield self.commit()
+
+        # Update it
+        cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+        yield self.failUnlessFailure(cobj.splitAt(DateTime.parseText("%(now_back14)s" % self.subs), pastUID="12345-67890-existing"), InvalidSplit)
+
+
+
 class TimeRangeUpdateOptimization(CommonCommonTests, unittest.TestCase):
     """
     CalendarObject time range optimization tests.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150204/3e9c5c19/attachment-0001.html>


More information about the calendarserver-changes mailing list