[CalendarServer-changes] [8817] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Mar 5 22:56:48 PST 2012


Revision: 8817
          http://trac.macosforge.org/projects/calendarserver/changeset/8817
Author:   glyph at apple.com
Date:     2012-03-05 22:56:48 -0800 (Mon, 05 Mar 2012)
Log Message:
-----------
Modify hasCalendarResourceUIDSomewhereElse to look only at owned calendars rather than shared calendars (i.e. those bound with BIND_MODE_OWN).  This affects scheduling and case-duplication migration.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/caldav/datastore/test/common.py
    CalendarServer/trunk/txdav/caldav/datastore/test/test_scheduling.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Property Changed:
----------------
    CalendarServer/trunk/

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2012-03-05 23:04:10 UTC (rev 8816)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2012-03-06 06:56:48 UTC (rev 8817)
@@ -182,7 +182,9 @@
         # refer to calendar *object* UIDs, since calendar *resources* are an
         # HTTP protocol layer thing, not a data store thing.  (See also
         # objectResourcesWithUID.)
-        objectResources = (yield self.objectResourcesWithUID(uid, ("inbox",)))
+        objectResources = (
+            yield self.objectResourcesWithUID(uid, ["inbox"], False)
+        )
         for objectResource in objectResources:
             if ok_object and objectResource._resourceID == ok_object._resourceID:
                 continue
@@ -198,7 +200,7 @@
     def getCalendarResourcesForUID(self, uid, allow_shared=False):
 
         results = []
-        objectResources = (yield self.objectResourcesWithUID(uid, ("inbox",)))
+        objectResources = (yield self.objectResourcesWithUID(uid, ["inbox"]))
         for objectResource in objectResources:
             if allow_shared or objectResource._parentCollection._owned:
                 results.append(objectResource)

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2012-03-05 23:04:10 UTC (rev 8816)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2012-03-06 06:56:48 UTC (rev 8817)
@@ -989,8 +989,9 @@
     @inlineCallbacks
     def test_hasCalendarResourceUIDSomewhereElse(self):
         """
-        L{ICalendar.calendarObjects} will enumerate the calendar objects present
-        in the filesystem, in name order, but skip those with hidden names.
+        L{ICalendarHome.hasCalendarResourceUIDSomewhereElse} will determine if
+        a calendar object with a conflicting iCalendar UID is found anywhere
+        within the calendar home.
         """
         home = yield self.homeUnderTest()
         object = yield self.calendarObjectUnderTest()
@@ -1002,6 +1003,18 @@
 
         result = (yield home.hasCalendarResourceUIDSomewhereElse("uid2", object, "schedule"))
         self.assertTrue(result)
+        from twistedcaldav.sharing import SharedCollectionRecord
+        scr = SharedCollectionRecord(
+            shareuid="opaque", sharetype="D", summary="ignored",
+            hosturl="/.../__uids__/home_splits/calendar_2",
+            localname="shared_other_calendar"
+        )
+        yield home.retrieveOldShares().addOrUpdateRecord(scr)
+        # uid 2-5 is the UID of a VTODO in home_splits/calendar_2.
+        result = (yield home.hasCalendarResourceUIDSomewhereElse(
+            "uid2-5", object, "schedule"
+        ))
+        self.assertFalse(result)
 
 
     @inlineCallbacks

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_scheduling.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_scheduling.py	2012-03-05 23:04:10 UTC (rev 8816)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_scheduling.py	2012-03-06 06:56:48 UTC (rev 8817)
@@ -64,5 +64,6 @@
     test_countComponentTypes = skipit
     test_init = skipit
     test_calendarObjectsWithDirectory = skipit
+    test_hasCalendarResourceUIDSomewhereElse = skipit
 
 del FileStorageTests

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2012-03-05 23:04:10 UTC (rev 8816)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2012-03-06 06:56:48 UTC (rev 8817)
@@ -1257,31 +1257,54 @@
         return datetimeMktime(parseSQLTimestamp(self._modified)) if self._modified else None
 
 
-    @classproperty
-    def _resourceByUIDQuery(cls): #@NoSelf
+    @classmethod
+    def _objectResourceQuery(cls, checkBindMode):
         obj = cls._objectSchema
         bind = cls._bindSchema
-        return Select([obj.PARENT_RESOURCE_ID, obj.RESOURCE_ID],
-                     From=obj.join(bind, obj.PARENT_RESOURCE_ID ==
-                                   bind.RESOURCE_ID),
-                     Where=(obj.UID == Parameter("uid")).And(
-                            bind.HOME_RESOURCE_ID == Parameter("resourceID")))
+        where = ((obj.UID == Parameter("uid"))
+                 .And(bind.HOME_RESOURCE_ID == Parameter("resourceID")))
+        if checkBindMode:
+            where = where.And(bind.BIND_MODE == Parameter("bindMode"))
+        return Select(
+            [obj.PARENT_RESOURCE_ID, obj.RESOURCE_ID],
+            From=obj.join(bind, obj.PARENT_RESOURCE_ID == bind.RESOURCE_ID),
+            Where=where
+        )
 
 
+    @classproperty
+    def _resourceByUIDQuery(cls): #@NoSelf
+        return cls._objectResourceQuery(checkBindMode=False)
+
+
+    @classproperty
+    def _resourceByUIDBindQuery(cls): #@NoSelf
+        return cls._objectResourceQuery(checkBindMode=True)
+
+
     @inlineCallbacks
-    def objectResourcesWithUID(self, uid, ignore_children=()):
+    def objectResourcesWithUID(self, uid, ignore_children=[], allowShared=True):
         """
         Return all child object resources with the specified UID, ignoring any
         in the named child collections.
         """
         results = []
-        rows = (yield self._resourceByUIDQuery.on(self._txn, uid=uid,
-                                                  resourceID=self._resourceID))
+        if allowShared:
+            rows = (yield self._resourceByUIDQuery.on(
+                self._txn, uid=uid, resourceID=self._resourceID
+            ))
+        else:
+            rows = (yield self._resourceByUIDBindQuery.on(
+                self._txn, uid=uid, resourceID=self._resourceID,
+                bindMode=_BIND_MODE_OWN
+            ))
         if rows:
             for childID, objectID in rows:
                 child = (yield self.childWithID(childID))
                 if child and child.name() not in ignore_children:
-                    objectResource = (yield child.objectResourceWithID(objectID))
+                    objectResource = (
+                        yield child.objectResourceWithID(objectID)
+                    )
                     results.append(objectResource)
 
         returnValue(results)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120305/a5f260bc/attachment-0001.html>


More information about the calendarserver-changes mailing list