[CalendarServer-changes] [14186] CalendarServer/branches/users/sagen/trashcan/txdav
source_changes at macosforge.org
source_changes at macosforge.org
Thu Nov 20 11:51:36 PST 2014
Revision: 14186
http://trac.calendarserver.org//changeset/14186
Author: sagen at apple.com
Date: 2014-11-20 11:51:36 -0800 (Thu, 20 Nov 2014)
Log Message:
-----------
First pass at the TrashCollection itself
Modified Paths:
--------------
CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py
CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py
CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql
CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/test_sql.py
Modified: CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py 2014-11-18 19:27:55 UTC (rev 14185)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/caldav/datastore/sql.py 2014-11-20 19:51:36 UTC (rev 14186)
@@ -675,7 +675,9 @@
inbox = yield self.createCalendarWithName("inbox")
yield inbox.setUsedForFreeBusy(False)
+ yield self.createTrash()
+
@inlineCallbacks
def splitCalendars(self):
"""
@@ -5645,10 +5647,62 @@
returnValue(location)
+
+class TrashCollection(Calendar):
+
+ _childType = "trash" # FIXME: make childType an enumeration
+
+
+ @classproperty
+ def _trashInHomeQuery(cls):
+ 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.IS_TRASH == True).And(
+ bind.HOME_RESOURCE_ID == Parameter("resourceID")
+ ).And(
+ bind.BIND_MODE == _BIND_MODE_OWN
+ )
+ )
+
+
+ @inlineCallbacks
+ def listObjectResources(self):
+ """
+ Return a list of names of child object resources in this trash; the
+ list is computed from all the homeChildren in the trash's parent home.
+ """
+ home = self._calendarHome
+
+ results = []
+ rows = (yield self._trashInHomeQuery.on(
+ self._txn, resourceID=home._resourceID
+ ))
+ if rows:
+ for childID, objectID in rows:
+ child = (yield home.childWithID(childID))
+ if child:
+ objectResource = (
+ yield child.objectResourceWithID(objectID)
+ )
+ results.append(objectResource.name())
+
+ 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
CalendarHome._childClass = Calendar
+CommonHome._trashClass = TrashCollection
Calendar._externalClass = CalendarExternal
Calendar._objectResourceClass = CalendarObject
CalendarObject._externalClass = CalendarObjectExternal
Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py 2014-11-18 19:27:55 UTC (rev 14185)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql.py 2014-11-20 19:51:36 UTC (rev 14186)
@@ -2991,6 +2991,7 @@
_homeMetaDataTable = None
_externalClass = None
_childClass = None
+ _trashClass = None
_childTable = None
_notifierPrefix = None
@@ -3442,7 +3443,11 @@
@param name: a string.
@return: an L{ICalendar} or C{None} if no such child exists.
"""
- return self._childClass.objectWithName(self, name)
+ # FIXME: should determine the class from the collection_type column
+ if name == "trash":
+ return self._trashClass.objectWithName(self, name)
+ else:
+ return self._childClass.objectWithName(self, name)
def anyObjectWithShareUID(self, shareUID):
@@ -3511,6 +3516,12 @@
self._children.pop(resourceID, None)
+ @inlineCallbacks
+ def createTrash(self):
+ child = yield self._trashClass.create(self, "trash")
+ returnValue(child)
+
+
@classproperty
def _syncTokenQuery(cls):
"""
@@ -5521,7 +5532,9 @@
_revisionsSchema = None
_objectSchema = None
+ _childType = None
+
@classmethod
@inlineCallbacks
def makeClass(cls, home, bindData, additionalBindData, metadataData, propstore=None, ownerHome=None):
@@ -5814,7 +5827,10 @@
"""
child = cls._homeChildSchema
return Insert(
- {child.RESOURCE_ID: schema.RESOURCE_ID_SEQ},
+ {
+ child.RESOURCE_ID: schema.RESOURCE_ID_SEQ,
+ child.COLLECTION_TYPE: Parameter("childType"),
+ },
Return=(child.RESOURCE_ID)
)
@@ -5825,8 +5841,12 @@
DAL statement to create a home child with all default values.
"""
child = cls._homeChildMetaDataSchema
- return Insert({child.RESOURCE_ID: Parameter("resourceID")},
- Return=(child.CREATED, child.MODIFIED))
+ return Insert(
+ {
+ child.RESOURCE_ID: Parameter("resourceID"),
+ },
+ Return=(child.CREATED, child.MODIFIED)
+ )
@classmethod
@@ -5840,7 +5860,7 @@
raise HomeChildNameNotAllowedError(name)
# Create this object
- resourceID = (yield cls._insertHomeChild.on(home._txn))[0][0]
+ resourceID = (yield cls._insertHomeChild.on(home._txn, childType=cls._childType))[0][0]
# Initialize this object
_created, _modified = (yield cls._insertHomeChildMetaData.on(home._txn, resourceID=resourceID))[0]
Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql 2014-11-18 19:27:55 UTC (rev 14185)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/sql_schema/current.sql 2014-11-20 19:51:36 UTC (rev 14186)
@@ -92,7 +92,8 @@
--------------
create table CALENDAR (
- RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ') -- implicit index
+ RESOURCE_ID integer primary key default nextval('RESOURCE_ID_SEQ'), -- implicit index
+ COLLECTION_TYPE varchar(10) default null -- None, inbox, trash (FIXME: convert this to enumeration)
);
Modified: CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/test_sql.py
===================================================================
--- CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/test_sql.py 2014-11-18 19:27:55 UTC (rev 14185)
+++ CalendarServer/branches/users/sagen/trashcan/txdav/common/datastore/test/test_sql.py 2014-11-20 19:51:36 UTC (rev 14186)
@@ -527,6 +527,7 @@
home = yield txn.calendarHomeWithUID("user01", create=True)
collection = yield home.childWithName("calendar")
+ trash = yield home.childWithName("trash")
# No objects
objects = yield collection.listObjectResources()
@@ -538,10 +539,14 @@
Component.allFromString(VCALENDAR_DATA_NO_SCHEDULING)
)
- # One object
+ # One object in collection
objects = yield collection.listObjectResources()
self.assertEquals(len(objects), 1)
+ # No objects in trash
+ objects = yield trash.listObjectResources()
+ self.assertEquals(len(objects), 0)
+
# Verify it's not in the trash
self.assertFalse((yield resource.isTrash()))
@@ -551,21 +556,29 @@
# Verify it's in the trash
self.assertTrue((yield resource.isTrash()))
- # No objects
+ # No objects in collection
objects = yield collection.listObjectResources()
self.assertEquals(len(objects), 0)
+ # One object in trash
+ objects = yield trash.listObjectResources()
+ self.assertEquals(len(objects), 1)
+
# Put back from trash
yield resource.fromTrash()
# Not in trash
self.assertFalse((yield resource.isTrash()))
- # One object
+ # One object in collection
objects = yield collection.listObjectResources()
self.assertEquals(len(objects), 1)
+ # No objects in trash
+ objects = yield trash.listObjectResources()
+ self.assertEquals(len(objects), 0)
+
#
# Now with addressbook
#
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20141120/1cf8b5b9/attachment.html>
More information about the calendarserver-changes
mailing list