[CalendarServer-changes] [13024] CalendarServer/branches/users/sagen/move2who-4

source_changes at macosforge.org source_changes at macosforge.org
Fri Mar 28 10:59:00 PDT 2014


Revision: 13024
          http://trac.calendarserver.org//changeset/13024
Author:   sagen at apple.com
Date:     2014-03-28 10:59:00 -0700 (Fri, 28 Mar 2014)
Log Message:
-----------
Fix purge tool and test

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/purge.py
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_purge.py
    CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml

Removed Paths:
-------------
    CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/purge/

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/purge.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/purge.py	2014-03-28 17:33:42 UTC (rev 13023)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/purge.py	2014-03-28 17:59:00 UTC (rev 13024)
@@ -19,7 +19,6 @@
 
 from calendarserver.tools import tables
 from calendarserver.tools.cmdline import utilityMain, WorkerService
-from calendarserver.tools.util import removeProxy
 
 from getopt import getopt, GetoptError
 
@@ -33,7 +32,6 @@
 # from twistedcaldav.directory.directory import DirectoryRecord
 
 from txdav.caldav.datastore.query.filter import Filter
-from txdav.xml import element as davxml
 
 
 import collections
@@ -711,10 +709,8 @@
 
         total = 0
 
-        allAssignments = {}
-
         for uid in self.uids:
-            count, allAssignments[uid] = (yield self._purgeUID(uid))
+            count = (yield self._purgeUID(uid))
             total += count
 
         if self.verbose:
@@ -724,7 +720,7 @@
             else:
                 print("Modified or deleted %s" % (amount,))
 
-        returnValue((total, allAssignments,))
+        returnValue(total)
 
 
     @inlineCallbacks
@@ -734,7 +730,7 @@
             self.when = DateTime.getNowUTC()
 
         # Does the record exist?
-        record = self.directory.recordWithUID(uid)
+        record = yield self.directory.recordWithUID(uid)
         # if record is None:
             # The user has already been removed from the directory service.  We
             # need to fashion a temporary, fake record
@@ -746,15 +742,11 @@
             # self.directory._tmpRecords["uids"][uid] = record
 
         # Override augments settings for this record
-        record.enabled = True
-        record.enabledForCalendaring = True
-        record.enabledForAddressBooks = True
+        record.hasCalendars = True
+        record.hasContacts = True
 
-        cua = "urn:uuid:%s" % (uid,)
+        cua = record.canonicalCalendarUserAddress()
 
-        principalCollection = self.directory.principalCollection
-        principal = principalCollection.principalForRecord(record)
-
         # See if calendar home is provisioned
         txn = self.store.newTransaction()
         storeCalHome = (yield txn.calendarHomeWithUID(uid))
@@ -767,7 +759,6 @@
         yield txn.commit()
 
         count = 0
-        assignments = []
 
         if calHomeProvisioned:
             count = (yield self._cancelEvents(txn, uid, cua))
@@ -782,9 +773,9 @@
         if self.proxies and not self.dryrun:
             if self.verbose:
                 print("Deleting any proxy assignments")
-            assignments = (yield self._purgeProxyAssignments(principal))
+            yield self._purgeProxyAssignments(self.store, record)
 
-        returnValue((count, assignments))
+        returnValue(count)
 
 
     @inlineCallbacks
@@ -1107,22 +1098,10 @@
 
 
     @inlineCallbacks
-    def _purgeProxyAssignments(self, principal):
+    def _purgeProxyAssignments(self, store, record):
 
-        assignments = []
-
-        for proxyType in ("read", "write"):
-
-            proxyFor = (yield principal.proxyFor(proxyType == "write"))
-            for other in proxyFor:
-                assignments.append((principal.record.uid, proxyType, other.record.uid))
-                (yield removeProxy(self.root, self.directory, self.store, other, principal))
-
-            subPrincipal = principal.getChild("calendar-proxy-" + proxyType)
-            proxies = (yield subPrincipal.readProperty(davxml.GroupMemberSet, None))
-            for other in proxies.children:
-                assignments.append((str(other).split("/")[3], proxyType, principal.record.uid))
-
-            (yield subPrincipal.writeProperty(davxml.GroupMemberSet(), None))
-
-        returnValue(assignments)
+        txn = store.newTransaction()
+        for readWrite in (True, False):
+            yield txn.removeDelegates(record.uid, readWrite)
+            yield txn.removeDelegateGroupss(record.uid, readWrite)
+        yield txn.commit()

Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_purge.py
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_purge.py	2014-03-28 17:33:42 UTC (rev 13023)
+++ CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_purge.py	2014-03-28 17:59:00 UTC (rev 13024)
@@ -17,7 +17,6 @@
 
 from calendarserver.tools.purge import PurgePrincipalService
 
-from twistedcaldav.config import config
 from twistedcaldav.ical import Component
 from twistedcaldav.test.util import StoreTestCase
 
@@ -30,7 +29,6 @@
 
 from txweb2.http_headers import MimeType
 
-import os
 
 
 future = DateTime.getNowUTC()
@@ -770,7 +768,7 @@
 DTSTART;TZID=US/Pacific:20100304T120000
 DTSTAMP:20100303T195203Z
 SEQUENCE:2
-X-APPLE-DROPBOX:/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/dropbox/F2F14D94-B944-43D9-8F6F-97F95B2764CA.dropbox
+X-APPLE-DROPBOX:/calendars/__uids__/C76DB741-5A2A-4239-8112-10CF152AFCA4/dropbox/F2F14D94-B944-43D9-8F6F-97F95B2764CA.dropbox
 END:VEVENT
 END:VCALENDAR
 """.replace("\n", "\r\n")
@@ -781,8 +779,8 @@
     """
     Tests for purging the data belonging to a given principal
     """
-    uid = "6423F94A-6B76-4A3A-815B-D52CFD77935D"
-    uid2 = "37DB0C90-4DB1-4932-BC69-3DAB66F374F5"
+    uid = "C76DB741-5A2A-4239-8112-10CF152AFCA4"
+    uid2 = "FFED7B62-2E08-496E-BD32-B2F95FFDDB6B"
 
     metadata = {
         "accessMode": "PUBLIC",
@@ -812,48 +810,35 @@
 
         # Add attachment to attachment.ics
         self._sqlCalendarStore._dropbox_ok = True
-        home = (yield txn.calendarHomeWithUID(self.uid))
-        calendar = (yield home.calendarWithName("calendar1"))
-        event = (yield calendar.calendarObjectWithName("attachment.ics"))
-        attachment = (yield event.createAttachmentWithName("attachment.txt"))
+        home = yield txn.calendarHomeWithUID(self.uid)
+        calendar = yield home.calendarWithName("calendar1")
+        event = yield calendar.calendarObjectWithName("attachment.ics")
+        attachment = yield event.createAttachmentWithName("attachment.txt")
         t = attachment.store(MimeType("text", "x-fixture"))
         t.write("attachment")
         t.write(" text")
-        (yield t.loseConnection())
+        yield t.loseConnection()
         self._sqlCalendarStore._dropbox_ok = False
 
         # Share calendars each way
-        home2 = (yield txn.calendarHomeWithUID(self.uid2))
-        calendar2 = (yield home2.calendarWithName("calendar2"))
-        self.sharedName = (yield calendar2.shareWith(home, _BIND_MODE_WRITE))
-        self.sharedName2 = (yield calendar.shareWith(home2, _BIND_MODE_WRITE))
+        home2 = yield txn.calendarHomeWithUID(self.uid2)
+        calendar2 = yield home2.calendarWithName("calendar2")
+        self.sharedName = yield calendar2.shareWith(home, _BIND_MODE_WRITE)
+        self.sharedName2 = yield calendar.shareWith(home2, _BIND_MODE_WRITE)
 
-        (yield txn.commit())
+        yield txn.commit()
 
         txn = self._sqlCalendarStore.newTransaction()
-        home = (yield txn.calendarHomeWithUID(self.uid))
-        calendar2 = (yield home.childWithName(self.sharedName))
+        home = yield txn.calendarHomeWithUID(self.uid)
+        calendar2 = yield home.childWithName(self.sharedName)
         self.assertNotEquals(calendar2, None)
-        home2 = (yield txn.calendarHomeWithUID(self.uid2))
-        calendar1 = (yield home2.childWithName(self.sharedName2))
+        home2 = yield txn.calendarHomeWithUID(self.uid2)
+        calendar1 = yield home2.childWithName(self.sharedName2)
         self.assertNotEquals(calendar1, None)
-        (yield txn.commit())
+        yield txn.commit()
 
 
-    def configure(self):
-        super(PurgePrincipalTests, self).configure()
-        self.patch(config.DirectoryService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "accounts.xml"
-            )
-        )
-        self.patch(config.ResourceService.params, "xmlFile",
-            os.path.join(
-                os.path.dirname(__file__), "purge", "resources.xml"
-            )
-        )
 
-
     @inlineCallbacks
     def populate(self):
         yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
@@ -868,29 +853,43 @@
 
         # Now you see it
         txn = self._sqlCalendarStore.newTransaction()
-        home = (yield txn.calendarHomeWithUID(self.uid))
+        home = yield txn.calendarHomeWithUID(self.uid)
         self.assertNotEquals(home, None)
-        (yield txn.commit())
+        yield txn.commit()
 
-        count, ignored = (yield PurgePrincipalService.purgeUIDs(self.storeUnderTest(), self.directory,
-            self.rootResource, (self.uid,), verbose=False, proxies=False, completely=True))
-        self.assertEquals(count, 1) # 1 event
+        count = yield PurgePrincipalService.purgeUIDs(
+            self.storeUnderTest(),
+            self.directory,
+            self.rootResource,
+            (self.uid,),
+            verbose=False,
+            proxies=False,
+            completely=True
+        )
+        self.assertEquals(count, 1)  # 1 event
 
         # Now you don't
         txn = self._sqlCalendarStore.newTransaction()
-        home = (yield txn.calendarHomeWithUID(self.uid))
+        home = yield txn.calendarHomeWithUID(self.uid)
         self.assertEquals(home, None)
         # Verify calendar1 was unshared to uid2
-        home2 = (yield txn.calendarHomeWithUID(self.uid2))
+        home2 = yield txn.calendarHomeWithUID(self.uid2)
         self.assertEquals((yield home2.childWithName(self.sharedName)), None)
-        (yield txn.commit())
+        yield txn.commit()
 
-        count, ignored = (yield PurgePrincipalService.purgeUIDs(self.storeUnderTest(), self.directory,
-            self.rootResource, (self.uid,), verbose=False, proxies=False, completely=True))
+        count = yield PurgePrincipalService.purgeUIDs(
+            self.storeUnderTest(),
+            self.directory,
+            self.rootResource,
+            (self.uid,),
+            verbose=False,
+            proxies=False,
+            completely=True
+        )
         self.assertEquals(count, 0)
 
         # And you still don't (making sure it's not provisioned)
         txn = self._sqlCalendarStore.newTransaction()
-        home = (yield txn.calendarHomeWithUID(self.uid))
+        home = yield txn.calendarHomeWithUID(self.uid)
         self.assertEquals(home, None)
-        (yield txn.commit())
+        yield txn.commit()

Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml
===================================================================
--- CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml	2014-03-28 17:33:42 UTC (rev 13023)
+++ CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml	2014-03-28 17:59:00 UTC (rev 13024)
@@ -63,7 +63,39 @@
     <full-name>Double "quotey" Quotes</full-name>
     <email>doublequotes at example.com</email>
   </record>
+
   <record type="user">
+    <short-name>example</short-name>
+    <uid>C76DB741-5A2A-4239-8112-10CF152AFCA4</uid>
+    <guid>C76DB741-5A2A-4239-8112-10CF152AFCA4</guid>
+    <password>example</password>
+    <full-name>Example</full-name>
+    <email>example at example.com</email>
+  </record>
+  <record type="user">
+    <short-name>example2</short-name>
+    <uid>FFED7B62-2E08-496E-BD32-B2F95FFDDB6B</uid>
+    <guid>FFED7B62-2E08-496E-BD32-B2F95FFDDB6B</guid>
+    <password>example2</password>
+    <full-name>Example Two</full-name>
+    <email>example2 at example.com</email>
+  </record>
+  <record type="user">
+    <short-name>home1</short-name>
+    <uid>home1</uid>
+    <password>home1</password>
+    <full-name>Home One</full-name>
+    <email>home1 at example.com</email>
+  </record>
+  <record type="user">
+    <short-name>home2</short-name>
+    <uid>home2</uid>
+    <password>home2</password>
+    <full-name>Home Two</full-name>
+    <email>home2 at example.com</email>
+  </record>
+
+  <record type="user">
     <short-name>nocalendar</short-name>
     <uid>543D28BA-F74F-4D5F-9243-B3E3A61171E5</uid>
     <password>radnelacon</password>
@@ -214,7 +246,6 @@
     <full-name>Morgen Sagen</full-name>
     <password>negas</password>
     <email>sagen at bitbucket.calendarserver.org</email>
-    <email>shared at example.com</email>
   </record>
 
   <record type="user">
@@ -231,7 +262,6 @@
     <full-name>Andre LaBranche</full-name>
     <password>erd</password>
     <email>dre at bitbucket.calendarserver.org</email>
-    <email>shared at example.com</email>
   </record>
 
   <record type="group">
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140328/396dc920/attachment-0001.html>


More information about the calendarserver-changes mailing list