[CalendarServer-changes] [15187] CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav /datastore

source_changes at macosforge.org source_changes at macosforge.org
Tue Oct 13 10:58:36 PDT 2015


Revision: 15187
          http://trac.calendarserver.org//changeset/15187
Author:   cdaboo at apple.com
Date:     2015-10-13 10:58:36 -0700 (Tue, 13 Oct 2015)
Log Message:
-----------
Fix for missing attachment error when attendee shares their invite back to the organizer.

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/sql.py
    CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_attachments.py

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-10-13 17:57:37 UTC (rev 15186)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/sql.py	2015-10-13 17:58:36 UTC (rev 15187)
@@ -27,7 +27,7 @@
 ]
 
 from twext.enterprise.dal.record import fromTable
-from twext.enterprise.dal.syntax import Delete
+from twext.enterprise.dal.syntax import Delete, Union
 from twext.enterprise.dal.syntax import Insert
 from twext.enterprise.dal.syntax import Len
 from twext.enterprise.dal.syntax import Parameter
@@ -582,7 +582,10 @@
             From=co.join(cb, co.PARENT_RESOURCE_ID == cb.RESOURCE_ID,
                          'left outer'),
             Where=(co.DROPBOX_ID == dropboxID).And(
-                cb.HOME_RESOURCE_ID == self._resourceID)
+                cb.HOME_RESOURCE_ID == self._resourceID).And(
+                cb.BIND_MODE == _BIND_MODE_OWN).And(
+                cb.CALENDAR_RESOURCE_NAME != "inbox"),
+            OrderBy=co.RESOURCE_ID,
         ).on(self._txn))
 
         if rows:
@@ -596,16 +599,33 @@
 
     @inlineCallbacks
     def getAllDropboxIDs(self):
+        """
+        Only return dropbox-IDs that actually have an attachment associated with them. To do that we will
+        look at the ATTACHMENT table and get all (old) dropbox ids for the home. Then look at the combined
+        ATTACHMENT and ATTACHMENT_CALENDAR_OBJECT table to get all managed attachment drop box ids. Those
+        results need to be unique and sorted.
+        """
+        att = schema.ATTACHMENT
+        attco = schema.ATTACHMENT_CALENDAR_OBJECT
         co = schema.CALENDAR_OBJECT
-        cb = schema.CALENDAR_BIND
+
+        # Old dropbox items (DROPBOX_ID != "." in ATTACHMENT table)
         rows = (yield Select(
-            [co.DROPBOX_ID],
-            From=co.join(cb, co.PARENT_RESOURCE_ID == cb.RESOURCE_ID),
-            Where=(co.DROPBOX_ID != None).And(
-                cb.HOME_RESOURCE_ID == self._resourceID),
-            OrderBy=co.DROPBOX_ID
+            [att.DROPBOX_ID],
+            From=att,
+            Where=(att.CALENDAR_HOME_RESOURCE_ID == self._resourceID).And(
+                att.DROPBOX_ID != "."),
+            SetExpression=Union(
+                Select(
+                    [co.DROPBOX_ID],
+                    From=att.join(attco, att.ATTACHMENT_ID == attco.ATTACHMENT_ID).join(co, attco.CALENDAR_OBJECT_RESOURCE_ID == co.RESOURCE_ID),
+                    Where=(att.CALENDAR_HOME_RESOURCE_ID == self._resourceID).And(
+                        att.DROPBOX_ID == "."),
+                ),
+                optype=Union.OPTYPE_ALL,
+            )
         ).on(self._txn))
-        returnValue([row[0] for row in rows])
+        returnValue(sorted(set([row[0] for row in rows])))
 
 
     @inlineCallbacks

Modified: CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_attachments.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_attachments.py	2015-10-13 17:57:37 UTC (rev 15186)
+++ CalendarServer/branches/release/CalendarServer-5.4-dev/txdav/caldav/datastore/test/test_attachments.py	2015-10-13 17:58:36 UTC (rev 15187)
@@ -307,6 +307,7 @@
         L{ICalendarObject.getAllDropboxIDs} returns a L{Deferred} that fires
         with a C{list} of all Dropbox IDs.
         """
+        yield self.createAttachmentTest(lambda x: x)
         home = yield self.homeUnderTest()
         # The only item in the home which has an ATTACH or X-APPLE-DROPBOX
         # property.
@@ -899,6 +900,23 @@
         self.assertEquals(data2, "test data 2")
 
 
+    @inlineCallbacks
+    def test_dropboxIDs(self):
+        """
+        L{ICalendarObject.getAllDropboxIDs} returns a L{Deferred} that fires
+        with a C{list} of all Dropbox IDs.
+        """
+        yield self.createAttachmentTest(lambda x: x)
+        home = yield self.homeUnderTest()
+        # The only item in the home which has an ATTACH or X-APPLE-DROPBOX
+        # property.
+        allDropboxIDs = set([
+            u'FE5CDC6F-7776-4607-83A9-B90FF7ACC8D0.dropbox',
+        ])
+        self.assertEquals(set((yield home.getAllDropboxIDs())),
+                          allDropboxIDs)
+
+
     def test_createAttachment(self):
         """
         L{ICalendarObject.createManagedAttachment} will store an
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151013/a8b5c227/attachment.html>


More information about the calendarserver-changes mailing list