[CalendarServer-changes] [14843] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Thu May 28 13:00:19 PDT 2015


Revision: 14843
          http://trac.calendarserver.org//changeset/14843
Author:   cdaboo at apple.com
Date:     2015-05-28 13:00:18 -0700 (Thu, 28 May 2015)
Log Message:
-----------
Fix for splitting of an attendee trashed item. Trash api clean-up.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/trash.py
    CalendarServer/trunk/calendarserver/tools/util.py
    CalendarServer/trunk/requirements-dev.txt
    CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/carddav/datastore/sql.py
    CalendarServer/trunk/txdav/common/datastore/sql.py
    CalendarServer/trunk/txdav/common/datastore/test/test_trash.py

Modified: CalendarServer/trunk/calendarserver/tools/trash.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/trash.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/calendarserver/tools/trash.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -160,7 +160,7 @@
 
     component = yield event.component()
     mainSummary = component.mainComponent().propertyValue("SUMMARY", u"<no title>")
-    whenTrashed = yield event.whenTrashed()
+    whenTrashed = event.whenTrashed()
     ago = nowDT - whenTrashed
     print("   Trashed {}:".format(agoString(ago)))
 

Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/calendarserver/tools/util.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -520,7 +520,7 @@
 
     component = yield event.component()
     mainSummary = component.mainComponent().propertyValue("SUMMARY", u"<no title>")
-    whenTrashed = yield event.whenTrashed()
+    whenTrashed = event.whenTrashed()
     ago = nowDT - whenTrashed
 
     detail["summary"] = mainSummary

Modified: CalendarServer/trunk/requirements-dev.txt
===================================================================
--- CalendarServer/trunk/requirements-dev.txt	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/requirements-dev.txt	2015-05-28 20:00:18 UTC (rev 14843)
@@ -8,4 +8,4 @@
 q
 tl.eggdeps
 --editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@14811#egg=CalDAVClientLibrary
---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14840#egg=CalDAVTester
+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@14842#egg=CalDAVTester

Modified: CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/txdav/caldav/datastore/scheduling/processing.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -168,7 +168,7 @@
         if calendar_resource:
             self.recipient_calendar = (yield calendar_resource.componentForUser(self.recipient.record.uid)).duplicate()
             self.recipient_calendar_resource = calendar_resource
-            self.recipient_in_trash = (yield self.recipient_calendar_resource.isInTrash())
+            self.recipient_in_trash = self.recipient_calendar_resource.isInTrash()
 
 
     @inlineCallbacks

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -605,7 +605,7 @@
         objectResources = (yield self.getCalendarResourcesForUID(uid))
         for objectResource in objectResources:
             # The matching calendar resource is in the trash, so delete it
-            if (yield objectResource.isInTrash()):
+            if objectResource.isInTrash():
                 yield objectResource.purge(implicitly=False)
                 continue
             if ok_object and objectResource._resourceID == ok_object._resourceID:
@@ -3936,6 +3936,8 @@
                 )[0]
                 self._created = parseSQLTimestamp(self._created)
                 self._modified = parseSQLTimestamp(self._modified)
+                self._original_collection = None
+                self._trashed = None
             else:
                 values[co.MODIFIED] = utcNowSQL
                 self._modified = parseSQLTimestamp((
@@ -5160,6 +5162,12 @@
             split_details=(rid, newerUID, False, False)
         )
 
+        # Reconcile trash state
+        if self.isInTrash():
+            yield olderObject._updateToTrashQuery.on(
+                olderObject._txn, originalCollection=self._original_collection, trashed=self._trashed, resourceID=olderObject._resourceID
+            )
+
         # Split each one - but not this resource
         for resource in resources:
             if resource._resourceID == self._resourceID:
@@ -5208,9 +5216,15 @@
 
         # Create a new resource and store its data (but not if the parent is "inbox", or if it is empty)
         if not self.calendar().isInbox() and ical_old.mainType() is not None:
-            yield self.calendar()._createCalendarObjectWithNameInternal("{0}.ics".format(olderUID,), ical_old, ComponentUpdateState.SPLIT_ATTENDEE)
+            olderObject = yield self.calendar()._createCalendarObjectWithNameInternal("{0}.ics".format(olderUID,), ical_old, ComponentUpdateState.SPLIT_ATTENDEE)
 
+            # Reconcile trash state
+            if self.isInTrash():
+                yield olderObject._updateToTrashQuery.on(
+                    olderObject._txn, originalCollection=self._original_collection, trashed=self._trashed, resourceID=olderObject._resourceID
+                )
 
+
     class CalendarObjectSplitterWork(WorkItem, fromTable(schema.CALENDAR_OBJECT_SPLITTER_WORK)):
 
         group = property(lambda self: (self.table.RESOURCE_ID == self.resourceID))

Modified: CalendarServer/trunk/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/sql.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/txdav/carddav/datastore/sql.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -2634,6 +2634,8 @@
             )[0]
             self._created = parseSQLTimestamp(self._created)
             self._modified = parseSQLTimestamp(self._modified)
+            self._is_in_trash = None
+            self._trashed = None
 
             # delete foreign members table rows for this object
             groupIDRows = yield Select(

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -3706,7 +3706,7 @@
         """
 
         if config.EnableTrashCollection:
-            isInTrash = yield self.isInTrash()
+            isInTrash = self.isInTrash()
             if isInTrash:
                 raise AlreadyInTrashError
             else:
@@ -3835,12 +3835,6 @@
                     yield child.fromTrash()
 
 
-    @classproperty
-    def _selectIsInTrashQuery(cls):
-        table = cls._homeChildMetaDataSchema
-        return Select((table.IS_IN_TRASH, table.TRASHED), From=table, Where=table.RESOURCE_ID == Parameter("resourceID"))
-
-
     def isInTrash(self):
         return getattr(self, "_isInTrash", False)
 
@@ -5268,8 +5262,11 @@
         trash = yield self._parentCollection.ownerHome().getTrash(create=True)
         newName = str(uuid4())
         yield self.moveTo(trash, name=newName)
+
+        self._original_collection = originalCollection
+        self._trashed = datetime.datetime.utcnow()
         yield self._updateToTrashQuery.on(
-            self._txn, originalCollection=originalCollection, trashed=datetime.datetime.utcnow(), resourceID=self._resourceID
+            self._txn, originalCollection=self._original_collection, trashed=self._trashed, resourceID=self._resourceID
         )
         returnValue(newName)
 
@@ -5278,37 +5275,23 @@
     def fromTrash(self):
         originalCollection = yield self.originalCollection()
         yield self.moveTo(originalCollection)
+
+        self._original_collection = None
+        self._trashed = None
         yield self._updateFromTrashQuery.on(
             self._txn, resourceID=self._resourceID
         )
         returnValue(self._name)
 
 
-    @classproperty
-    def _selectIsInTrashQuery(cls):
-        obj = cls._objectSchema
-        return Select((obj.ORIGINAL_COLLECTION, obj.TRASHED), From=obj, Where=obj.RESOURCE_ID == Parameter("resourceID"))
-
-
-    @inlineCallbacks
     def isInTrash(self):
-        originalCollectionID = (
-            yield self._selectIsInTrashQuery.on(
-                self._txn, resourceID=self._resourceID
-            )
-        )[0][0]
-        returnValue(originalCollectionID is not None)
+        return (getattr(self, "_original_collection", None) is not None) or getattr(self, "_isInTrash", False)
 
 
-    @inlineCallbacks
     def whenTrashed(self):
-        returnValue(
-            (
-                yield self._selectIsInTrashQuery.on(
-                    self._txn, resourceID=self._resourceID
-                )
-            )[0][1]
-        )
+        if self._trashed is None:
+            return None
+        return parseSQLTimestamp(self._trashed)
 
 
     def purge(self):

Modified: CalendarServer/trunk/txdav/common/datastore/test/test_trash.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_trash.py	2015-05-28 19:58:44 UTC (rev 14842)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_trash.py	2015-05-28 20:00:18 UTC (rev 14843)
@@ -165,8 +165,8 @@
         self.assertEquals(len(objects), 0)
 
         # Verify it's not in the trash
-        self.assertFalse((yield resource.isInTrash()))
-        trashed = yield resource.whenTrashed()
+        self.assertFalse(resource.isInTrash())
+        trashed = resource.whenTrashed()
         self.assertTrue(trashed is None)
 
         # Move object to trash
@@ -179,8 +179,8 @@
 
         # Verify it's in the trash
         resource = yield self._getResource(txn, "user01", trash.name(), newName)
-        self.assertTrue((yield resource.isInTrash()))
-        trashed = yield resource.whenTrashed()
+        self.assertTrue(resource.isInTrash())
+        trashed = resource.whenTrashed()
         self.assertFalse(trashed is None)
 
         # No objects in collection
@@ -208,8 +208,8 @@
         resourceNames = yield self._getResourceNames(txn, "user01", "calendar")
         self.assertEqual(len(resourceNames), 1)
         resource = yield self._getResource(txn, "user01", "calendar", newName)
-        self.assertFalse((yield resource.isInTrash()))
-        trashed = yield resource.whenTrashed()
+        self.assertFalse(resource.isInTrash())
+        trashed = resource.whenTrashed()
         self.assertTrue(trashed is None)
 
         # No objects in trash
@@ -322,8 +322,8 @@
         # user01's copy is in the trash, still with user02 accepted
         txn = self.store.newTransaction()
         resource = yield self._getResource(txn, "user01", trash1.name(), "")
-        self.assertTrue((yield resource.isInTrash()))
-        trashed = yield resource.whenTrashed()
+        self.assertTrue(resource.isInTrash())
+        trashed = resource.whenTrashed()
         self.assertFalse(trashed is None)
         data = yield self._getResourceData(txn, "user01", trash1.name(), "")
         self.assertTrue("PARTSTAT=ACCEPTED" in data)
@@ -357,8 +357,8 @@
 
         # user01's copy should be back on their calendar
         resource = yield self._getResource(txn, "user01", "calendar", "")
-        self.assertFalse((yield resource.isInTrash()))
-        trashed = yield resource.whenTrashed()
+        self.assertFalse(resource.isInTrash())
+        trashed = resource.whenTrashed()
         self.assertTrue(trashed is None)
         data = yield self._getResourceData(txn, "user01", "calendar", "")
         self.assertTrue("PARTSTAT=NEEDS-ACTION" in data)
@@ -1768,8 +1768,8 @@
         self.assertEquals(len(objects), 0)
 
         # Verify it's not in the trash
-        self.assertFalse((yield resource.isInTrash()))
-        trashed = yield resource.whenTrashed()
+        self.assertFalse(resource.isInTrash())
+        trashed = resource.whenTrashed()
         self.assertTrue(trashed is None)
 
         collection = yield self._collectionForUser(txn, "user01", "test")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150528/a75288de/attachment-0001.html>


More information about the calendarserver-changes mailing list