[CalendarServer-changes] [9227] CalendarServer/trunk/txdav

source_changes at macosforge.org source_changes at macosforge.org
Fri May 4 09:10:15 PDT 2012


Revision: 9227
          http://trac.macosforge.org/projects/calendarserver/changeset/9227
Author:   glyph at apple.com
Date:     2012-05-04 09:10:15 -0700 (Fri, 04 May 2012)
Log Message:
-----------
unshare API and simple test

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/test/common.py
    CalendarServer/trunk/txdav/caldav/datastore/test/test_file.py
    CalendarServer/trunk/txdav/common/datastore/sql.py

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2012-05-04 03:11:05 UTC (rev 9226)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2012-05-04 16:10:15 UTC (rev 9227)
@@ -78,13 +78,13 @@
     "4.ics",
 ]
 
-
 home1_calendarNames = [
     "calendar_1",
     "calendar_2",
     "calendar_empty",
 ]
 
+OTHER_HOME_UID = "home_splits"
 
 test_event_text = (
     "BEGIN:VCALENDAR\r\n"
@@ -990,9 +990,9 @@
         L{ICalendar.shareWith} will share a calendar with a given home UID.
         """
         cal = yield self.calendarUnderTest()
-        OTHER_HOME_UID = "home_splits"
         other = yield self.homeUnderTest(name=OTHER_HOME_UID)
         newCalName = yield cal.shareWith(other, _BIND_MODE_WRITE)
+        self.sharedName = newCalName
         yield self.commit()
         normalCal = yield self.calendarUnderTest()
         otherHome = yield self.homeUnderTest(name=OTHER_HOME_UID)
@@ -1021,11 +1021,13 @@
         """
         yield self.test_shareWith()
         # yield self.commit() # txn is none? why?
-        OTHER_HOME_UID = "home_splits"
         cal = yield self.calendarUnderTest()
         other = yield self.homeUnderTest(name=OTHER_HOME_UID)
         newName = yield cal.shareWith(other, _BIND_MODE_READ)
-        otherCal = yield other.sharedChildWithName(newName)
+        otherCal = yield other.sharedChildWithName(self.sharedName)
+
+        # Name should not change just because we updated the mode.
+        self.assertEqual(newName, self.sharedName)
         self.assertNotIdentical(otherCal, None)
 
         # FIXME: permission information should be visible on the retrieved
@@ -1036,6 +1038,26 @@
 
 
     @inlineCallbacks
+    def test_unshareWith(self):
+        """
+        L{ICalendar.unshareWith} will remove a previously-shared calendar from
+        anotheruser's calendar home.
+        """
+        # XXX: ideally this would actually be using the shared calendar object
+        # from the shareee's home and just calling .unshare() on it.
+        yield self.test_shareWith()
+        cal = yield self.calendarUnderTest()
+        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
+        newName = yield cal.unshareWith(other)
+        otherCal = yield other.sharedChildWithName(newName)
+        self.assertIdentical(otherCal, None)
+        invites = yield cal.retrieveOldInvites().allRecords()
+        self.assertEqual(len(invites), 0)
+        shares = yield other.retrieveOldShares().allRecords()
+        self.assertEqual(len(shares), 0)
+
+
+    @inlineCallbacks
     def test_hasCalendarResourceUIDSomewhereElse(self):
         """
         L{ICalendarHome.hasCalendarResourceUIDSomewhereElse} will determine if

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_file.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_file.py	2012-05-04 03:11:05 UTC (rev 9226)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_file.py	2012-05-04 16:10:15 UTC (rev 9227)
@@ -472,6 +472,7 @@
 
     test_shareWith.skip = "Not implemented for file store yet."
     test_shareAgainChangesMode = test_shareWith
+    test_unshareWith = test_shareWith
 
 
     def test_init(self):

Modified: CalendarServer/trunk/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/sql.py	2012-05-04 03:11:05 UTC (rev 9226)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py	2012-05-04 16:10:15 UTC (rev 9227)
@@ -2028,6 +2028,31 @@
         returnValue(sharedName)
 
 
+    @inlineCallbacks
+    def unshareWith(self, shareeHome):
+        """
+        Remove the shared version of this (owned) L{CommonHomeChild} from the
+        referenced L{CommonHome}.
+
+        @see: L{CommonHomeChild.shareWith}
+
+        @param shareeHome: The home with which this L{CommonHomeChild} was
+            previously shared.
+
+        @return: a L{Deferred} which will fire with the previously-used name.
+        """
+        bind = self._bindSchema
+        resourceName = (yield Delete(
+            From=bind,
+            Where=(bind.RESOURCE_ID == Parameter("resourceID"))
+                  .And(bind.HOME_RESOURCE_ID == Parameter("homeID")),
+            Return=bind.RESOURCE_NAME,
+        ).on(self._txn, resourceID=self._resourceID,
+             homeID=shareeHome._resourceID))[0][0]
+        del shareeHome._sharedChildren[resourceName]
+        returnValue(resourceName)
+
+
     @classmethod
     @inlineCallbacks
     def loadAllObjects(cls, home, owned):
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20120504/e82ba9e1/attachment.html>


More information about the calendarserver-changes mailing list