[CalendarServer-changes] [5415] CalendarServer/branches/users/sagen/deprovision/calendarserver/tools

source_changes at macosforge.org source_changes at macosforge.org
Tue Mar 30 13:58:26 PDT 2010


Revision: 5415
          http://trac.macosforge.org/projects/calendarserver/changeset/5415
Author:   sagen at apple.com
Date:     2010-03-30 13:58:26 -0700 (Tue, 30 Mar 2010)
Log Message:
-----------
purgeGUID( ) now clears out proxy assignments, and generates a gzip'd tarball of the deprovisioned user's calendars plus a list of the proxy assignments that were removed.

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/purge.py
    CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/test/test_purge.py

Modified: CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/purge.py	2010-03-30 18:31:28 UTC (rev 5414)
+++ CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/purge.py	2010-03-30 20:58:26 UTC (rev 5415)
@@ -16,6 +16,7 @@
 # limitations under the License.
 ##
 
+from cStringIO import StringIO
 from calendarserver.tap.util import FakeRequest
 from calendarserver.tap.util import getRootResource
 from calendarserver.tools.principals import removeProxy
@@ -36,6 +37,7 @@
 from twistedcaldav.method.delete_common import DeleteResource
 import os
 import sys
+import tarfile
 
 log = Logger()
 
@@ -259,14 +261,16 @@
 
 
 @inlineCallbacks
-def purgeGUID(guid, directory, root):
+def purgeGUID(guid, directory, root, tarPath=None):
 
     # Does the record exist?
     record = directory.recordWithGUID(guid)
     if record is None:
         # The user has already been removed from the directory service.  We
         # need to fashion a temporary, fake record
-        # FIXME: implement the fake record
+
+        # FIXME: probaby want a more elegant way to accomplish this,
+        # since it requires the aggregate directory to examine these first:
         record = DirectoryRecord(directory, "users", guid, shortNames=(guid,),
             enabledForCalendaring=True)
         record.enabled = True
@@ -277,6 +281,11 @@
     principal = principalCollection.principalForRecord(record)
     calendarHome = principal.calendarHome()
 
+    if tarPath:
+        tarFile = tarfile.open(tarPath, mode="w:gz")
+    else:
+        tarFile = None
+
     # Anything in the past should be deleted without implicit scheduling
     now = datetime.utcnow().strftime("%Y%m%dT%H%M%SZ")
     filter =  caldavxml.Filter(
@@ -308,6 +317,13 @@
 
             for name in allEvents:
                 resource = collection.getChild(name)
+
+                if tarFile:
+                    data = resource.iCalendarText()
+                    tarInfo = tarfile.TarInfo(name="%s/%s" % (collName, name))
+                    tarInfo.size = len(data)
+                    tarFile.addfile(tarInfo, fileobj=StringIO(data))
+
                 uri = "/calendars/__uids__/%s/%s/%s" % (
                     record.uid,
                     collName,
@@ -318,15 +334,39 @@
                     uri, guid, implicit=(name in ongoingEvents)))
                 count += 1
 
-    # Remove proxy assignments
+    assignments = (yield purgeProxyAssignments(principal))
+
+    if tarFile:
+        tarInfo = tarfile.TarInfo(name="ProxyAssignments")
+        tarInfo.size = len(assignments)
+        tarFile.addfile(tarInfo, fileobj=StringIO(assignments))
+        tarFile.close()
+
+    returnValue(count)
+
+
+ at inlineCallbacks
+def purgeProxyAssignments(principal):
+
+    assignments = []
+
     for proxyType in ("read", "write"):
 
-        proxyFor = (yield principal.proxyFor(proxyType))
+        proxyFor = (yield principal.proxyFor(proxyType == "write"))
         for other in proxyFor:
+            assignments.append("%s\t%s\t%s\n" %
+                (principal.record.guid, proxyType, other.record.guid))
             (yield removeProxy(other, principal))
 
         subPrincipal = principal.getChild("calendar-proxy-" + proxyType)
+        proxies = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
+        for other in proxies.children:
+            assignments.append("%s\t%s\t%s\n" %
+                (str(other).split("/")[3], proxyType, principal.record.guid))
+
         (yield subPrincipal.writeProperty(davxml.GroupMemberSet(), None))
 
-    returnValue(count)
+    assignments = "".join(assignments)
+    returnValue(assignments)
 
+

Modified: CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/test/test_purge.py
===================================================================
--- CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/test/test_purge.py	2010-03-30 18:31:28 UTC (rev 5414)
+++ CalendarServer/branches/users/sagen/deprovision/calendarserver/tools/test/test_purge.py	2010-03-30 20:58:26 UTC (rev 5415)
@@ -16,7 +16,7 @@
 
 from calendarserver.tap.util import getRootResource
 from calendarserver.tools.principals import addProxy, removeProxy
-from calendarserver.tools.purge import purgeOldEvents, purgeGUID
+from calendarserver.tools.purge import purgeOldEvents, purgeGUID, purgeProxyAssignments
 from datetime import datetime, timedelta
 from twext.python.filepath import CachingFilePath as FilePath
 from twext.python.plistlib import readPlistFromString
@@ -431,31 +431,36 @@
         keeping = "291C2C29-B663-4342-8EA1-A055E6A04D65"
         keepingPrincipal = pc.principalForUID(keeping)
 
+        def getProxies(principal, proxyType):
+            subPrincipal = principal.getChild("calendar-proxy-" + proxyType)
+            return subPrincipal.readProperty(davxml.GroupMemberSet, None)
+
         # Add purgingPrincipal as a proxy for keepingPrincipal
         (yield addProxy(keepingPrincipal, "write", purgingPrincipal))
 
         # Add keepingPrincipal as a proxy for purgingPrincipal
         (yield addProxy(purgingPrincipal, "write", keepingPrincipal))
 
-        def getProxies(principal, proxyType):
-            subPrincipal = principal.getChild("calendar-proxy-" + proxyType)
-            return subPrincipal.readProperty(davxml.GroupMemberSet, None)
-
         # Verify the proxy assignments
         membersProperty = (yield getProxies(keepingPrincipal, "write"))
         self.assertEquals(len(membersProperty.children), 1)
         self.assertEquals(membersProperty.children[0],
             "/principals/__uids__/5D6ABA3C-3446-4340-8083-7E37C5BC0B26/")
+        membersProperty = (yield getProxies(keepingPrincipal, "read"))
+        self.assertEquals(len(membersProperty.children), 0)
 
         membersProperty = (yield getProxies(purgingPrincipal, "write"))
         self.assertEquals(len(membersProperty.children), 1)
         self.assertEquals(membersProperty.children[0],
             "/principals/__uids__/291C2C29-B663-4342-8EA1-A055E6A04D65/")
+        membersProperty = (yield getProxies(purgingPrincipal, "read"))
+        self.assertEquals(len(membersProperty.children), 0)
 
-
         # Purging the guid should clear out proxy assignments
 
-        (yield purgeGUID(purging, self.directory, self.rootResource))
+        assignments = (yield purgeProxyAssignments(purgingPrincipal))
+        self.assertTrue("5D6ABA3C-3446-4340-8083-7E37C5BC0B26\twrite\t291C2C29-B663-4342-8EA1-A055E6A04D65" in assignments)
+        self.assertTrue("291C2C29-B663-4342-8EA1-A055E6A04D65\twrite\t5D6ABA3C-3446-4340-8083-7E37C5BC0B26" in assignments)
 
         membersProperty = (yield getProxies(keepingPrincipal, "write"))
         self.assertEquals(len(membersProperty.children), 0)
@@ -514,12 +519,16 @@
             },
         }
         self.createHierarchy(before, config.DocumentRoot)
+        tarPath = os.path.join(config.DocumentRoot, "calendars", "tarball.tgz")
         count = (yield purgeGUID("E9E78C86-4829-4520-A35D-70DDADAB2092",
-            self.directory, self.rootResource))
+            self.directory, self.rootResource, tarPath=tarPath))
 
         self.assertEquals(count, 3)
 
         after = {
+            "tarball.tgz" : {
+                "@contents" : None, # ignore contents
+            },
             "__uids__" : {
                 "E9" : {
                     "E7" : {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20100330/f269f4e0/attachment.html>


More information about the calendarserver-changes mailing list