<!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>[13144] CalendarServer/branches/release/CalendarServer-5.2-dev</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/13144">13144</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2014-04-03 10:59:12 -0700 (Thu, 03 Apr 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix principal purge where a private event needs to be cancelled.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesreleaseCalendarServer52devcalendarservertoolspurgepy">CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/purge.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer52devcalendarservertoolstesttest_purgepy">CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/test/test_purge.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer52devtxdavcaldavdatastoreschedulingfreebusypy">CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/scheduling/freebusy.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer52devtxdavcaldavdatastoresqlpy">CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesreleaseCalendarServer52devtxdavcommondatastoresqlpy">CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesreleaseCalendarServer52devcalendarservertoolspurgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/purge.py (13143 => 13144)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/purge.py        2014-04-03 17:50:55 UTC (rev 13143)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/purge.py        2014-04-03 17:59:12 UTC (rev 13144)
</span><span class="lines">@@ -833,7 +833,7 @@
</span><span class="cx"> 
</span><span class="cx">         for calendarName in calendarNames:
</span><span class="cx"> 
</span><del>-            txn = self.store.newTransaction()
</del><ins>+            txn = self.store.newTransaction(authz_uid=uid)
</ins><span class="cx">             storeCalHome = (yield txn.calendarHomeWithUID(uid))
</span><span class="cx">             calendar = (yield storeCalHome.calendarWithName(calendarName))
</span><span class="cx">             childNames = []
</span><span class="lines">@@ -850,7 +850,7 @@
</span><span class="cx"> 
</span><span class="cx">             for childName in childNames:
</span><span class="cx"> 
</span><del>-                txn = self.store.newTransaction()
</del><ins>+                txn = self.store.newTransaction(authz_uid=uid)
</ins><span class="cx">                 storeCalHome = (yield txn.calendarHomeWithUID(uid))
</span><span class="cx">                 calendar = (yield storeCalHome.calendarWithName(calendarName))
</span><span class="cx"> 
</span><span class="lines">@@ -918,7 +918,7 @@
</span><span class="cx">     def _removeCalendarHome(self, uid):
</span><span class="cx"> 
</span><span class="cx">         try:
</span><del>-            txn = self.store.newTransaction()
</del><ins>+            txn = self.store.newTransaction(authz_uid=uid)
</ins><span class="cx"> 
</span><span class="cx">             # Remove empty calendar collections (and calendar home if no more
</span><span class="cx">             # calendars)
</span><span class="lines">@@ -936,7 +936,10 @@
</span><span class="cx">                             else:
</span><span class="cx">                                 print(&quot;Deleting calendar: %s&quot; % (calendarName,))
</span><span class="cx">                         if not self.dryrun:
</span><del>-                            (yield storeCalHome.removeChildWithName(calendarName))
</del><ins>+                            if calColl.owned():
+                                yield storeCalHome.removeChildWithName(calendarName)
+                            else:
+                                yield calColl.unshare()
</ins><span class="cx"> 
</span><span class="cx">                 if not remainingCalendars:
</span><span class="cx">                     if self.verbose:
</span><span class="lines">@@ -960,7 +963,7 @@
</span><span class="cx">     def _removeAddressbookHome(self, uid):
</span><span class="cx"> 
</span><span class="cx">         count = 0
</span><del>-        txn = self.store.newTransaction()
</del><ins>+        txn = self.store.newTransaction(authz_uid=uid)
</ins><span class="cx"> 
</span><span class="cx">         try:
</span><span class="cx">             # Remove VCards
</span><span class="lines">@@ -978,15 +981,18 @@
</span><span class="cx">                         if not self.dryrun:
</span><span class="cx">                             (yield card.remove())
</span><span class="cx">                         count += 1
</span><ins>+                    abName = abColl.name()
</ins><span class="cx">                     if self.verbose:
</span><del>-                        abName = abColl.name()
</del><span class="cx">                         if self.dryrun:
</span><span class="cx">                             print(&quot;Would delete addressbook: %s&quot; % (abName,))
</span><span class="cx">                         else:
</span><span class="cx">                             print(&quot;Deleting addressbook: %s&quot; % (abName,))
</span><span class="cx">                     if not self.dryrun:
</span><span class="cx">                         # Also remove the addressbook collection itself
</span><del>-                        (yield storeAbHome.removeChildWithName(abColl.name()))
</del><ins>+                        if abColl.owned():
+                            yield storeAbHome.removeChildWithName(abName)
+                        else:
+                            yield abColl.unshare()
</ins><span class="cx"> 
</span><span class="cx">                 if self.verbose:
</span><span class="cx">                     if self.dryrun:
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer52devcalendarservertoolstesttest_purgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/test/test_purge.py (13143 => 13144)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/test/test_purge.py        2014-04-03 17:50:55 UTC (rev 13143)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/calendarserver/tools/test/test_purge.py        2014-04-03 17:59:12 UTC (rev 13144)
</span><span class="lines">@@ -776,7 +776,27 @@
</span><span class="cx"> &quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+# Purging non-existent organizer; has existing attendee; repeating
+REPEATING_PUBLIC_EVENT_ORGANIZER_ICS = &quot;&quot;&quot;BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//Apple Inc.//iCal 4.0.1//EN
+X-CALENDARSERVER-ACCESS:PRIVATE
+BEGIN:VEVENT
+UID:8ED97931-9A19-4596-9D4D-52B36D6AB803
+SUMMARY:Repeating Organizer
+DTSTART:%s
+DURATION:PT1H
+RRULE:FREQ=DAILY;COUNT=400
+ORGANIZER:urn:uuid:6423F94A-6B76-4A3A-815B-D52CFD77935D
+ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:urn:uuid:6423F94A-6B76-4A3A-815B-D52CFD77935D
+ATTENDEE;CUTYPE=INDIVIDUAL;PARTSTAT=ACCEPTED:urn:uuid:291C2C29-B663-4342-8EA1-A055E6A04D65
+DTSTAMP:20100303T195203Z
+END:VEVENT
+END:VCALENDAR
+&quot;&quot;&quot;.replace(&quot;\n&quot;, &quot;\r\n&quot;) % (past,)
</ins><span class="cx"> 
</span><ins>+
+
</ins><span class="cx"> class PurgePrincipalTests(StoreTestCase):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Tests for purging the data belonging to a given principal
</span><span class="lines">@@ -796,6 +816,7 @@
</span><span class="cx">         uid : {
</span><span class="cx">             &quot;calendar1&quot; : {
</span><span class="cx">                 &quot;attachment.ics&quot; : (ATTACHMENT_ICS, metadata,),
</span><ins>+                &quot;organizer.ics&quot; : (REPEATING_PUBLIC_EVENT_ORGANIZER_ICS, metadata,),
</ins><span class="cx">             }
</span><span class="cx">         },
</span><span class="cx">         uid2 : {
</span><span class="lines">@@ -870,7 +891,7 @@
</span><span class="cx"> 
</span><span class="cx">         count, ignored = (yield PurgePrincipalService.purgeUIDs(self.storeUnderTest(), self.directory,
</span><span class="cx">             self.rootResource, (self.uid,), verbose=False, proxies=False, completely=True))
</span><del>-        self.assertEquals(count, 1) # 1 event
</del><ins>+        self.assertEquals(count, 2) # 2 events
</ins><span class="cx"> 
</span><span class="cx">         # Now you don't
</span><span class="cx">         txn = self._sqlCalendarStore.newTransaction()
</span><span class="lines">@@ -890,3 +911,41 @@
</span><span class="cx">         home = (yield txn.calendarHomeWithUID(self.uid))
</span><span class="cx">         self.assertEquals(home, None)
</span><span class="cx">         (yield txn.commit())
</span><ins>+
+
+    @inlineCallbacks
+    def test_purgeUIDsNotCompletely(self):
+        &quot;&quot;&quot;
+        Verify purgeUIDs removes some events, but leaves others and the home behind
+        &quot;&quot;&quot;
+
+        self.patch(config, &quot;EnablePrivateEvents&quot;, True)
+
+        # Now you see it
+        txn = self._sqlCalendarStore.newTransaction()
+        home = (yield txn.calendarHomeWithUID(self.uid))
+        self.assertNotEquals(home, None)
+        (yield txn.commit())
+
+        count, ignored = (yield PurgePrincipalService.purgeUIDs(self.storeUnderTest(), self.directory,
+            self.rootResource, (self.uid,), verbose=False, proxies=False, completely=False))
+        self.assertEquals(count, 1) # 2 events
+
+        # Now you still see it
+        txn = self._sqlCalendarStore.newTransaction()
+        home = (yield txn.calendarHomeWithUID(self.uid))
+        self.assertNotEquals(home, None)
+        # Verify calendar1 was unshared to uid2
+        home2 = (yield txn.calendarHomeWithUID(self.uid2))
+        self.assertEquals((yield home2.childWithName(self.sharedName)), None)
+        (yield txn.commit())
+
+        count, ignored = (yield PurgePrincipalService.purgeUIDs(self.storeUnderTest(), self.directory,
+            self.rootResource, (self.uid,), verbose=False, proxies=False, completely=False))
+        self.assertEquals(count, 1)
+
+        # And you still do
+        txn = self._sqlCalendarStore.newTransaction()
+        home = (yield txn.calendarHomeWithUID(self.uid))
+        self.assertNotEquals(home, None)
+        (yield txn.commit())
</ins></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer52devtxdavcaldavdatastoreschedulingfreebusypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/scheduling/freebusy.py (13143 => 13144)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/scheduling/freebusy.py        2014-04-03 17:50:55 UTC (rev 13143)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/scheduling/freebusy.py        2014-04-03 17:59:12 UTC (rev 13144)
</span><span class="lines">@@ -155,7 +155,7 @@
</span><span class="cx">         # the organizer is making the request
</span><span class="cx">         authz_uid = organizer_uid
</span><span class="cx">         authz_record = organizer_record
</span><del>-        if hasattr(calresource._txn, &quot;_authz_uid&quot;) and calresource._txn._authz_uid != organizer_uid:
</del><ins>+        if calresource._txn._authz_uid is not None and calresource._txn._authz_uid != organizer_uid:
</ins><span class="cx">             authz_uid = calresource._txn._authz_uid
</span><span class="cx">             authz_record = calresource.directoryService().recordWithUID(authz_uid)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer52devtxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/sql.py (13143 => 13144)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/sql.py        2014-04-03 17:50:55 UTC (rev 13143)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/caldav/datastore/sql.py        2014-04-03 17:59:12 UTC (rev 13144)
</span><span class="lines">@@ -1706,7 +1706,7 @@
</span><span class="cx">                 cutype == &quot;RESOURCE&quot; and config.Scheduling.Options.TrackUnscheduledResourceData):
</span><span class="cx"> 
</span><span class="cx">                 # Find current principal and update modified by details
</span><del>-                if hasattr(self._txn, &quot;_authz_uid&quot;):
</del><ins>+                if self._txn._authz_uid is not None:
</ins><span class="cx">                     authz = self.directoryService().recordWithUID(self._txn._authz_uid)
</span><span class="cx">                     prop = Property(&quot;X-CALENDARSERVER-MODIFIED-BY&quot;, authz.canonicalCalendarUserAddress())
</span><span class="cx">                     prop.setParameter(&quot;CN&quot;, authz.displayName())
</span><span class="lines">@@ -1734,7 +1734,7 @@
</span><span class="cx"> 
</span><span class="cx">             # Only DAV:owner is able to set the property to other than PUBLIC
</span><span class="cx">             if internal_state == ComponentUpdateState.NORMAL:
</span><del>-                if self.calendar().viewerHome().uid() != self._txn._authz_uid and access != Component.ACCESS_PUBLIC:
</del><ins>+                if (self._txn._authz_uid is None or self.calendar().viewerHome().uid() != self._txn._authz_uid) and access != Component.ACCESS_PUBLIC:
</ins><span class="cx">                     raise InvalidCalendarAccessError(&quot;Private event access level change not allowed&quot;)
</span><span class="cx"> 
</span><span class="cx">             self.accessMode = access
</span></span></pre></div>
<a id="CalendarServerbranchesreleaseCalendarServer52devtxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql.py (13143 => 13144)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql.py        2014-04-03 17:50:55 UTC (rev 13143)
+++ CalendarServer/branches/release/CalendarServer-5.2-dev/txdav/common/datastore/sql.py        2014-04-03 17:59:12 UTC (rev 13144)
</span><span class="lines">@@ -246,7 +246,7 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def newTransaction(self, label=&quot;unlabeled&quot;, disableCache=False):
</del><ins>+    def newTransaction(self, label=&quot;unlabeled&quot;, disableCache=False, authz_uid=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @see: L{IDataStore.newTransaction}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -258,7 +258,8 @@
</span><span class="cx">             self._notifierFactories if self._enableNotifications else {},
</span><span class="cx">             label,
</span><span class="cx">             self._migrating,
</span><del>-            disableCache
</del><ins>+            disableCache,
+            authz_uid,
</ins><span class="cx">         )
</span><span class="cx">         if self.logTransactionWaits or self.timeoutTransactions:
</span><span class="cx">             CommonStoreTransactionMonitor(txn, self.logTransactionWaits,
</span><span class="lines">@@ -455,9 +456,12 @@
</span><span class="cx"> 
</span><span class="cx">     id = 0
</span><span class="cx"> 
</span><del>-    def __init__(self, store, sqlTxn,
-                 enableCalendars, enableAddressBooks,
-                 notifierFactories, label, migrating=False, disableCache=False):
</del><ins>+    def __init__(
+        self, store, sqlTxn,
+        enableCalendars, enableAddressBooks,
+        notifierFactories, label, migrating=False, disableCache=False,
+        authz_uid=None,
+    ):
</ins><span class="cx">         self._store = store
</span><span class="cx">         self._calendarHomes = {}
</span><span class="cx">         self._addressbookHomes = {}
</span><span class="lines">@@ -473,6 +477,7 @@
</span><span class="cx">             self._queryCacher = None
</span><span class="cx">         else:
</span><span class="cx">             self._queryCacher = store.queryCacher
</span><ins>+        self._authz_uid = authz_uid
</ins><span class="cx"> 
</span><span class="cx">         CommonStoreTransaction.id += 1
</span><span class="cx">         self._txid = CommonStoreTransaction.id
</span><span class="lines">@@ -3253,7 +3258,7 @@
</span><span class="cx">         @param shared: whether or not the owned collection is &quot;shared&quot;
</span><span class="cx">         @type shared: C{bool}
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        assert self.owned()
</del><ins>+        assert self.owned(), &quot;Cannot change share mode on a shared collection&quot;
</ins><span class="cx"> 
</span><span class="cx">         self._bindMessage = &quot;shared&quot; if shared else None
</span><span class="cx"> 
</span></span></pre>
</div>
</div>

</body>
</html>