[CalendarServer-changes] [14646] CalendarServer/trunk
source_changes at macosforge.org
source_changes at macosforge.org
Wed Apr 1 17:11:49 PDT 2015
Revision: 14646
http://trac.calendarserver.org//changeset/14646
Author: sagen at apple.com
Date: 2015-04-01 17:11:49 -0700 (Wed, 01 Apr 2015)
Log Message:
-----------
Don't expose trash collection as resource by default; fix sync report for deleted collections; fix home.calendars()
Modified Paths:
--------------
CalendarServer/trunk/twistedcaldav/stdconfig.py
CalendarServer/trunk/txdav/caldav/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/sql.py
CalendarServer/trunk/txdav/common/datastore/test/test_trash.py
Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/stdconfig.py 2015-04-01 21:31:16 UTC (rev 14645)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py 2015-04-02 00:11:49 UTC (rev 14646)
@@ -578,6 +578,7 @@
],
"EnableTrashCollection": False, # Enable Trash Collection
+ "ExposeTrashCollection": False, # Expose Trash Collection as a resource
"ParallelUpgrades": False, # Perform upgrades - currently only the
# database -> filesystem migration - but in
Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py 2015-04-01 21:31:16 UTC (rev 14645)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py 2015-04-02 00:11:49 UTC (rev 14646)
@@ -520,10 +520,9 @@
@inlineCallbacks
def calendars(self, onlyInTrash=False):
- if onlyInTrash:
- returnValue([c for c in (yield self.children()) if c.isTrash()])
- else:
- returnValue([c for c in (yield self.children()) if not c.isTrash()])
+ returnValue(
+ [c for c in (yield self.children(onlyInTrash=onlyInTrash))]
+ )
@inlineCallbacks
Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py 2015-04-01 21:31:16 UTC (rev 14645)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py 2015-04-02 00:11:49 UTC (rev 14646)
@@ -2204,6 +2204,9 @@
"""
results = (yield self._childClass.loadAllObjects(self))
for result in results:
+ if not config.ExposeTrashCollection:
+ if result.isTrash():
+ continue
key = self._childrenKey(result.isInTrash())
if result.name() not in self._children[key]:
self._children[key][result.name()] = result
@@ -2324,9 +2327,12 @@
@inlineCallbacks
def getTrash(self, create=False):
child = None
- if hasattr(self, "_trash"):
+ if hasattr(self, "_trashObject"):
+ child = self._trashObject
+ elif hasattr(self, "_trash"):
if self._trash:
- child = yield self.childWithID(self._trash)
+ child = yield self._childClass.objectWithID(self, self._trash)
+ self._trashObject = child
elif create:
schema = self._homeMetaDataSchema
@@ -2344,7 +2350,7 @@
Where=(schema.RESOURCE_ID == self.id()),
).on(self._txn))[0][0]
if self._trash:
- child = yield self.childWithID(self._trash)
+ child = yield self._childClass.objectWithID(self, self._trash)
else:
child = yield self._trashClass.create(self, str(uuid4()))
self._trash = child.id()
@@ -2353,6 +2359,7 @@
{schema.TRASH: self._trash},
Where=(schema.RESOURCE_ID == self.id())
).on(self._txn)
+ self._trashObject = child
returnValue(child)
@@ -3619,9 +3626,11 @@
yield self._updateIsInTrashQuery.on(
self._txn, isInTrash=True, trashed=whenTrashed, resourceID=self._resourceID
)
+ yield self._deletedSyncToken()
+
+ # Rename after calling _deletedSyncToken
newName = "{}-{}".format(self._name[:36], str(uuid4()))
yield self.rename(newName)
- yield self._deletedSyncToken()
# Update _children cache to reflect moving to trash
try:
Modified: CalendarServer/trunk/txdav/common/datastore/test/test_trash.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/test_trash.py 2015-04-01 21:31:16 UTC (rev 14645)
+++ CalendarServer/trunk/txdav/common/datastore/test/test_trash.py 2015-04-02 00:11:49 UTC (rev 14646)
@@ -2052,3 +2052,45 @@
result = yield txn.execSQL("select * from calendar_object", [])
self.assertEquals(len(result), 0)
yield txn.commit()
+
+
+ @inlineCallbacks
+ def test_trashedCalendars(self):
+
+ from twistedcaldav.stdconfig import config
+ self.patch(config, "EnableTrashCollection", True)
+
+ txn = self.store.newTransaction()
+ home = yield self._homeForUser(txn, "user01")
+ yield home.getTrash(create=True) # force loading trash
+ calendar = yield self._collectionForUser(txn, "user01", "calendar")
+ calendars = yield home.calendars(onlyInTrash=False)
+ self.assertEquals(
+ set([c.name() for c in calendars]),
+ set(["tasks", "inbox", "calendar"]) # trash not there
+ )
+ calendars = yield home.calendars(onlyInTrash=True)
+ self.assertEquals(
+ set([c.name() for c in calendars]),
+ set() # trash not there either
+ )
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ calendar = yield self._collectionForUser(txn, "user01", "calendar")
+ resourceID = calendar._resourceID
+ yield calendar.remove()
+ yield txn.commit()
+
+ txn = self.store.newTransaction()
+ home = yield self._homeForUser(txn, "user01")
+ yield home.getTrash(create=True) # force loading trash
+ calendars = yield home.calendars(onlyInTrash=False)
+ self.assertEquals(
+ set([c.name() for c in calendars]),
+ set(["tasks", "inbox"])
+ )
+ calendars = yield home.calendars(onlyInTrash=True)
+ self.assertEquals(len(calendars), 1)
+ self.assertEquals(calendars[0]._resourceID, resourceID)
+ yield txn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150401/c207f977/attachment.html>
More information about the calendarserver-changes
mailing list