[CalendarServer-changes] [14258] CalendarServer/branches/users/sagen/trashcan

source_changes at macosforge.org source_changes at macosforge.org
Wed Jan 7 10:17:30 PST 2015


Revision: 14258
          http://trac.calendarserver.org//changeset/14258
Author:   sagen at apple.com
Date:     2015-01-07 10:17:29 -0800 (Wed, 07 Jan 2015)
Log Message:
-----------
Checkpoint of trashcan work

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/trashcan/twistedcaldav/method/report_sync_collection.py
    CalendarServer/branches/users/sagen/trashcan/twistedcaldav/storebridge.py
    CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py
    CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/test/test_sql.py
    CalendarServer/branches/users/sagen/trashcan/txdav/carddav/datastore/sql.py
    CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py
    CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/util.py
    CalendarServer/branches/users/sagen/trashcan/txdav/common/icommondatastore.py

Modified: CalendarServer/branches/users/sagen/trashcan/twistedcaldav/method/report_sync_collection.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/twistedcaldav/method/report_sync_collection.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/twistedcaldav/method/report_sync_collection.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -25,7 +25,9 @@
 from twisted.internet.defer import inlineCallbacks, returnValue
 
 from twistedcaldav.config import config
-from twistedcaldav.method.report_common import _namedPropertiesForResource
+from twistedcaldav.method.report_common import (
+    _namedPropertiesForResource, responseForHref
+)
 
 from txdav.common.icommondatastore import ConcurrentModification
 from txdav.xml import element
@@ -33,7 +35,6 @@
 from txweb2 import responsecode
 from txweb2.dav.http import ErrorResponse
 from txweb2.dav.http import MultiStatusResponse
-from txweb2.dav.method.prop_common import responseForHref
 from txweb2.dav.util import joinURL
 from txweb2.http import HTTPError, StatusResponse
 

Modified: CalendarServer/branches/users/sagen/trashcan/twistedcaldav/storebridge.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/twistedcaldav/storebridge.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/twistedcaldav/storebridge.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -73,7 +73,7 @@
     InvalidObjectResourceError, ObjectResourceNameNotAllowedError,
     ObjectResourceNameAlreadyExistsError, UIDExistsError,
     UIDExistsElsewhereError, InvalidUIDError, InvalidResourceMove,
-    InvalidComponentForStoreError
+    InvalidComponentForStoreError, AlreadyInTrashError
 )
 from txdav.idav import PropertyChangeNotAllowedError
 from txdav.who.wiki import RecordType as WikiRecordType
@@ -2700,6 +2700,7 @@
         DuplicatePrivateCommentsError: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "no-duplicate-private-comments",),),
         LockTimeout: (_CommonObjectResource._storeExceptionUnavailable, "Lock timed out.",),
         UnknownTimezone: (_CommonObjectResource._storeExceptionError, (caldav_namespace, "valid-timezone"),),
+        AlreadyInTrashError: (_CommonObjectResource._storeExceptionError, (calendarserver_namespace, "not-in-trash",),),
     }
 
     StoreMoveExceptionsErrors = {

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -692,6 +692,9 @@
             # Ignore inbox - also shared calendars are not part of .calendars()
             if calendar.isInbox():
                 continue
+            # Ignore trash
+            if calendar.isTrash():
+                continue
             split_count = yield calendar.splitCollectionByComponentTypes()
             self.log.warn("  Calendar: '{0}', split into {1}".format(calendar.name(), split_count + 1,))
 
@@ -713,6 +716,8 @@
             for calendar in calendars:
                 if calendar.isInbox():
                     continue
+                if calendar.isTrash():
+                    continue
                 names.add(calendar.name())
                 result = yield calendar.getSupportedComponents()
                 supported_components.update(result.split(","))
@@ -753,6 +758,8 @@
         # Check validity of the default
         if calendar.isInbox():
             raise InvalidDefaultCalendar("Cannot set inbox as a default calendar")
+        elif calendar.isTrash():
+            raise InvalidDefaultCalendar("Cannot set trash as a default calendar")
         elif not calendar.owned():
             raise InvalidDefaultCalendar("Cannot set shared calendar as a default calendar")
         elif not calendar.isSupportedComponent(componentType):
@@ -807,6 +814,8 @@
         if default is not None:
             if default.isInbox():
                 default = None
+            elif default.isTrash():
+                default = None
             elif not default.owned():
                 default = None
             elif not default.isSupportedComponent(componentType):
@@ -822,6 +831,8 @@
                 calendar = (yield self.calendarWithName(calendarName))
                 if calendar.isInbox():
                     continue
+                elif calendar.isTrash():
+                    continue
                 elif not calendar.owned():
                     continue
                 elif not calendar.isSupportedComponent(componentType):
@@ -1313,7 +1324,7 @@
         @return: C{True} if it does, C{False} otherwise
         @rtype: C{bool}
         """
-        return (self._transp == _TRANSP_OPAQUE) and not self.isInbox()
+        return (self._transp == _TRANSP_OPAQUE) and not self.isInbox() and not self.isTrash()
 
 
     @inlineCallbacks
@@ -1327,7 +1338,7 @@
         @type use_it: C{bool}
         """
 
-        self._transp = _TRANSP_OPAQUE if use_it and not self.isInbox() else _TRANSP_TRANSPARENT
+        self._transp = _TRANSP_OPAQUE if use_it and (not self.isInbox() and not self.isTrash()) else _TRANSP_TRANSPARENT
         cal = self._bindSchema
         yield Update(
             {cal.TRANSP : self._transp},
@@ -3893,7 +3904,7 @@
             if self._dropboxID:
                 yield DropBoxAttachment.resourceRemoved(self._txn, self._resourceID, self._dropboxID)
             yield ManagedAttachment.resourceRemoved(self._txn, self._resourceID)
-        yield super(CalendarObject, self).remove()
+        yield super(CalendarObject, self).reallyRemove()
 
         # Do scheduling
         if scheduler is not None:
@@ -5711,6 +5722,19 @@
         )
 
 
+    def isTrash(self):
+        return True
+
+
+    def nameForResource(self, collection, objectResource):
+        return "{}-{}".format(collection._resourceID, objectResource.name())
+
+
+    def parseName(self, name):
+        parentID, resourceName = name.split("-", 1)
+        return int(parentID), resourceName
+
+
     @inlineCallbacks
     def listObjectResources(self):
         """
@@ -5730,13 +5754,12 @@
                     objectResource = (
                         yield child.objectResourceWithID(objectID)
                     )
-                    results.append(objectResource.name())
+                    results.append(self.nameForResource(child, objectResource))
 
         returnValue(results)
 
 
 
-
 # Hook-up class relationships at the end after they have all been defined
 from txdav.caldav.datastore.sql_external import CalendarHomeExternal, CalendarExternal, CalendarObjectExternal
 CalendarHome._externalClass = CalendarHomeExternal

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/test/test_sql.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/test/test_sql.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -466,7 +466,7 @@
         )
         yield migrateHome(fromHome, toHome, lambda x: x.component())
         toCalendars = yield toHome.calendars()
-        self.assertEquals(set([c.name() for c in toCalendars if c.name() != "inbox"]),
+        self.assertEquals(set([c.name() for c in toCalendars if c.name() not in ("inbox", "trash")]),
                           set([k for k in self.requirements['home1'].keys()
                                if self.requirements['home1'][k] is not None]))
         fromCalendars = yield fromHome.calendars()
@@ -496,9 +496,9 @@
             )
 
         supported_components = set()
-        self.assertEqual(len(toCalendars), 2 + len(ical.allowedStoreComponents))
+        self.assertEqual(len(toCalendars), 3 + len(ical.allowedStoreComponents))
         for calendar in toCalendars:
-            if calendar.name() == "inbox":
+            if calendar.name() in ("inbox", "trash"):
                 continue
             result = yield calendar.getSupportedComponents()
             supported_components.add(result)
@@ -524,7 +524,7 @@
             )
 
         supported_components = set()
-        self.assertEqual(len(toCalendars), 3)
+        self.assertEqual(len(toCalendars), 4)
         for calendar in toCalendars:
             if calendar.name() == "inbox":
                 continue
@@ -1947,7 +1947,7 @@
 
         home = yield self.homeUnderTest(name="user01")
         children = yield home.loadChildren()
-        self.assertEqual(len(children), 3)
+        self.assertEqual(len(children), 4)
         yield self.commit()
 
         calendar = yield self.calendarUnderTest(home="user01", name="calendar")

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/carddav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/carddav/datastore/sql.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/carddav/datastore/sql.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -2130,7 +2130,7 @@
                     removed=True,
                 )
 
-        yield super(AddressBookObject, self).remove()
+        yield super(AddressBookObject, self).reallyRemove() # FIXME: carddav trash?
         self._kind = None
         self._ownerAddressBookResourceID = None
         self._objectText = None

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -74,7 +74,7 @@
     ObjectResourceNameNotAllowedError, ObjectResourceNameAlreadyExistsError, \
     NoSuchObjectResourceError, AllRetriesFailed, InvalidSubscriptionValues, \
     InvalidIMIPTokenValues, TooManyObjectResourcesError, \
-    SyncTokenValidException
+    SyncTokenValidException, AlreadyInTrashError
 from txdav.common.idirectoryservice import IStoreDirectoryService, \
     DirectoryRecordNotFoundError
 from txdav.common.inotifications import INotificationCollection, \
@@ -5695,6 +5695,10 @@
             self._notifiers = None
 
 
+    def isTrash(self):
+        return False
+
+
     def memoMe(self, key, memo):
         """
         Add this object to the memo dictionary in whatever fashion is appropriate.
@@ -6846,18 +6850,28 @@
 
         rows = None
         if name:
+            if parent.isTrash():
+                # the name needs to be split
+                parentID, name = parent.parseName(name)
+            else:
+                parentID = parent._resourceID
+
             rows = yield cls._allColumnsWithParentAndName.on(
                 parent._txn,
                 name=name,
-                parentID=parent._resourceID
+                parentID=parentID
             )
         elif uid:
+            assert not parent.isTrash(), "UID lookup in Trash not supported"
+
             rows = yield cls._allColumnsWithParentAndUID.on(
                 parent._txn,
                 uid=uid,
                 parentID=parent._resourceID
             )
         elif resourceID:
+            assert not parent.isTrash(), "ID lookup in Trash not supported"
+
             rows = yield cls._allColumnsWithParentAndID.on(
                 parent._txn,
                 resourceID=resourceID,
@@ -7335,9 +7349,13 @@
         """
         Just moves the object to the trash
         """
-        yield self.toTrash()
 
+        if self._parentCollection.isTrash():
+            raise AlreadyInTrashError
+        else:
+            yield self.toTrash()
 
+
     @inlineCallbacks
     def reallyRemove(self, options=None):
         """
@@ -7380,7 +7398,12 @@
         trash = yield self._parentCollection._home.childWithName("trash")
         print("TO TRASH", trash)
         if trash is not None:
-            yield trash._insertRevision(self._name)
+            yield trash._insertRevision(
+                trash.nameForResource(
+                    self._parentCollection,
+                    self
+                )
+            )
 
 
     @inlineCallbacks
@@ -7392,7 +7415,12 @@
         trash = yield self._parentCollection._home.childWithName("trash")
         print("FROM TRASH", trash)
         if trash is not None:
-            yield trash._deleteRevision(self._name)
+            yield trash._deleteRevision(
+                trash.nameForResource(
+                    self._parentCollection,
+                    self
+                )
+            )
 
 
     @classproperty

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/util.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/util.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -445,6 +445,7 @@
                 else:
                     yield home.removeCalendarWithName("calendar")
                 yield home.removeCalendarWithName("inbox")
+                yield home.removeCalendarWithName("trash")
             except NoSuchHomeChildError:
                 pass
             for calendarName in calendars:

Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/icommondatastore.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/icommondatastore.py	2015-01-07 18:09:06 UTC (rev 14257)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/icommondatastore.py	2015-01-07 18:17:29 UTC (rev 14258)
@@ -38,6 +38,7 @@
     "ConcurrentModification",
     "InvalidObjectResourceError",
     "InternalDataStoreError",
+    "AlreadyInTrashError",
 ]
 
 #
@@ -235,6 +236,13 @@
     """
 
 
+class AlreadyInTrashError(CommonStoreError):
+    """
+    An object resource being removed is already in the trash.
+    """
+
+
+
 # Indexing / sync tokens
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150107/4eabed77/attachment-0001.html>


More information about the calendarserver-changes mailing list