[CalendarServer-changes] [14369] CalendarServer/branches/release/CalendarServer-5.4-dev
source_changes at macosforge.org
source_changes at macosforge.org
Wed Feb 4 17:52:07 PST 2015
Revision: 14369
http://trac.calendarserver.org//changeset/14369
Author: cdaboo at apple.com
Date: 2015-02-04 17:52:07 -0800 (Wed, 04 Feb 2015)
Log Message:
-----------
Fix unscheduled-split-scheduled scenario. Other splitting clean-up.
Modified Paths:
--------------
CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py
CalendarServer/branches/release/CalendarServer-5.4-dev/twistedcaldav/storebridge.py
CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/sql.py
CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_sql.py
Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py 2015-02-05 01:51:13 UTC (rev 14368)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/calendarserver/tools/test/test_calverify.py 2015-02-05 01:52:07 UTC (rev 14369)
@@ -2842,8 +2842,8 @@
UID:INVITE_VALID_ORGANIZER_ICS
DTSTART:%(now)s
DURATION:PT1H
-ATTENDEE:urn:uuid:%(uuid1)s
-ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:uuid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:uuid:%(uuid2)s
ORGANIZER:urn:uuid:%(uuid1)s
RRULE:FREQ=DAILY
SUMMARY:INVITE_VALID_ORGANIZER_ICS
@@ -2859,8 +2859,8 @@
UID:INVITE_VALID_ORGANIZER_ICS
DTSTART:%(now)s
DURATION:PT1H
-ATTENDEE:urn:uuid:%(uuid1)s
-ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:uuid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:uuid:%(uuid2)s
ORGANIZER:urn:uuid:%(uuid1)s
RRULE:FREQ=DAILY
SUMMARY:INVITE_VALID_ORGANIZER_ICS
@@ -2876,8 +2876,8 @@
UID:INVITE_VALID_ORGANIZER_ICS
DTSTART:%(now_fwd11)s
DURATION:PT1H
-ATTENDEE:urn:uuid:%(uuid1)s
-ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:uuid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:uuid:%(uuid2)s
ORGANIZER:urn:uuid:%(uuid1)s
RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
RRULE:FREQ=DAILY
@@ -2895,8 +2895,8 @@
UID:INVITE_VALID_ORGANIZER_ICS
DTSTART:%(now_fwd11)s
DURATION:PT1H
-ATTENDEE:urn:uuid:%(uuid1)s
-ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:uuid:%(uuid1)s
+ATTENDEE;RSVP=TRUE:urn:uuid:%(uuid2)s
ORGANIZER:urn:uuid:%(uuid1)s
RELATED-TO;RELTYPE=X-CALENDARSERVER-RECURRENCE-SET:%(relID)s
RRULE:FREQ=DAILY
@@ -2914,8 +2914,8 @@
UID:%(relID)s
DTSTART:%(now)s
DURATION:PT1H
-ATTENDEE:urn:uuid:%(uuid1)s
-ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:uuid:%(uuid1)s
+ATTENDEE;RSVP=TRUE: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
@@ -2933,8 +2933,8 @@
UID:%(relID)s
DTSTART:%(now)s
DURATION:PT1H
-ATTENDEE:urn:uuid:%(uuid1)s
-ATTENDEE:urn:uuid:%(uuid2)s
+ATTENDEE;PARTSTAT=ACCPETED:urn:uuid:%(uuid1)s
+ATTENDEE;RSVP=TRUE: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
Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/twistedcaldav/storebridge.py 2015-02-05 01:51:13 UTC (rev 14368)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/twistedcaldav/storebridge.py 2015-02-05 01:52:07 UTC (rev 14369)
@@ -2972,11 +2972,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/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/sql.py 2015-02-05 01:51:13 UTC (rev 14368)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/sql.py 2015-02-05 01:52:07 UTC (rev 14369)
@@ -1512,6 +1512,8 @@
self._cachedComponent = None
self._cachedCommponentPerUser = {}
+ self._lockedUID = False
+
_allColumns = [
_objectSchema.RESOURCE_ID,
_objectSchema.RESOURCE_NAME,
@@ -2125,15 +2127,27 @@
@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.
+ """
+
+ # Lock it
new_uid = component.resourceUID()
- if internal_state == ComponentUpdateState.NORMAL:
- yield NamedLock.acquire(self._txn, "ImplicitUIDLock:%s" % (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.
@@ -2203,9 +2217,27 @@
# Do scheduling only for owner split
if internal_state == ComponentUpdateState.SPLIT_OWNER:
- yield self.doImplicitScheduling(component, inserting, internal_state, 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, 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:
@@ -2213,7 +2245,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)
@@ -3447,26 +3479,33 @@
@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
ownerPrincipal = self.calendar().ownerHome().directoryRecord()
organizer = component.getOrganizer()
organizerPrincipal = self.directoryService().recordWithCalendarUserAddress(organizer) if organizer else None
if organizer is not None and organizerPrincipal.uid != ownerPrincipal.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)
@@ -3492,7 +3531,7 @@
"""
# First job is to grab a UID lock on this entire series of events
- yield NamedLock.acquire(self._txn, "ImplicitUIDLock:%s" % (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/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_sql.py 2015-02-05 01:51:13 UTC (rev 14368)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_sql.py 2015-02-05 01:52:07 UTC (rev 14369)
@@ -5160,7 +5160,10 @@
responses = ScheduleResponseQueue("REQUEST", responsecode.OK)
for recipient in recipients:
- responses.add(recipient, responsecode.OK, reqstatus=iTIPRequestStatus.MESSAGE_DELIVERED)
+ if recipient.startswith("urn:uuid"):
+ 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)
@@ -6261,13 +6264,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()
newUID = 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)
ical_future = yield cobj1.component()
ical_past = yield cobj2.component()
@@ -6404,7 +6407,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(PyCalendarDateTime.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(PyCalendarDateTime.parseText("%(now_back14)s" % self.subs), pastUID="12345-67890-existing"), InvalidSplit)
+
+
+
class TimeRangeUpdateOptimization(CommonCommonTests, unittest.TestCase):
"""
CalendarObject splitting tests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150204/8db0d107/attachment-0001.html>
More information about the calendarserver-changes
mailing list