<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13024] CalendarServer/branches/users/sagen/move2who-4</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13024">13024</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-03-28 10:59:00 -0700 (Fri, 28 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Fix purge tool and test</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolspurgepy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/purge.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4calendarservertoolstesttest_purgepy">CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_purge.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytestaccountsxml">CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml</a></li>
</ul>
<h3>Removed Paths</h3>
<ul>
<li>CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/purge/</li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolspurgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/purge.py (13023 => 13024)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -19,7 +19,6 @@
</span><span class="cx">
</span><span class="cx"> from calendarserver.tools import tables
</span><span class="cx"> from calendarserver.tools.cmdline import utilityMain, WorkerService
</span><del>-from calendarserver.tools.util import removeProxy
</del><span class="cx">
</span><span class="cx"> from getopt import getopt, GetoptError
</span><span class="cx">
</span><span class="lines">@@ -33,7 +32,6 @@
</span><span class="cx"> # from twistedcaldav.directory.directory import DirectoryRecord
</span><span class="cx">
</span><span class="cx"> from txdav.caldav.datastore.query.filter import Filter
</span><del>-from txdav.xml import element as davxml
</del><span class="cx">
</span><span class="cx">
</span><span class="cx"> import collections
</span><span class="lines">@@ -711,10 +709,8 @@
</span><span class="cx">
</span><span class="cx"> total = 0
</span><span class="cx">
</span><del>- allAssignments = {}
-
</del><span class="cx"> for uid in self.uids:
</span><del>- count, allAssignments[uid] = (yield self._purgeUID(uid))
</del><ins>+ count = (yield self._purgeUID(uid))
</ins><span class="cx"> total += count
</span><span class="cx">
</span><span class="cx"> if self.verbose:
</span><span class="lines">@@ -724,7 +720,7 @@
</span><span class="cx"> else:
</span><span class="cx"> print("Modified or deleted %s" % (amount,))
</span><span class="cx">
</span><del>- returnValue((total, allAssignments,))
</del><ins>+ returnValue(total)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -734,7 +730,7 @@
</span><span class="cx"> self.when = DateTime.getNowUTC()
</span><span class="cx">
</span><span class="cx"> # Does the record exist?
</span><del>- record = self.directory.recordWithUID(uid)
</del><ins>+ record = yield self.directory.recordWithUID(uid)
</ins><span class="cx"> # if record is None:
</span><span class="cx"> # The user has already been removed from the directory service. We
</span><span class="cx"> # need to fashion a temporary, fake record
</span><span class="lines">@@ -746,15 +742,11 @@
</span><span class="cx"> # self.directory._tmpRecords["uids"][uid] = record
</span><span class="cx">
</span><span class="cx"> # Override augments settings for this record
</span><del>- record.enabled = True
- record.enabledForCalendaring = True
- record.enabledForAddressBooks = True
</del><ins>+ record.hasCalendars = True
+ record.hasContacts = True
</ins><span class="cx">
</span><del>- cua = "urn:uuid:%s" % (uid,)
</del><ins>+ cua = record.canonicalCalendarUserAddress()
</ins><span class="cx">
</span><del>- principalCollection = self.directory.principalCollection
- principal = principalCollection.principalForRecord(record)
-
</del><span class="cx"> # See if calendar home is provisioned
</span><span class="cx"> txn = self.store.newTransaction()
</span><span class="cx"> storeCalHome = (yield txn.calendarHomeWithUID(uid))
</span><span class="lines">@@ -767,7 +759,6 @@
</span><span class="cx"> yield txn.commit()
</span><span class="cx">
</span><span class="cx"> count = 0
</span><del>- assignments = []
</del><span class="cx">
</span><span class="cx"> if calHomeProvisioned:
</span><span class="cx"> count = (yield self._cancelEvents(txn, uid, cua))
</span><span class="lines">@@ -782,9 +773,9 @@
</span><span class="cx"> if self.proxies and not self.dryrun:
</span><span class="cx"> if self.verbose:
</span><span class="cx"> print("Deleting any proxy assignments")
</span><del>- assignments = (yield self._purgeProxyAssignments(principal))
</del><ins>+ yield self._purgeProxyAssignments(self.store, record)
</ins><span class="cx">
</span><del>- returnValue((count, assignments))
</del><ins>+ returnValue(count)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -1107,22 +1098,10 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def _purgeProxyAssignments(self, principal):
</del><ins>+ def _purgeProxyAssignments(self, store, record):
</ins><span class="cx">
</span><del>- 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)
</del><ins>+ txn = store.newTransaction()
+ for readWrite in (True, False):
+ yield txn.removeDelegates(record.uid, readWrite)
+ yield txn.removeDelegateGroupss(record.uid, readWrite)
+ yield txn.commit()
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4calendarservertoolstesttest_purgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/calendarserver/tools/test/test_purge.py (13023 => 13024)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -17,7 +17,6 @@
</span><span class="cx">
</span><span class="cx"> from calendarserver.tools.purge import PurgePrincipalService
</span><span class="cx">
</span><del>-from twistedcaldav.config import config
</del><span class="cx"> from twistedcaldav.ical import Component
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><span class="cx">
</span><span class="lines">@@ -30,7 +29,6 @@
</span><span class="cx">
</span><span class="cx"> from txweb2.http_headers import MimeType
</span><span class="cx">
</span><del>-import os
</del><span class="cx">
</span><span class="cx">
</span><span class="cx"> future = DateTime.getNowUTC()
</span><span class="lines">@@ -770,7 +768,7 @@
</span><span class="cx"> DTSTART;TZID=US/Pacific:20100304T120000
</span><span class="cx"> DTSTAMP:20100303T195203Z
</span><span class="cx"> SEQUENCE:2
</span><del>-X-APPLE-DROPBOX:/calendars/__uids__/6423F94A-6B76-4A3A-815B-D52CFD77935D/dropbox/F2F14D94-B944-43D9-8F6F-97F95B2764CA.dropbox
</del><ins>+X-APPLE-DROPBOX:/calendars/__uids__/C76DB741-5A2A-4239-8112-10CF152AFCA4/dropbox/F2F14D94-B944-43D9-8F6F-97F95B2764CA.dropbox
</ins><span class="cx"> END:VEVENT
</span><span class="cx"> END:VCALENDAR
</span><span class="cx"> """.replace("\n", "\r\n")
</span><span class="lines">@@ -781,8 +779,8 @@
</span><span class="cx"> """
</span><span class="cx"> Tests for purging the data belonging to a given principal
</span><span class="cx"> """
</span><del>- uid = "6423F94A-6B76-4A3A-815B-D52CFD77935D"
- uid2 = "37DB0C90-4DB1-4932-BC69-3DAB66F374F5"
</del><ins>+ uid = "C76DB741-5A2A-4239-8112-10CF152AFCA4"
+ uid2 = "FFED7B62-2E08-496E-BD32-B2F95FFDDB6B"
</ins><span class="cx">
</span><span class="cx"> metadata = {
</span><span class="cx"> "accessMode": "PUBLIC",
</span><span class="lines">@@ -812,48 +810,35 @@
</span><span class="cx">
</span><span class="cx"> # Add attachment to attachment.ics
</span><span class="cx"> self._sqlCalendarStore._dropbox_ok = True
</span><del>- home = (yield txn.calendarHomeWithUID(self.uid))
- calendar = (yield home.calendarWithName("calendar1"))
- event = (yield calendar.calendarObjectWithName("attachment.ics"))
- attachment = (yield event.createAttachmentWithName("attachment.txt"))
</del><ins>+ home = yield txn.calendarHomeWithUID(self.uid)
+ calendar = yield home.calendarWithName("calendar1")
+ event = yield calendar.calendarObjectWithName("attachment.ics")
+ attachment = yield event.createAttachmentWithName("attachment.txt")
</ins><span class="cx"> t = attachment.store(MimeType("text", "x-fixture"))
</span><span class="cx"> t.write("attachment")
</span><span class="cx"> t.write(" text")
</span><del>- (yield t.loseConnection())
</del><ins>+ yield t.loseConnection()
</ins><span class="cx"> self._sqlCalendarStore._dropbox_ok = False
</span><span class="cx">
</span><span class="cx"> # Share calendars each way
</span><del>- 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))
</del><ins>+ 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)
</ins><span class="cx">
</span><del>- (yield txn.commit())
</del><ins>+ yield txn.commit()
</ins><span class="cx">
</span><span class="cx"> txn = self._sqlCalendarStore.newTransaction()
</span><del>- home = (yield txn.calendarHomeWithUID(self.uid))
- calendar2 = (yield home.childWithName(self.sharedName))
</del><ins>+ home = yield txn.calendarHomeWithUID(self.uid)
+ calendar2 = yield home.childWithName(self.sharedName)
</ins><span class="cx"> self.assertNotEquals(calendar2, None)
</span><del>- home2 = (yield txn.calendarHomeWithUID(self.uid2))
- calendar1 = (yield home2.childWithName(self.sharedName2))
</del><ins>+ home2 = yield txn.calendarHomeWithUID(self.uid2)
+ calendar1 = yield home2.childWithName(self.sharedName2)
</ins><span class="cx"> self.assertNotEquals(calendar1, None)
</span><del>- (yield txn.commit())
</del><ins>+ yield txn.commit()
</ins><span class="cx">
</span><span class="cx">
</span><del>- 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"
- )
- )
</del><span class="cx">
</span><del>-
</del><span class="cx"> @inlineCallbacks
</span><span class="cx"> def populate(self):
</span><span class="cx"> yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
</span><span class="lines">@@ -868,29 +853,43 @@
</span><span class="cx">
</span><span class="cx"> # Now you see it
</span><span class="cx"> txn = self._sqlCalendarStore.newTransaction()
</span><del>- home = (yield txn.calendarHomeWithUID(self.uid))
</del><ins>+ home = yield txn.calendarHomeWithUID(self.uid)
</ins><span class="cx"> self.assertNotEquals(home, None)
</span><del>- (yield txn.commit())
</del><ins>+ yield txn.commit()
</ins><span class="cx">
</span><del>- 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
</del><ins>+ count = yield PurgePrincipalService.purgeUIDs(
+ self.storeUnderTest(),
+ self.directory,
+ self.rootResource,
+ (self.uid,),
+ verbose=False,
+ proxies=False,
+ completely=True
+ )
+ self.assertEquals(count, 1) # 1 event
</ins><span class="cx">
</span><span class="cx"> # Now you don't
</span><span class="cx"> txn = self._sqlCalendarStore.newTransaction()
</span><del>- home = (yield txn.calendarHomeWithUID(self.uid))
</del><ins>+ home = yield txn.calendarHomeWithUID(self.uid)
</ins><span class="cx"> self.assertEquals(home, None)
</span><span class="cx"> # Verify calendar1 was unshared to uid2
</span><del>- home2 = (yield txn.calendarHomeWithUID(self.uid2))
</del><ins>+ home2 = yield txn.calendarHomeWithUID(self.uid2)
</ins><span class="cx"> self.assertEquals((yield home2.childWithName(self.sharedName)), None)
</span><del>- (yield txn.commit())
</del><ins>+ yield txn.commit()
</ins><span class="cx">
</span><del>- count, ignored = (yield PurgePrincipalService.purgeUIDs(self.storeUnderTest(), self.directory,
- self.rootResource, (self.uid,), verbose=False, proxies=False, completely=True))
</del><ins>+ count = yield PurgePrincipalService.purgeUIDs(
+ self.storeUnderTest(),
+ self.directory,
+ self.rootResource,
+ (self.uid,),
+ verbose=False,
+ proxies=False,
+ completely=True
+ )
</ins><span class="cx"> self.assertEquals(count, 0)
</span><span class="cx">
</span><span class="cx"> # And you still don't (making sure it's not provisioned)
</span><span class="cx"> txn = self._sqlCalendarStore.newTransaction()
</span><del>- home = (yield txn.calendarHomeWithUID(self.uid))
</del><ins>+ home = yield txn.calendarHomeWithUID(self.uid)
</ins><span class="cx"> self.assertEquals(home, None)
</span><del>- (yield txn.commit())
</del><ins>+ yield txn.commit()
</ins></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4twistedcaldavdirectorytestaccountsxml"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/twistedcaldav/directory/test/accounts.xml (13023 => 13024)</h4>
<pre class="diff"><span>
<span class="info">--- 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)
</span><span class="lines">@@ -63,7 +63,39 @@
</span><span class="cx"> <full-name>Double "quotey" Quotes</full-name>
</span><span class="cx"> <email>doublequotes@example.com</email>
</span><span class="cx"> </record>
</span><ins>+
</ins><span class="cx"> <record type="user">
</span><ins>+ <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@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@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@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@example.com</email>
+ </record>
+
+ <record type="user">
</ins><span class="cx"> <short-name>nocalendar</short-name>
</span><span class="cx"> <uid>543D28BA-F74F-4D5F-9243-B3E3A61171E5</uid>
</span><span class="cx"> <password>radnelacon</password>
</span><span class="lines">@@ -214,7 +246,6 @@
</span><span class="cx"> <full-name>Morgen Sagen</full-name>
</span><span class="cx"> <password>negas</password>
</span><span class="cx"> <email>sagen@bitbucket.calendarserver.org</email>
</span><del>- <email>shared@example.com</email>
</del><span class="cx"> </record>
</span><span class="cx">
</span><span class="cx"> <record type="user">
</span><span class="lines">@@ -231,7 +262,6 @@
</span><span class="cx"> <full-name>Andre LaBranche</full-name>
</span><span class="cx"> <password>erd</password>
</span><span class="cx"> <email>dre@bitbucket.calendarserver.org</email>
</span><del>- <email>shared@example.com</email>
</del><span class="cx"> </record>
</span><span class="cx">
</span><span class="cx"> <record type="group">
</span></span></pre>
</div>
</div>
</body>
</html>