<!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>[11960] CalendarServer/branches/users/cdaboo/sharing-in-the-store</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/11960">11960</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2013-11-18 07:30:49 -0800 (Mon, 18 Nov 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Checkpoint changes: move sharing invitations into the store. Major api changes and clean-up done. Still need to rework address books/group
sharing some more to simplify that api.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavresourcepy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/resource.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavsharingpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavstorebridgepy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavtesttest_sharingpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/test/test_sharing.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavbasedatastoreutilpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/base/datastore/util.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoresqlpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretestcommonpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretesttest_sqlpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoresqlpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoretesttest_sqlpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresqlpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemacurrentoracledialectsql">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemacurrentsql">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_tablespy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_tables.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoretestutilpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/test/util.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretesttest_sql_sharingpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql_sharing.py</a></li>
<li><a href="#CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoretesttest_sql_sharingpy">CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql_sharing.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavresourcepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/resource.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/resource.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/resource.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -691,7 +691,7 @@
</span><span class="cx"> 
</span><span class="cx">         elif qname == customxml.SharedURL.qname():
</span><span class="cx">             if self.isShareeResource():
</span><del>-                returnValue(customxml.SharedURL(element.HRef.fromString(self._share.url())))
</del><ins>+                returnValue(customxml.SharedURL(element.HRef.fromString(self._share_url)))
</ins><span class="cx">             else:
</span><span class="cx">                 returnValue(None)
</span><span class="cx"> 
</span><span class="lines">@@ -860,7 +860,7 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         if self.isShareeResource():
</span><del>-            parent = (yield self.locateParent(request, self._share.url()))
</del><ins>+            parent = (yield self.locateParent(request, self._share_url))
</ins><span class="cx">         else:
</span><span class="cx">             parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx">         if parent and isinstance(parent, CalDAVResource):
</span><span class="lines">@@ -876,7 +876,7 @@
</span><span class="cx">         Return the DAV:owner property value (MUST be a DAV:href or None).
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         if self.isShareeResource():
</span><del>-            parent = (yield self.locateParent(request, self._share.url()))
</del><ins>+            parent = (yield self.locateParent(request, self._share_url))
</ins><span class="cx">         else:
</span><span class="cx">             parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx">         if parent and isinstance(parent, CalDAVResource):
</span><span class="lines">@@ -1251,13 +1251,13 @@
</span><span class="cx">         sharedParent = None
</span><span class="cx">         if self.isShareeResource():
</span><span class="cx">             # A sharee collection's quota root is the resource owner's root
</span><del>-            sharedParent = (yield request.locateResource(parentForURL(self._share.url())))
</del><ins>+            sharedParent = (yield request.locateResource(parentForURL(self._share_url)))
</ins><span class="cx">         else:
</span><span class="cx">             parent = (yield self.locateParent(request, request.urlForResource(self)))
</span><span class="cx">             if isCalendarCollectionResource(parent) or isAddressBookCollectionResource(parent):
</span><span class="cx">                 if parent.isShareeResource():
</span><span class="cx">                     # A sharee collection's quota root is the resource owner's root
</span><del>-                    sharedParent = (yield request.locateResource(parentForURL(parent._share.url())))
</del><ins>+                    sharedParent = (yield request.locateResource(parentForURL(parent._share_url)))
</ins><span class="cx"> 
</span><span class="cx">         if sharedParent:
</span><span class="cx">             result = (yield sharedParent.quotaRootResource(request))
</span><span class="lines">@@ -2542,6 +2542,11 @@
</span><span class="cx">         return config.Sharing.Enabled and config.Sharing.Calendars.Enabled and self.exists()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def _otherPrincipalHomeURL(self, otherUID):
+        ownerPrincipal = self.principalForUID(otherUID)
+        return ownerPrincipal.calendarHomeURLs()[0]
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def makeRegularChild(self, name):
</span><span class="cx">         newCalendar = yield self._newStoreHome.calendarWithName(name)
</span><span class="lines">@@ -2794,6 +2799,11 @@
</span><span class="cx">         return config.Sharing.Enabled and config.Sharing.AddressBooks.Enabled and self.exists()
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def _otherPrincipalHomeURL(self, otherUID):
+        ownerPrincipal = self.principalForUID(otherUID)
+        return ownerPrincipal.addressBookHomeURLs()[0]
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def makeRegularChild(self, name):
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavsharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/sharing.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -22,6 +22,7 @@
</span><span class="cx"> 
</span><span class="cx"> __all__ = [
</span><span class="cx">     &quot;SharedResourceMixin&quot;,
</span><ins>+    &quot;SharedHomeMixin&quot;,
</ins><span class="cx"> ]
</span><span class="cx"> 
</span><span class="cx"> from twext.web2 import responsecode
</span><span class="lines">@@ -30,11 +31,10 @@
</span><span class="cx"> from twext.web2.dav.resource import TwistedACLInheritable
</span><span class="cx"> from twext.web2.dav.util import allDataFromStream, joinURL
</span><span class="cx"> 
</span><del>-from txdav.common.datastore.sql import SharingInvitation
</del><span class="cx"> from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
</span><span class="cx">     _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_STATUS_INVITED, \
</span><del>-    _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
-    _BIND_STATUS_INVALID, _ABO_KIND_GROUP
</del><ins>+    _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
+    _BIND_STATUS_INVALID, _ABO_KIND_GROUP, _BIND_STATUS_DELETED
</ins><span class="cx"> from txdav.xml import element
</span><span class="cx"> 
</span><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, DeferredList, \
</span><span class="lines">@@ -46,26 +46,11 @@
</span><span class="cx"> from twistedcaldav.directory.wiki import WikiDirectoryService, getWikiAccess
</span><span class="cx"> from twistedcaldav.linkresource import LinkFollowerMixIn
</span><span class="cx"> 
</span><del>-from pycalendar.datetime import DateTime
</del><span class="cx"> 
</span><del>-
-# FIXME: Get rid of these imports
-from twistedcaldav.directory.util import TRANSACTION_KEY
-# circular import
-# from txdav.common.datastore.sql import ECALENDARTYPE, EADDRESSBOOKTYPE
-ECALENDARTYPE = 0
-EADDRESSBOOKTYPE = 1
-# ENOTIFICATIONTYPE = 2
-
-
</del><span class="cx"> class SharedResourceMixin(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A mix-in for calendar/addressbook resources that implements sharing-related
</span><span class="cx">     functionality.
</span><del>-
-    @ivar _share: If this L{SharedResourceMixin} is the sharee's version of a
-        resource, this refers to the L{Share} that describes it.
-    @type _share: L{Share} or L{NoneType}
</del><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -78,15 +63,15 @@
</span><span class="cx"> 
</span><span class="cx">             def invitePropertyElement(invitation, includeUID=True):
</span><span class="cx"> 
</span><del>-                userid = &quot;urn:uuid:&quot; + invitation.shareeUID()
-                principal = self.principalForUID(invitation.shareeUID())
-                cn = principal.displayName() if principal else invitation.shareeUID()
</del><ins>+                userid = &quot;urn:uuid:&quot; + invitation.shareeUID
+                principal = self.principalForUID(invitation.shareeUID)
+                cn = principal.displayName() if principal else invitation.shareeUID
</ins><span class="cx">                 return customxml.InviteUser(
</span><del>-                    customxml.UID.fromString(invitation.uid()) if includeUID else None,
</del><ins>+                    customxml.UID.fromString(invitation.uid) if includeUID else None,
</ins><span class="cx">                     element.HRef.fromString(userid),
</span><span class="cx">                     customxml.CommonName.fromString(cn),
</span><del>-                    customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode()]()),
-                    invitationBindStatusToXMLMap[invitation.status()](),
</del><ins>+                    customxml.InviteAccess(invitationBindModeToXMLMap[invitation.mode]()),
+                    invitationBindStatusToXMLMap[invitation.status](),
</ins><span class="cx">                 )
</span><span class="cx"> 
</span><span class="cx">             # See if this property is on the shared calendar
</span><span class="lines">@@ -98,11 +83,12 @@
</span><span class="cx"> 
</span><span class="cx">             # See if it is on the sharee calendar
</span><span class="cx">             if self.isShareeResource():
</span><del>-                original = (yield request.locateResource(self._share.url()))
</del><ins>+                original = yield self._newStoreObject.ownerView()
</ins><span class="cx">                 if original is not None:
</span><del>-                    invitations = yield original.validateInvites(request)
</del><ins>+                    invitations = yield original.allInvitations()
+                    invitations = yield self.validateInvites(request, invitations)
</ins><span class="cx"> 
</span><del>-                    ownerPrincipal = (yield original.ownerPrincipal(request))
</del><ins>+                    ownerPrincipal = self.principalForUID(self._newStoreObject.ownerHome().uid())
</ins><span class="cx">                     # FIXME:  use urn:uuid in all cases
</span><span class="cx">                     if self.isCalendarCollection():
</span><span class="cx">                         owner = ownerPrincipal.principalURL()
</span><span class="lines">@@ -138,35 +124,13 @@
</span><span class="cx">         yield self._newStoreObject.setShared(False)
</span><span class="cx"> 
</span><span class="cx">         # Remove all invitees
</span><del>-        for invitation in (yield self._allInvitations()):
-            yield self.uninviteFromShare(invitation, request)
</del><ins>+        for invitation in (yield self._newStoreObject.allInvitations()):
+            yield self._newStoreObject.uninviteUserFromShare(invitation.shareeUID)
</ins><span class="cx"> 
</span><span class="cx">         returnValue(True)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def changeUserInviteState(self, request, inviteUID, shareeUID, state, summary=None):
-        if not self.isShared():
-            raise HTTPError(ErrorResponse(
-                responsecode.FORBIDDEN,
-                (customxml.calendarserver_namespace, &quot;valid-request&quot;),
-                &quot;Invalid share&quot;,
-            ))
-
-        invitation = yield self._invitationForUID(inviteUID)
-        if invitation is None or invitation.shareeUID() != shareeUID:
-            raise HTTPError(ErrorResponse(
-                responsecode.FORBIDDEN,
-                (customxml.calendarserver_namespace, &quot;valid-request&quot;),
-                &quot;Invalid invitation uid: %s&quot; % (inviteUID,),
-            ))
-
-        # Only certain states are owner controlled
-        if invitation.status() in (_BIND_STATUS_INVITED, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED,):
-            yield self._updateInvitation(invitation, status=state, summary=summary)
-
-
-    @inlineCallbacks
</del><span class="cx">     def directShare(self, request):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Directly bind an accessible calendar/address book collection into the
</span><span class="lines">@@ -233,11 +197,16 @@
</span><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         # Accept it
</span><del>-        directUID = Share.directUID(shareeHomeResource._newStoreHome, self._newStoreObject)
-        response = (yield shareeHomeResource.acceptDirectShare(request, hostURL, directUID, self.displayName()))
</del><ins>+        shareeView = yield self._newStoreObject.directShareWithUser(sharee.principalUID())
</ins><span class="cx"> 
</span><span class="cx">         # Return the URL of the shared calendar
</span><del>-        returnValue(response)
</del><ins>+        sharedAsURL = joinURL(shareeHomeResource.url(), shareeView.name())
+        returnValue(XMLResponse(
+            code=responsecode.OK,
+            element=customxml.SharedAs(
+                element.HRef.fromString(sharedAsURL)
+            )
+        ))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def isShared(self):
</span><span class="lines">@@ -250,54 +219,33 @@
</span><span class="cx">             return False
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def setShare(self, share):
</del><ins>+    def setShare(self, share_url):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Set the L{Share} associated with this L{SharedResourceMixin}.  (This
</del><ins>+        Set the URL associated with this L{SharedResourceMixin}.  (This
</ins><span class="cx">         is only invoked on the sharee's resource, not the owner's.)
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         self._isShareeResource = True
</span><del>-        self._share = share
</del><ins>+        self._share_url = share_url
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def isShareeResource(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Return True if this is a sharee view of a shared calendar collection.
</del><ins>+        Return True if this is a sharee view of a shared collection.
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        return hasattr(self, &quot;_isShareeResource&quot;)
</del><ins>+        return (
+            hasattr(self, &quot;_newStoreObject&quot;) and
+            hasattr(self._newStoreObject, &quot;owned&quot;) and
+            not self._newStoreObject.owned()
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
</del><span class="cx">     def removeShareeResource(self, request):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Called when the sharee DELETEs a shared collection.
</span><span class="cx">         &quot;&quot;&quot;
</span><ins>+        return self._newStoreObject.deleteShare()
</ins><span class="cx"> 
</span><del>-        sharee = self.principalForUID(self._share.shareeUID())
</del><span class="cx"> 
</span><del>-        # Remove from sharee's calendar/address book home
-        if self.isCalendarCollection():
-            shareeHome = yield sharee.calendarHome(request)
-        elif self.isAddressBookCollection() or self.isGroup():
-            shareeHome = yield sharee.addressBookHome(request)
-        returnValue((yield shareeHome.removeShare(request, self._share)))
-
-
-    def sharedResourceType(self):
-        &quot;&quot;&quot;
-        Return the DAV:resourcetype stripped of any shared elements.
-        &quot;&quot;&quot;
-
-        if self.isCalendarCollection():
-            return &quot;calendar&quot;
-        elif self.isAddressBookCollection():
-            return &quot;addressbook&quot;
-        elif self.isGroup():
-            # TODO: Add group xml resource type ?
-            return &quot;group&quot;
-        else:
-            return &quot;&quot;
-
-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _checkAccessControl(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -315,13 +263,12 @@
</span><span class="cx">             access control mechanism has dictate the home should no longer have
</span><span class="cx">             any access at all.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        if self._share.direct():
-            ownerUID = self._share.ownerUID()
-            owner = self.principalForUID(ownerUID)
</del><ins>+        if self._newStoreObject.direct():
+            owner = self.principalForUID(self._newStoreObject.ownerHome().uid())
</ins><span class="cx">             if owner.record.recordType == WikiDirectoryService.recordType_wikis:
</span><span class="cx">                 # Access level comes from what the wiki has granted to the
</span><span class="cx">                 # sharee
</span><del>-                sharee = self.principalForUID(self._share.shareeUID())
</del><ins>+                sharee = self.principalForUID(self._newStoreObject.viewerHome().uid())
</ins><span class="cx">                 userID = sharee.record.guid
</span><span class="cx">                 wikiID = owner.record.shortNames[0]
</span><span class="cx">                 access = (yield getWikiAccess(userID, wikiID))
</span><span class="lines">@@ -366,13 +313,12 @@
</span><span class="cx">         assert self._isShareeResource, &quot;Only call this for a sharee resource&quot;
</span><span class="cx">         assert self.isCalendarCollection() or self.isAddressBookCollection(), &quot;Only call this for a address book or calendar resource&quot;
</span><span class="cx"> 
</span><del>-        sharee = self.principalForUID(self._share.shareeUID())
</del><ins>+        sharee = self.principalForUID(self._newStoreObject.viewerHome().uid())
</ins><span class="cx">         access = yield self._checkAccessControl()
</span><span class="cx"> 
</span><span class="cx">         if access == &quot;original&quot;:
</span><del>-            original = (yield request.locateResource(self._share.url()))
-            result = (yield original.accessControlList(request, *args,
-                **kwargs))
</del><ins>+            original = (yield request.locateResource(self._share_url))
+            result = (yield original.accessControlList(request, *args, **kwargs))
</ins><span class="cx">             returnValue(result)
</span><span class="cx"> 
</span><span class="cx">         # Direct shares use underlying privileges of shared collection
</span><span class="lines">@@ -476,18 +422,17 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def validateInvites(self, request):
</del><ins>+    def validateInvites(self, request, invitations=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Make sure each userid in an invite is valid - if not re-write status.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         # assert request
</span><del>-        invitations = yield self._allInvitations()
</del><ins>+        if invitations is None:
+            invitations = yield self._newStoreObject.allInvitations()
</ins><span class="cx">         for invitation in invitations:
</span><del>-            if invitation.status() != _BIND_STATUS_INVALID:
-                if not (yield self.validUserIDForShare(&quot;urn:uuid:&quot; + invitation.shareeUID(), request)):
-                    # FIXME: temporarily disable this to deal with flaky directory
-                    #yield self._updateInvitation(invitation, status=_BIND_STATUS_INVALID)
-                    self.log.error(&quot;Invalid sharee detected: {uid}&quot;, uid=invitation.shareeUID())
</del><ins>+            if invitation.status != _BIND_STATUS_INVALID:
+                if not (yield self.validUserIDForShare(&quot;urn:uuid:&quot; + invitation.shareeUID, request)):
+                    self.log.error(&quot;Invalid sharee detected: {uid}&quot;, uid=invitation.shareeUID)
</ins><span class="cx"> 
</span><span class="cx">         returnValue(invitations)
</span><span class="cx"> 
</span><span class="lines">@@ -549,78 +494,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def _createInvitation(self, shareeUID, mode, summary,):
-        &quot;&quot;&quot;
-        Create a new homeChild and wrap it in an Invitation
-        &quot;&quot;&quot;
-        if self.isCalendarCollection():
-            shareeHome = yield self._newStoreObject._txn.calendarHomeWithUID(shareeUID, create=True)
-        elif self.isAddressBookCollection() or self.isGroup():
-            shareeHome = yield self._newStoreObject._txn.addressbookHomeWithUID(shareeUID, create=True)
-
-        shareUID = yield self._newStoreObject.shareWith(shareeHome,
-                                                    mode=mode,
-                                                    status=_BIND_STATUS_INVITED,
-                                                    message=summary)
-        shareeStoreObject = yield shareeHome.invitedObjectWithShareUID(shareUID)
-        invitation = SharingInvitation.fromCommonHomeChild(shareeStoreObject)
-        returnValue(invitation)
-
-
-    @inlineCallbacks
-    def _updateInvitation(self, invitation, mode=None, status=None, summary=None):
-        yield self._newStoreObject.updateShareFromSharingInvitation(invitation, mode=mode, status=status, message=summary)
-        if mode is not None:
-            invitation.setMode(mode)
-        if status is not None:
-            invitation.setStatus(status)
-        if summary is not None:
-            invitation.setSummary(summary)
-
-
-    @inlineCallbacks
-    def _allInvitations(self):
-        &quot;&quot;&quot;
-        Get list of all invitations (non-direct) to this object.
-        &quot;&quot;&quot;
-        if not self.exists():
-            returnValue([])
-
-        invitations = yield self._newStoreObject.sharingInvites()
-
-        # remove direct shares as those are not &quot;real&quot; invitations
-        invitations = filter(lambda x: x.mode() != _BIND_MODE_DIRECT, invitations)
-
-        invitations.sort(key=lambda invitation: invitation.shareeUID())
-
-        returnValue(invitations)
-
-
-    @inlineCallbacks
-    def _invitationForShareeUID(self, shareeUID):
-        &quot;&quot;&quot;
-        Get an invitation for this sharee principal UID
-        &quot;&quot;&quot;
-        invitations = yield self._allInvitations()
-        for invitation in invitations:
-            if invitation.shareeUID() == shareeUID:
-                returnValue(invitation)
-        returnValue(None)
-
-
-    @inlineCallbacks
-    def _invitationForUID(self, uid):
-        &quot;&quot;&quot;
-        Get an invitation for an invitations uid
-        &quot;&quot;&quot;
-        invitations = yield self._allInvitations()
-        for invitation in invitations:
-            if invitation.uid() == uid:
-                returnValue(invitation)
-        returnValue(None)
-
-
-    @inlineCallbacks
</del><span class="cx">     def inviteSingleUserToShare(self, userid, cn, ace, summary, request): #@UnusedVariable
</span><span class="cx"> 
</span><span class="cx">         # We currently only handle local users
</span><span class="lines">@@ -628,71 +501,32 @@
</span><span class="cx">         if not sharee:
</span><span class="cx">             returnValue(False)
</span><span class="cx"> 
</span><del>-        shareeUID = sharee.principalUID()
</del><ins>+        result = (yield self._newStoreObject.inviteUserToShare(
+            sharee.principalUID(),
+            invitationBindModeFromXMLMap[type(ace)],
+            summary,
+        ))
</ins><span class="cx"> 
</span><del>-        # Look for existing invite and update its fields or create new one
-        invitation = yield self._invitationForShareeUID(shareeUID)
-        if invitation:
-            status = _BIND_STATUS_INVITED if invitation.status() in (_BIND_STATUS_DECLINED, _BIND_STATUS_INVALID) else None
-            yield self._updateInvitation(invitation, mode=invitationBindModeFromXMLMap[type(ace)], status=status, summary=summary)
-        else:
-            invitation = yield self._createInvitation(
-                                shareeUID=shareeUID,
-                                mode=invitationBindModeFromXMLMap[type(ace)],
-                                summary=summary)
-        # Send invite notification
-        yield self.sendInviteNotification(invitation, request)
</del><ins>+        returnValue(result)
</ins><span class="cx"> 
</span><del>-        returnValue(True)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def uninviteSingleUserFromShare(self, userid, aces, request): #@UnusedVariable
</span><del>-        # Cancel invites - we'll just use whatever userid we are given
</del><span class="cx"> 
</span><ins>+        # Cancel invites - we'll just use whatever userid we are given
</ins><span class="cx">         sharee = self.principalForCalendarUserAddress(userid)
</span><span class="cx">         if not sharee:
</span><span class="cx">             returnValue(False)
</span><span class="cx"> 
</span><del>-        shareeUID = sharee.principalUID()
</del><ins>+        result = (yield self._newStoreObject.uninviteUserFromShare(sharee.principalUID()))
</ins><span class="cx"> 
</span><del>-        invitation = yield self._invitationForShareeUID(shareeUID)
-        if invitation:
-            result = (yield self.uninviteFromShare(invitation, request))
-        else:
-            result = False
-
</del><span class="cx">         returnValue(result)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def uninviteFromShare(self, invitation, request):
</span><span class="cx"> 
</span><del>-        # Remove any shared calendar or address book
-        sharee = self.principalForUID(invitation.shareeUID())
-        if sharee:
-            previousInvitationStatus = invitation.status()
-            displayName = None
-            if self.isCalendarCollection():
-                shareeHomeResource = yield sharee.calendarHome(request)
-                if shareeHomeResource is not None:
-                    displayName = yield shareeHomeResource.removeShareByUID(request, invitation.uid())
-            elif self.isAddressBookCollection() or self.isGroup():
-                shareeHomeResource = yield sharee.addressBookHome(request)
-                if shareeHomeResource is not None:
-                    yield shareeHomeResource.removeShareByUID(request, invitation.uid())
-
-            # If current user state is accepted then we send an invite with the new state, otherwise
-            # we cancel any existing invites for the user
-            if shareeHomeResource is not None:
-                if previousInvitationStatus != _BIND_STATUS_ACCEPTED:
-                    yield self.removeInviteNotification(invitation, request)
-                else:
-                    yield self.sendInviteNotification(invitation, request, displayName=displayName, notificationState=&quot;DELETED&quot;)
-
-        # Direct shares for  with valid sharee principal will already be deleted
-        yield self._newStoreObject.unshareWithUID(invitation.shareeUID())
-
</del><ins>+        yield self._newStoreObject.uninviteFromShare(invitation)
</ins><span class="cx">         returnValue(True)
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -703,74 +537,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def sendInviteNotification(self, invitation, request, notificationState=None, displayName=None):
-
-        ownerPrincipal = (yield self.ownerPrincipal(request))
-
-        # Locate notifications collection for user
-        sharee = self.principalForUID(invitation.shareeUID())
-        if sharee is None:
-            raise ValueError(&quot;sharee is None but principalUID was valid before&quot;)
-
-        hosturl = self._newStoreObject.name()
-        if self.sharedResourceType() == &quot;group&quot;:
-            hosturl = self._newStoreObject.parentCollection().name() + &quot;/&quot; + hosturl
-
-        # We need to look up the resource so that the response cache notifier is properly initialized
-        notificationResource = (yield request.locateResource(sharee.notificationURL()))
-        notifications = notificationResource._newStoreNotifications
-
-        '''
-        # Look for existing notification
-        # oldnotification is not used don't query for it
-        oldnotification = (yield notifications.notificationObjectWithUID(invitation.uid()))
-        if oldnotification:
-            # TODO: rollup changes?
-            pass
-        '''
-
-        # Generate invite XML
-        state = notificationState if notificationState else invitation.status()
-        summary = invitation.summary() if displayName is None else displayName
-
-        notificationtype = {
-            &quot;notification-type&quot;: &quot;invite-notification&quot;,
-            &quot;shared-type&quot;: self.sharedResourceType(),
-        }
-        notificationdata = {
-            &quot;notification-type&quot;: &quot;invite-notification&quot;,
-            &quot;shared-type&quot;: self.sharedResourceType(),
-            &quot;dtstamp&quot;: DateTime.getNowUTC().getText(),
-            &quot;owner&quot;: ownerPrincipal.principalUID(),
-            &quot;sharee&quot;: invitation.shareeUID(),
-            &quot;uid&quot;: invitation.uid(),
-            &quot;status&quot;: state,
-            &quot;access&quot;: invitation.mode(),
-            &quot;name&quot;: hosturl,
-            &quot;summary&quot;: summary,
-        }
-        if self.isCalendarCollection():
-            notificationdata[&quot;supported-components&quot;] = self._newStoreObject.getSupportedComponents()
-
-        # Add to collections
-        yield notifications.writeNotificationObject(invitation.uid(), notificationtype, notificationdata)
-
-
-    @inlineCallbacks
-    def removeInviteNotification(self, invitation, request):
-
-        # Locate notifications collection for user
-        sharee = self.principalForUID(invitation.shareeUID())
-        if sharee is None:
-            raise ValueError(&quot;sharee is None but principalUID was valid before&quot;)
-        notificationResource = (yield request.locateResource(sharee.notificationURL()))
-        notifications = notificationResource._newStoreNotifications
-
-        # Add to collections
-        yield notifications.removeNotificationObjectWithUID(invitation.uid())
-
-
-    @inlineCallbacks
</del><span class="cx">     def _xmlHandleInvite(self, request, docroot):
</span><span class="cx">         yield self.authorize(request, (element.Read(), element.Write()))
</span><span class="cx">         result = (yield self._handleInvite(request, docroot))
</span><span class="lines">@@ -988,7 +754,7 @@
</span><span class="cx">     _BIND_STATUS_ACCEPTED     : customxml.InviteStatusAccepted,
</span><span class="cx">     _BIND_STATUS_DECLINED     : customxml.InviteStatusDeclined,
</span><span class="cx">     _BIND_STATUS_INVALID      : customxml.InviteStatusInvalid,
</span><del>-    &quot;DELETED&quot;                 : customxml.InviteStatusDeleted,
</del><ins>+    _BIND_STATUS_DELETED      : customxml.InviteStatusDeleted,
</ins><span class="cx"> }
</span><span class="cx"> invitationBindStatusFromXMLMap = dict((v, k) for k, v in invitationBindStatusToXMLMap.iteritems())
</span><span class="cx"> 
</span><span class="lines">@@ -1015,219 +781,30 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def provisionShare(self, child, request=None):
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        If the given child resource (a L{SharedResourceMixin}) of this
-        L{SharedHomeMixin} is a I{sharee}'s view of a shared calendar object,
-        associate it with a L{Share}.
</del><ins>+        Set shared state and check access control.
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        share = yield self._shareForStoreObject(child._newStoreObject, request)
-        if share:
-            child.setShare(share)
</del><ins>+        if child._newStoreObject is not None and not child._newStoreObject.owned():
+            ownerHomeURL = self._otherPrincipalHomeURL(child._newStoreObject.ownerHome().uid())
+            ownerView = yield child._newStoreObject.ownerView()
+            child.setShare(joinURL(ownerHomeURL, ownerView.name()))
</ins><span class="cx">             access = yield child._checkAccessControl()
</span><span class="cx">             if access is None:
</span><span class="cx">                 returnValue(None)
</span><span class="cx">         returnValue(child)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
-    def _shareForStoreObject(self, storeObject, request=None):
-        &quot;&quot;&quot;
-        Determine the L{Share} associated with the given child.
</del><ins>+    def _otherPrincipalHomeURL(self, otherUID):
+        pass
</ins><span class="cx"> 
</span><del>-        @param child: A calendar or addressbook data store object, a child of
-            the resource represented by this L{SharedHomeMixin} instance, which
-            may be shared.
-        @type child: L{txdav.caldav.icalendarstore.ICalendar} or
-            L{txdav.carddav.iaddressbookstore.IAddressBook}
</del><span class="cx"> 
</span><del>-        @return: a L{Share} if C{child} is not the owner's view of the share,
-            or C{None}.
-        @rtype: L{Share} or L{NoneType}
-        &quot;&quot;&quot;
-        # Find a matching share
-        # use &quot;storeObject.shareUID is not None&quot; to prevent partially shared address books form getting a share
-        if storeObject is None or storeObject.owned():
-            returnValue(None)
-
-        # Get the shared object's URL - we may need to fake this if the sharer principal is missing or disabled
-        url = None
-        owner = self.principalForUID(storeObject.ownerHome().uid())
-        from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
-        if isinstance(owner, DirectoryCalendarPrincipalResource):
-
-            if not request:
-                # FIXEME:  Fake up a request that can be used to get the owner home resource
-                class _FakeRequest(object):
-                    pass
-                fakeRequest = _FakeRequest()
-                setattr(fakeRequest, TRANSACTION_KEY, self._newStoreHome._txn)
-                request = fakeRequest
-
-            if self._newStoreHome._homeType == ECALENDARTYPE:
-                ownerHomeCollection = yield owner.calendarHome(request)
-            elif self._newStoreHome._homeType == EADDRESSBOOKTYPE:
-                ownerHomeCollection = yield owner.addressBookHome(request)
-
-            if ownerHomeCollection is not None:
-                url = ownerHomeCollection.url()
-
-        if url is None:
-            url = &quot;/calendars/__uids__/%s/&quot; % (storeObject.ownerHome().uid(),)
-
-        ownerHomeChild = yield storeObject.ownerHome().childWithID(storeObject._resourceID)
-        if ownerHomeChild:
-            assert ownerHomeChild != storeObject
-            url = joinURL(url, ownerHomeChild.name())
-            share = Share(shareeStoreObject=storeObject, ownerStoreObject=ownerHomeChild, url=url)
-        else:
-            for ownerHomeChild in (yield storeObject.ownerHome().children()):
-                if ownerHomeChild.owned():
-                    sharedGroup = yield ownerHomeChild.objectResourceWithID(storeObject._resourceID)
-                    if sharedGroup:
-                        url = joinURL(url, ownerHomeChild.name(), sharedGroup.name())
-                        share = Share(shareeStoreObject=storeObject, ownerStoreObject=sharedGroup, url=url)
-                        break
-
-        returnValue(share)
-
-
</del><span class="cx">     @inlineCallbacks
</span><del>-    def _shareForUID(self, shareUID, request):
</del><ins>+    def acceptShare(self, request, inviteUID, summary):
</ins><span class="cx"> 
</span><del>-        if shareUID is not None:  # shareUID may be None for partially shared addressbooks
-            shareeStoreObject = yield self._newStoreHome.objectWithShareUID(shareUID)
-            if shareeStoreObject:
-                share = yield self._shareForStoreObject(shareeStoreObject, request)
-                if share:
-                    returnValue(share)
</del><ins>+        # Accept the share
+        shareeView = yield self._newStoreHome.acceptShare(inviteUID, summary)
</ins><span class="cx"> 
</span><del>-            # find direct shares
-            children = yield self._newStoreHome.children()
-            for child in children:
-                share = yield self._shareForStoreObject(child, request)
-                if share and share.uid() == shareUID:
-                    returnValue(share)
-
-        returnValue(None)
-
-
-    @inlineCallbacks
-    def acceptInviteShare(self, request, hostUrl, inviteUID, displayname=None):
-
-        # Check for old share
-        oldShare = yield self._shareForUID(inviteUID, request)
-
-        # Send the invite reply then add the link
-        yield self._changeShare(request, _BIND_STATUS_ACCEPTED, hostUrl, inviteUID, displayname)
-        if oldShare:
-            share = oldShare
-        else:
-            sharedResource = yield request.locateResource(hostUrl)
-            shareeStoreObject = yield self._newStoreHome.objectWithShareUID(inviteUID)
-
-            share = Share(shareeStoreObject=shareeStoreObject,
-                          ownerStoreObject=sharedResource._newStoreObject,
-                          url=hostUrl)
-
-        response = yield self._acceptShare(request, not oldShare, share, displayname)
-        returnValue(response)
-
-
-    @inlineCallbacks
-    def acceptDirectShare(self, request, hostUrl, resourceUID,
-                          displayname=None):
-
-        # Just add the link
-        oldShare = yield self._shareForUID(resourceUID, request)
-        if oldShare:
-            share = oldShare
-        else:
-            sharedCollection = yield request.locateResource(hostUrl)
-            shareUID = yield sharedCollection._newStoreObject.shareWith(
-                shareeHome=self._newStoreHome,
-                mode=_BIND_MODE_DIRECT,
-                status=_BIND_STATUS_ACCEPTED,
-                message=displayname
-            )
-
-            shareeStoreObject = yield self._newStoreHome.objectWithShareUID(shareUID)
-            share = Share(shareeStoreObject=shareeStoreObject,
-                          ownerStoreObject=sharedCollection._newStoreObject,
-                          url=hostUrl)
-
-        response = yield self._acceptShare(request, not oldShare, share, displayname)
-        returnValue(response)
-
-
-    @inlineCallbacks
-    def _acceptShare(self, request, isNewShare, share, displayname=None):
-        &quot;&quot;&quot;
-        Mark a pending shared invitation I{to} this, the owner's collection, as
-        accepted, generating the HTTP response to the request that accepted it.
-
-        @param request: The HTTP request that is accepting it.
-        @type request: L{twext.web2.iweb.IRequest}
-
-        @param isNewShare: a boolean indicating whether this share is new.
-        @type isNewShare: L{bool}
-
-        @param share: The share referencing the proposed sharer and sharee.
-        @type share: L{Share}
-
-        @param displayname: the UTF-8 encoded contents of the display-name
-            property on the resource to be created while accepting.
-        @type displayname: L{bytes}
-
-        @return: a L{twext.web2.iweb.IResponse} containing a serialized
-            L{customxml.SharedAs} element as its body.
-        @rtype: L{Deferred} firing L{XMLResponse}
-        &quot;&quot;&quot;
-        # Get shared collection in non-share mode first
-        sharedResource = yield request.locateResource(share.url())
-        sharee = self.principalForUID(share.shareeUID())
-
-        if sharedResource.isCalendarCollection():
-            shareeHomeResource = yield sharee.calendarHome(request)
-            sharedAsURL = joinURL(shareeHomeResource.url(), share.name())
-            shareeCalender = yield request.locateResource(sharedAsURL)
-            shareeCalender.setShare(share)
-
-            # For calendars only, per-user displayname and color
-            if displayname:
-                yield shareeCalender.writeProperty(element.DisplayName.fromString(displayname), request)
-
-            if isNewShare:
-                # For a direct share we will copy any calendar-color over using the owners view
-                if share.direct():
-                    try:
-                        color = yield sharedResource.readProperty(customxml.CalendarColor, request)
-                    except HTTPError:
-                        color = None
-                    if color:
-                        yield shareeCalender.writeProperty(customxml.CalendarColor.fromString(color), request)
-
-                # Calendars always start out transparent and with empty default alarms
-                yield shareeCalender._newStoreObject.setUsedForFreeBusy(False)
-                yield shareeCalender._newStoreObject.setDefaultAlarm(&quot;empty&quot;, True, True)
-                yield shareeCalender._newStoreObject.setDefaultAlarm(&quot;empty&quot;, True, False)
-                yield shareeCalender._newStoreObject.setDefaultAlarm(&quot;empty&quot;, False, True)
-                yield shareeCalender._newStoreObject.setDefaultAlarm(&quot;empty&quot;, False, False)
-
-        elif sharedResource.isAddressBookCollection():
-            shareeHomeResource = yield sharee.addressBookHome(request)
-            sharedAsURL = joinURL(shareeHomeResource.url(), share.ownerUID())
-            shareeAddressBook = yield request.locateResource(sharedAsURL)
-            shareeAddressBook.setShare(share)
-
-        elif sharedResource.isGroup():
-            shareeHomeResource = yield sharee.addressBookHome(request)
-            sharedAsURL = joinURL(shareeHomeResource.url(), share.ownerUID(), share.name())
-            shareeGroup = yield request.locateResource(sharedAsURL)
-            shareeGroup.setShare(share)
-
-        # Notify client of changes
-        yield self.notifyChanged()
-
</del><span class="cx">         # Return the URL of the shared collection
</span><ins>+        sharedAsURL = joinURL(self.url(), shareeView.name())
</ins><span class="cx">         returnValue(XMLResponse(
</span><span class="cx">             code=responsecode.OK,
</span><span class="cx">             element=customxml.SharedAs(
</span><span class="lines">@@ -1237,132 +814,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def removeShare(self, request, share):
-        &quot;&quot;&quot;
-        Remove a shared collection named in resourceName
-        &quot;&quot;&quot;
</del><ins>+    def declineShare(self, request, inviteUID):
</ins><span class="cx"> 
</span><del>-        if share.direct():
-            yield self.removeDirectShare(request, share)
-            returnValue(None)
-        else:
-            # Send a decline when an invite share is removed only
-            result = yield self.declineShare(request, share.url(), share.uid())
-            returnValue(result)
-
-
-    @inlineCallbacks
-    def removeShareByUID(self, request, shareUID):
-        &quot;&quot;&quot;
-        Remove a shared collection but do not send a decline back. Return the
-        current display name of the shared collection.
-        &quot;&quot;&quot;
-
-        share = yield self._shareForUID(shareUID, request)
-        if share:
-            displayName = (yield self.removeDirectShare(request, share))
-            returnValue(displayName)
-        else:
-            returnValue(None)
-
-
-    @inlineCallbacks
-    def removeDirectShare(self, request, share):
-        &quot;&quot;&quot;
-        Remove a shared collection but do not send a decline back. Return the
-        current display name of the shared collection.
-        &quot;&quot;&quot;
-        # FIXME: only works for calendar
-        shareURL = joinURL(self.url(), share.name())
-        shared = (yield request.locateResource(shareURL))
-        displayname = shared.displayName()
-
-        if share.direct():
-            yield share._ownerStoreObject.unshareWith(share._shareeStoreObject.viewerHome())
-        else:
-            yield share._ownerStoreObject.updateShare(share._shareeStoreObject, status=_BIND_STATUS_DECLINED)
-
-        returnValue(displayname)
-
-
-    @inlineCallbacks
-    def declineShare(self, request, hostUrl, inviteUID):
-
</del><span class="cx">         # Remove it if it is in the DB
</span><del>-        yield self.removeShareByUID(request, inviteUID)
-        yield self._changeShare(request, _BIND_STATUS_DECLINED, hostUrl, inviteUID, processed=True)
</del><ins>+        yield self._newStoreHome.declineShare(inviteUID)
</ins><span class="cx">         returnValue(Response(code=responsecode.NO_CONTENT))
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
-    def _changeShare(self, request, state, hostUrl, replytoUID, displayname=None, processed=False):
-        &quot;&quot;&quot;
-        Accept or decline an invite to a shared collection.
-        &quot;&quot;&quot;
-        # Change state in owner invite
-        ownerPrincipal = (yield self.ownerPrincipal(request))
-        ownerPrincipalUID = ownerPrincipal.principalUID()
-        sharedResource = (yield request.locateResource(hostUrl))
-        if sharedResource is None:
-            # FIXME: have to return here rather than raise to allow removal of a share for a sharer
-            # whose principal is no longer valid yet still exists in the store. Really we need to get rid of
-            # locateResource calls and just do everything via store objects.
-            returnValue(None)
-            # Original shared collection is gone - nothing we can do except ignore it
-            raise HTTPError(ErrorResponse(
-                responsecode.FORBIDDEN,
-                (customxml.calendarserver_namespace, &quot;valid-request&quot;),
-                &quot;Invalid shared collection&quot;,
-            ))
-
-        # Change the record
-        if not processed:
-            yield sharedResource.changeUserInviteState(request, replytoUID, ownerPrincipalUID, state, displayname)
-
-        yield self.sendReply(request, ownerPrincipal, sharedResource, state, hostUrl, replytoUID, displayname)
-
-
-    @inlineCallbacks
-    def sendReply(self, request, shareePrincipal, sharedResource, state, hostUrl, replytoUID, displayname=None):
-
-        # Locate notifications collection for owner
-        ownerPrincipal = (yield sharedResource.ownerPrincipal(request))
-        if ownerPrincipal is None:
-            # FIXME: have to return here rather than raise to allow removal of a share for a sharer
-            # whose principal is no longer valid yet still exists in the store. Really we need to get rid of
-            # locateResource calls and just do everything via store objects.
-            returnValue(None)
-
-        hosturl = sharedResource._newStoreObject.name()
-        if sharedResource.sharedResourceType() == &quot;group&quot;:
-            hosturl = sharedResource._newStoreObject.parentCollection().name() + &quot;/&quot; + hosturl
-
-        notificationResource = (yield request.locateResource(ownerPrincipal.notificationURL()))
-        notifications = notificationResource._newStoreNotifications
-
-        # Generate invite XML
-        notificationUID = &quot;%s-reply&quot; % (replytoUID,)
-
-        notificationtype = {
-            &quot;notification-type&quot;: &quot;invite-reply&quot;,
-        }
-
-        notificationdata = {
-            &quot;notification-type&quot;: &quot;invite-reply&quot;,
-            &quot;shared-type&quot;: sharedResource.sharedResourceType(),
-            &quot;dtstamp&quot;: DateTime.getNowUTC().getText(),
-            &quot;owner&quot;: ownerPrincipal.principalUID(),
-            &quot;sharee&quot;: shareePrincipal.principalUID(),
-            &quot;status&quot;: state,
-            &quot;name&quot;: hosturl,
-            &quot;in-reply-to&quot;: replytoUID,
-            &quot;summary&quot;: displayname if displayname is not None else &quot;&quot;,
-        }
-
-        # Add to collections
-        yield notifications.writeNotificationObject(notificationUID, notificationtype, notificationdata)
-
-
</del><span class="cx">     def _handleInviteReply(self, request, invitereplydoc):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Handle a user accepting or declining a sharing invite
</span><span class="lines">@@ -1392,80 +850,6 @@
</span><span class="cx">                 &quot;Missing required XML elements&quot;,
</span><span class="cx">             ))
</span><span class="cx">         if accepted:
</span><del>-            return self.acceptInviteShare(request, hostUrl, replytoUID, displayname=summary)
</del><ins>+            return self.acceptShare(request, replytoUID, summary=summary)
</ins><span class="cx">         else:
</span><del>-            return self.declineShare(request, hostUrl, replytoUID)
-
-
-
-class Share(object):
-    &quot;&quot;&quot;
-    A L{Share} represents information about a collection which has been shared
-    from one user to another.
-    &quot;&quot;&quot;
-
-    def __init__(self, ownerStoreObject, shareeStoreObject, url):
-        &quot;&quot;&quot;
-        @param sharerHomeChild: The data store object representing the shared
-            collection as present in the owner's home collection; the owner's
-            reference.
-        @type sharerHomeChild: L{txdav.caldav.icalendarstore.ICalendar}
-
-        @param shareeHomeChild: The data store object representing the
-            collection as present in the sharee's home collection; the sharee's
-            reference.
-        @type shareeHomeChild: L{txdav.caldav.icalendarstore.ICalendar}
-
-        @param url: The URL referring to the sharer's version of the resource.
-        @type url: L{bytes}
-        &quot;&quot;&quot;
-        self._shareeStoreObject = shareeStoreObject
-        self._ownerStoreObject = ownerStoreObject
-        self._ownerResourceURL = url
-
-
-    @classmethod
-    def directUID(cls, shareeHome, ownerHomeChild):
-        return &quot;Direct-%s-%s&quot; % (shareeHome._resourceID,
-                                 ownerHomeChild._resourceID,)
-
-
-    def uid(self):
-        # Move to CommonHomeChild shareUID?
-        if self._shareeStoreObject.shareMode() == _BIND_MODE_DIRECT:
-            return self.directUID(shareeHome=self._shareeStoreObject.viewerHome(),
-                                  ownerHomeChild=self._ownerStoreObject,)
-        else:
-            return self._shareeStoreObject.shareUID()
-
-
-    def direct(self):
-        &quot;&quot;&quot;
-        Is this L{Share} a &quot;direct&quot; share?
-
-        @return: a boolean indicating whether it's direct.
-        &quot;&quot;&quot;
-        return self._shareeStoreObject.shareMode() == _BIND_MODE_DIRECT
-
-
-    def url(self):
-        &quot;&quot;&quot;
-        @return: The URL to the owner's version of the shared collection.
-        &quot;&quot;&quot;
-        return self._ownerResourceURL
-
-
-    def name(self):
-        return self._shareeStoreObject.name()
-
-
-    def summary(self):
-        return self._shareeStoreObject.shareMessage()
-
-
-    def shareeUID(self):
-        return self._shareeStoreObject.viewerHome().uid()
-
-
-    def ownerUID(self):
-        return self._shareeStoreObject.ownerHome().uid()
</del><ins>+            return self.declineShare(request, replytoUID)
</ins></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavstorebridgepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/storebridge.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -277,7 +277,7 @@
</span><span class="cx"> 
</span><span class="cx">     def owner_url(self):
</span><span class="cx">         if self.isShareeResource():
</span><del>-            return joinURL(self._share.url(), &quot;/&quot;)
</del><ins>+            return joinURL(self._share_url, &quot;/&quot;)
</ins><span class="cx">         else:
</span><span class="cx">             return self.url()
</span><span class="cx"> 
</span><span class="lines">@@ -1642,23 +1642,23 @@
</span><span class="cx">         for invite in invites:
</span><span class="cx"> 
</span><span class="cx">             # Only want accepted invites
</span><del>-            if invite.status() != _BIND_STATUS_ACCEPTED:
</del><ins>+            if invite.status != _BIND_STATUS_ACCEPTED:
</ins><span class="cx">                 continue
</span><span class="cx"> 
</span><span class="cx">             userprivs = [
</span><span class="cx">             ]
</span><del>-            if invite.mode() in (_BIND_MODE_READ, _BIND_MODE_WRITE,):
</del><ins>+            if invite.mode in (_BIND_MODE_READ, _BIND_MODE_WRITE,):
</ins><span class="cx">                 userprivs.append(davxml.Privilege(davxml.Read()))
</span><span class="cx">                 userprivs.append(davxml.Privilege(davxml.ReadACL()))
</span><span class="cx">                 userprivs.append(davxml.Privilege(davxml.ReadCurrentUserPrivilegeSet()))
</span><del>-            if invite.mode() in (_BIND_MODE_READ,):
</del><ins>+            if invite.mode in (_BIND_MODE_READ,):
</ins><span class="cx">                 userprivs.append(davxml.Privilege(davxml.WriteProperties()))
</span><del>-            if invite.mode() in (_BIND_MODE_WRITE,):
</del><ins>+            if invite.mode in (_BIND_MODE_WRITE,):
</ins><span class="cx">                 userprivs.append(davxml.Privilege(davxml.Write()))
</span><span class="cx">             proxyprivs = list(userprivs)
</span><span class="cx">             proxyprivs.remove(davxml.Privilege(davxml.ReadACL()))
</span><span class="cx"> 
</span><del>-            principal = self.principalForUID(invite.shareeUID())
</del><ins>+            principal = self.principalForUID(invite.shareeUID)
</ins><span class="cx">             aces += (
</span><span class="cx">                 # Inheritable specific access for the resource's associated principal.
</span><span class="cx">                 davxml.ACE(
</span><span class="lines">@@ -1953,10 +1953,10 @@
</span><span class="cx">             access control mechanism has dictate the home should no longer have
</span><span class="cx">             any access at all.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        if invite.mode() in (_BIND_MODE_DIRECT,):
-            ownerUID = invite.ownerUID()
</del><ins>+        if invite.mode in (_BIND_MODE_DIRECT,):
+            ownerUID = invite.ownerUID
</ins><span class="cx">             owner = self.principalForUID(ownerUID)
</span><del>-            shareeUID = invite.shareeUID()
</del><ins>+            shareeUID = invite.shareeUID
</ins><span class="cx">             if owner.record.recordType == WikiDirectoryService.recordType_wikis:
</span><span class="cx">                 # Access level comes from what the wiki has granted to the
</span><span class="cx">                 # sharee
</span><span class="lines">@@ -1972,9 +1972,9 @@
</span><span class="cx">                     returnValue(None)
</span><span class="cx">             else:
</span><span class="cx">                 returnValue(&quot;original&quot;)
</span><del>-        elif invite.mode() in (_BIND_MODE_READ,):
</del><ins>+        elif invite.mode in (_BIND_MODE_READ,):
</ins><span class="cx">             returnValue(&quot;read-only&quot;)
</span><del>-        elif invite.mode() in (_BIND_MODE_WRITE,):
</del><ins>+        elif invite.mode in (_BIND_MODE_WRITE,):
</ins><span class="cx">             returnValue(&quot;read-write&quot;)
</span><span class="cx">         returnValue(&quot;original&quot;)
</span><span class="cx"> 
</span><span class="lines">@@ -1987,7 +1987,7 @@
</span><span class="cx">         for invite in invites:
</span><span class="cx"> 
</span><span class="cx">             # Only want accepted invites
</span><del>-            if invite.status() != _BIND_STATUS_ACCEPTED:
</del><ins>+            if invite.status != _BIND_STATUS_ACCEPTED:
</ins><span class="cx">                 continue
</span><span class="cx"> 
</span><span class="cx">             privileges = [
</span><span class="lines">@@ -1999,7 +1999,7 @@
</span><span class="cx">             if access in (&quot;read-only&quot;, &quot;read-write&quot;,):
</span><span class="cx">                 userprivs.extend(privileges)
</span><span class="cx"> 
</span><del>-            principal = self.principalForUID(invite.shareeUID())
</del><ins>+            principal = self.principalForUID(invite.shareeUID)
</ins><span class="cx">             aces += (
</span><span class="cx">                 # Inheritable specific access for the resource's associated principal.
</span><span class="cx">                 davxml.ACE(
</span><span class="lines">@@ -3771,7 +3771,7 @@
</span><span class="cx">                     invitationBindStatusToXMLMap[jsondata[&quot;status&quot;]](),
</span><span class="cx">                     customxml.InviteAccess(invitationBindModeToXMLMap[jsondata[&quot;access&quot;]]()),
</span><span class="cx">                     customxml.HostURL(
</span><del>-                        element.HRef.fromString(urljoin(ownerHomeURL, jsondata[&quot;name&quot;])),
</del><ins>+                        element.HRef.fromString(urljoin(ownerHomeURL, jsondata[&quot;ownerName&quot;])),
</ins><span class="cx">                     ),
</span><span class="cx">                     customxml.Organizer(
</span><span class="cx">                         element.HRef.fromString(owner),
</span><span class="lines">@@ -3802,22 +3802,21 @@
</span><span class="cx">             commonName = shareePrincipal.displayName()
</span><span class="cx">             record = shareePrincipal.record
</span><span class="cx"> 
</span><ins>+            typeAttr = {&quot;shared-type&quot;: jsondata[&quot;shared-type&quot;]}
</ins><span class="cx">             xmldata = customxml.Notification(
</span><span class="cx">                 customxml.DTStamp.fromString(jsondata[&quot;dtstamp&quot;]),
</span><span class="cx">                 customxml.InviteReply(
</span><del>-                    *(
-                        (
-                            element.HRef.fromString(cua),
-                            invitationBindStatusToXMLMap[jsondata[&quot;status&quot;]](),
-                            customxml.HostURL(
-                                element.HRef.fromString(urljoin(ownerHomeURL, jsondata[&quot;name&quot;])),
-                            ),
-                            customxml.InReplyTo.fromString(jsondata[&quot;in-reply-to&quot;]),
-                        ) + ((customxml.InviteSummary.fromString(jsondata[&quot;summary&quot;]),) if jsondata[&quot;summary&quot;] else ())
-                          + ((customxml.CommonName.fromString(commonName),) if commonName else ())
-                          + ((customxml.FirstNameProperty(record.firstName),) if record.firstName else ())
-                          + ((customxml.LastNameProperty(record.lastName),) if record.lastName else ())
-                    )
</del><ins>+                    element.HRef.fromString(cua),
+                    invitationBindStatusToXMLMap[jsondata[&quot;status&quot;]](),
+                    customxml.HostURL(
+                        element.HRef.fromString(urljoin(ownerHomeURL, jsondata[&quot;ownerName&quot;])),
+                    ),
+                    customxml.InReplyTo.fromString(jsondata[&quot;in-reply-to&quot;]),
+                    customxml.InviteSummary.fromString(jsondata[&quot;summary&quot;]) if jsondata[&quot;summary&quot;] else None,
+                    customxml.CommonName.fromString(commonName) if commonName else None,
+                    customxml.FirstNameProperty(record.firstName) if record.firstName else None,
+                    customxml.LastNameProperty(record.lastName) if record.lastName else None,
+                    #**typeAttr
</ins><span class="cx">                 ),
</span><span class="cx">             )
</span><span class="cx">         else:
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretwistedcaldavtesttest_sharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/test/test_sharing.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/test/test_sharing.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/twistedcaldav/test/test_sharing.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -52,8 +52,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> class FakeHome(object):
</span><del>-    def removeShareByUID(self, request, uid):
-        pass
</del><ins>+    pass
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavbasedatastoreutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/base/datastore/util.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/base/datastore/util.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/base/datastore/util.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -95,7 +95,7 @@
</span><span class="cx">     # Home child objects by id
</span><span class="cx"> 
</span><span class="cx">     def keyForObjectWithResourceID(self, homeResourceID, resourceID):
</span><del>-        return &quot;objectWithName:%s:%s&quot; % (homeResourceID, resourceID)
</del><ins>+        return &quot;objectWithResourceID:%s:%s&quot; % (homeResourceID, resourceID)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     # Home metadata (Created/Modified)
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/sql.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/sql.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/sql.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -14,6 +14,7 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><ins>+from txdav.xml import element
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="lines">@@ -396,6 +397,8 @@
</span><span class="cx"> 
</span><span class="cx">     implements(ICalendarHome)
</span><span class="cx"> 
</span><ins>+    _homeType = ECALENDARTYPE
+
</ins><span class="cx">     # structured tables.  (new, preferred)
</span><span class="cx">     _homeSchema = schema.CALENDAR_HOME
</span><span class="cx">     _bindSchema = schema.CALENDAR_BIND
</span><span class="lines">@@ -1245,6 +1248,44 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def sharedResourceType(self):
+        &quot;&quot;&quot;
+        The sharing resource type
+        &quot;&quot;&quot;
+        return &quot;calendar&quot;
+
+
+    @inlineCallbacks
+    def newShare(self, displayname=None):
+        &quot;&quot;&quot;
+        Override in derived classes to do any specific operations needed when a share
+        is first accepted.
+        &quot;&quot;&quot;
+
+        # For a direct share we will copy any displayname and calendar-color over using the owners view
+        if self.direct():
+            ownerView = yield self.ownerView()
+            try:
+                displayname = ownerView.properties()[PropertyName.fromElement(element.DisplayName)]
+                self.properties()[PropertyName.fromElement(element.DisplayName)] = displayname
+            except KeyError:
+                pass
+            try:
+                color = ownerView.properties()[PropertyName.fromElement(customxml.CalendarColor)]
+                self.properties()[PropertyName.fromElement(customxml.CalendarColor)] = color
+            except KeyError:
+                pass
+        elif displayname:
+            self.properties()[PropertyName.fromElement(element.DisplayName)] = element.DisplayName.fromString(displayname)
+
+        # Calendars always start out transparent and with empty default alarms
+        yield self.setUsedForFreeBusy(False)
+        yield self.setDefaultAlarm(&quot;empty&quot;, True, True)
+        yield self.setDefaultAlarm(&quot;empty&quot;, True, False)
+        yield self.setDefaultAlarm(&quot;empty&quot;, False, True)
+        yield self.setDefaultAlarm(&quot;empty&quot;, False, False)
+
+
</ins><span class="cx">     # FIXME: this is DAV-ish.  Data store calendar objects don't have
</span><span class="cx">     # mime types.  -wsv
</span><span class="cx">     def contentType(self):
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretestcommonpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/common.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -41,7 +41,6 @@
</span><span class="cx"> from txdav.common.icommondatastore import ObjectResourceNameAlreadyExistsError
</span><span class="cx"> from txdav.common.inotifications import INotificationObject
</span><span class="cx"> from txdav.common.datastore.test.util import CommonCommonTests
</span><del>-from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE, _BIND_MODE_READ
</del><span class="cx"> 
</span><span class="cx"> from txdav.caldav.icalendarstore import (
</span><span class="cx">     ICalendarObject, ICalendarHome,
</span><span class="lines">@@ -974,156 +973,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def test_shareWith(self):
-        &quot;&quot;&quot;
-        L{ICalendar.shareWith} will share a calendar with a given home UID.
-        &quot;&quot;&quot;
-        cal = yield self.calendarUnderTest()
-        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)
-        otherCal = yield otherHome.childWithName(newCalName)
-        self.assertNotIdentical(otherCal, None)
-        self.assertEqual(
-            (yield
-             (yield otherCal.calendarObjectWithName(&quot;1.ics&quot;)).component()),
-            (yield
-             (yield normalCal.calendarObjectWithName(&quot;1.ics&quot;)).component())
-        )
-
-
-    @inlineCallbacks
-    def test_shareAgainChangesMode(self):
-        &quot;&quot;&quot;
-        If a calendar is already shared with a given calendar home,
-        L{ICalendar.shareWith} will change the sharing mode.
-        &quot;&quot;&quot;
-        yield self.test_shareWith()
-        # yield self.commit() # txn is none? why?
-        cal = yield self.calendarUnderTest()
-        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        newName = yield cal.shareWith(other, _BIND_MODE_READ)
-        otherCal = yield other.childWithName(self.sharedName)
-
-        # Name should not change just because we updated the mode.
-        self.assertEqual(newName, self.sharedName)
-        self.assertNotIdentical(otherCal, None)
-
-        invitedCals = yield cal.sharingInvites()
-        self.assertEqual(len(invitedCals), 1)
-        self.assertEqual(invitedCals[0].mode(), _BIND_MODE_READ)
-
-
-    @inlineCallbacks
-    def test_unshareWith(self, commit=False):
-        &quot;&quot;&quot;
-        L{ICalendar.unshareWith} will remove a previously-shared calendar from
-        another user's calendar home.
-        &quot;&quot;&quot;
-        yield self.test_shareWith()
-        if commit:
-            yield self.commit()
-        cal = yield self.calendarUnderTest()
-        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        newName = yield cal.unshareWith(other)
-        otherCal = yield other.childWithName(newName)
-        self.assertIdentical(otherCal, None)
-        invitedCals = yield cal.sharingInvites()
-        self.assertEqual(len(invitedCals), 0)
-
-
-    @inlineCallbacks
-    def test_unshareSharerSide(self, commit=False):
-        &quot;&quot;&quot;
-        Verify the coll.unshare( ) method works when called from the
-        sharer's copy
-        &quot;&quot;&quot;
-        yield self.test_shareWith()
-        if commit:
-            yield self.commit()
-        cal = yield self.calendarUnderTest()
-        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        otherCal = yield other.childWithName(self.sharedName)
-        self.assertNotEqual(otherCal, None)
-        yield cal.unshare()
-        otherCal = yield other.childWithName(self.sharedName)
-        self.assertEqual(otherCal, None)
-        invitedCals = yield cal.sharingInvites()
-        self.assertEqual(len(invitedCals), 0)
-
-
-    @inlineCallbacks
-    def test_unshareShareeSide(self, commit=False):
-        &quot;&quot;&quot;
-        Verify the coll.unshare( ) method works when called from the
-        sharee's copy
-        &quot;&quot;&quot;
-        yield self.test_shareWith()
-        if commit:
-            yield self.commit()
-        cal = yield self.calendarUnderTest()
-        other = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        otherCal = yield other.childWithName(self.sharedName)
-        self.assertNotEqual(otherCal, None)
-        yield otherCal.unshare()
-        otherCal = yield other.childWithName(self.sharedName)
-        self.assertEqual(otherCal, None)
-        invitedCals = yield cal.sharingInvites()
-        self.assertEqual(len(invitedCals), 0)
-
-
-    @inlineCallbacks
-    def test_unshareWithInDifferentTransaction(self):
-        &quot;&quot;&quot;
-        L{ICalendar.unshareWith} will remove a previously-shared calendar from
-        another user's calendar home, assuming the sharing was committed in a
-        previous transaction.
-        &quot;&quot;&quot;
-        yield self.test_unshareWith(True)
-
-
-    @inlineCallbacks
-    def test_sharingInvites(self):
-        &quot;&quot;&quot;
-        L{ICalendar.sharingInvites} returns an iterable of all versions of a shared
-        calendar.
-        &quot;&quot;&quot;
-        cal = yield self.calendarUnderTest()
-        sharedBefore = yield cal.sharingInvites()
-        # It's not shared yet; make sure sharingInvites doesn't include owner version.
-        self.assertEqual(len(sharedBefore), 0)
-        yield self.test_shareWith()
-        # FIXME: don't know why this separate transaction is needed; remove it.
-        yield self.commit()
-        cal = yield self.calendarUnderTest()
-        sharedAfter = yield cal.sharingInvites()
-        self.assertEqual(len(sharedAfter), 1)
-        self.assertEqual(sharedAfter[0].mode(), _BIND_MODE_WRITE)
-        self.assertEqual(sharedAfter[0].shareeUID(), OTHER_HOME_UID)
-
-
-    @inlineCallbacks
-    def test_sharedNotifierID(self):
-        yield self.test_shareWith()
-        yield self.commit()
-
-        home = yield self.homeUnderTest()
-        self.assertEquals(home.notifierID(), (&quot;CalDAV&quot;, &quot;home1&quot;,))
-        calendar = yield home.calendarWithName(&quot;calendar_1&quot;)
-        self.assertEquals(calendar.notifierID(), (&quot;CalDAV&quot;, &quot;home1/calendar_1&quot;,))
-        yield self.commit()
-
-        home = yield self.homeUnderTest(name=OTHER_HOME_UID)
-        self.assertEquals(home.notifierID(), (&quot;CalDAV&quot;, OTHER_HOME_UID,))
-        calendar = yield home.calendarWithName(self.sharedName)
-        self.assertEquals(calendar.notifierID(), (&quot;CalDAV&quot;, &quot;home1/calendar_1&quot;,))
-        yield self.commit()
-
-
-    @inlineCallbacks
</del><span class="cx">     def test_hasCalendarResourceUIDSomewhereElse(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         L{ICalendarHome.hasCalendarResourceUIDSomewhereElse} will determine if
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -952,13 +952,13 @@
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def _defer1():
</span><del>-            yield cal1.shareWith(shareeHome=sharerHome1, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message=&quot;Shared Wiki Calendar&quot;)
</del><ins>+            yield cal1.shareWith(shareeHome=sharerHome1, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, summary=&quot;Shared Wiki Calendar&quot;)
</ins><span class="cx">             yield txn1.commit()
</span><span class="cx">         d1 = _defer1()
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def _defer2():
</span><del>-            yield cal2.shareWith(shareeHome=sharerHome2, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message=&quot;Shared Wiki Calendar&quot;)
</del><ins>+            yield cal2.shareWith(shareeHome=sharerHome2, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, summary=&quot;Shared Wiki Calendar&quot;)
</ins><span class="cx">             yield txn2.commit()
</span><span class="cx">         d2 = _defer2()
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcaldavdatastoretesttest_sql_sharingpy"></a>
<div class="addfile"><h4>Added: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql_sharing.py (0 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql_sharing.py                                (rev 0)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/caldav/datastore/test/test_sql_sharing.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -0,0 +1,433 @@
</span><ins>+##
+# Copyright (c) 2005-2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.trial.unittest import TestCase
+
+from twext.python.clsprop import classproperty
+from txdav.common.datastore.test.util import CommonCommonTests, \
+    populateCalendarsFrom
+from txdav.caldav.datastore.test.util import buildCalendarStore
+from txdav.common.datastore.sql_tables import _BIND_MODE_READ, \
+    _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED
+
+
+class CalendarSharing(CommonCommonTests, TestCase):
+    &quot;&quot;&quot;
+    Test twistedcaldav.scheduyling.implicit with a Request object.
+    &quot;&quot;&quot;
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(CalendarSharing, self).setUp()
+        self._sqlCalendarStore = yield buildCalendarStore(self, self.notifierFactory)
+        yield self.populate()
+
+
+    @inlineCallbacks
+    def populate(self):
+        yield populateCalendarsFrom(self.requirements, self.storeUnderTest())
+        self.notifierFactory.reset()
+
+
+    @classproperty(cache=False)
+    def requirements(cls): #@NoSelf
+        return {
+        &quot;user01&quot;: {
+            &quot;calendar&quot;: {
+            },
+            &quot;inbox&quot;: {
+            },
+        },
+        &quot;user02&quot;: {
+            &quot;calendar&quot;: {
+            },
+            &quot;inbox&quot;: {
+            },
+        },
+        &quot;user03&quot;: {
+            &quot;calendar&quot;: {
+            },
+            &quot;inbox&quot;: {
+            },
+        },
+    }
+
+
+    def storeUnderTest(self):
+        &quot;&quot;&quot;
+        Create and return a L{CalendarStore} for testing.
+        &quot;&quot;&quot;
+        return self._sqlCalendarStore
+
+
+    @inlineCallbacks
+    def _createShare(self):
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        inviteUID = shareeView.shareUID()
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        shareeView = yield shareeHome.acceptShare(inviteUID)
+        sharedName = shareeView.name()
+        yield self.commit()
+
+        returnValue(sharedName)
+
+
+    @inlineCallbacks
+    def test_no_shares(self):
+        &quot;&quot;&quot;
+        Test that initially there are no shares.
+        &quot;&quot;&quot;
+
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+
+    @inlineCallbacks
+    def test_invite_sharee(self):
+        &quot;&quot;&quot;
+        Test invite/uninvite creates/removes shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        self.assertEqual(invites[0].uid, shareeView.shareUID())
+        self.assertEqual(invites[0].ownerUID, &quot;user01&quot;)
+        self.assertEqual(invites[0].shareeUID, &quot;user02&quot;)
+        self.assertEqual(invites[0].shareeName, shareeView.name())
+        self.assertEqual(invites[0].mode, _BIND_MODE_READ)
+        self.assertEqual(invites[0].status, _BIND_STATUS_INVITED)
+        self.assertEqual(invites[0].summary, &quot;summary&quot;)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID, ])
+
+        yield self.commit()
+
+        # Uninvite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+
+        yield calendar.uninviteUserFromShare(&quot;user02&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [])
+
+
+    @inlineCallbacks
+    def test_accept_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept creates shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Re-accept
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_decline_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept creates shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Decline
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.declineShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Redecline
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.declineShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_accept_decline_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept/decline creates/removes shares and notifications.
+        Decline via the home.
+        &quot;&quot;&quot;
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Decline
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.declineShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_accept_remove_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept/decline creates/removes shares and notifications.
+        Decline via the shared collection (removal).
+        &quot;&quot;&quot;
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.homeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Delete
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        yield shared.deleteShare()
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_inviteProperties(self):
+
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        yield calendar.setUsedForFreeBusy(True)
+        yield self.commit()
+
+        shared_name = yield self._createShare()
+
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=shared_name)
+        self.assertFalse(shared.isUsedForFreeBusy())
+
+
+    @inlineCallbacks
+    def test_direct_sharee(self):
+        &quot;&quot;&quot;
+        Test invite/uninvite creates/removes shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield calendar.directShareWithUser(&quot;user02&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        self.assertEqual(invites[0].uid, shareeView.shareUID())
+        self.assertEqual(invites[0].ownerUID, &quot;user01&quot;)
+        self.assertEqual(invites[0].shareeUID, &quot;user02&quot;)
+        self.assertEqual(invites[0].shareeName, shareeView.name())
+        self.assertEqual(invites[0].mode, _BIND_MODE_DIRECT)
+        self.assertEqual(invites[0].status, _BIND_STATUS_ACCEPTED)
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 0)
+
+        yield self.commit()
+
+        # Remove
+        shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
+        yield shared.deleteShare()
+
+        calendar = yield self.calendarUnderTest(home=&quot;user01&quot;, name=&quot;calendar&quot;)
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 0)
+
+
+    @inlineCallbacks
+    def test_sharedNotifierID(self):
+        shared_name = yield self._createShare()
+
+        home = yield self.homeUnderTest(name=&quot;user01&quot;)
+        self.assertEquals(home.notifierID(), (&quot;CalDAV&quot;, &quot;user01&quot;,))
+        calendar = yield home.calendarWithName(&quot;calendar&quot;)
+        self.assertEquals(calendar.notifierID(), (&quot;CalDAV&quot;, &quot;user01/calendar&quot;,))
+        yield self.commit()
+
+        home = yield self.homeUnderTest(name=&quot;user02&quot;)
+        self.assertEquals(home.notifierID(), (&quot;CalDAV&quot;, &quot;user02&quot;,))
+        calendar = yield home.calendarWithName(shared_name)
+        self.assertEquals(calendar.notifierID(), (&quot;CalDAV&quot;, &quot;user01/calendar&quot;,))
+        yield self.commit()
</ins></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/sql.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/sql.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/sql.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -61,8 +61,6 @@
</span><span class="cx">     InvalidObjectResourceError, InvalidComponentForStoreError, \
</span><span class="cx">     AllRetriesFailed, ObjectResourceNameAlreadyExistsError
</span><span class="cx"> 
</span><del>-from uuid import uuid4
-
</del><span class="cx"> from zope.interface.declarations import implements
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -70,6 +68,8 @@
</span><span class="cx"> 
</span><span class="cx">     implements(IAddressBookHome)
</span><span class="cx"> 
</span><ins>+    _homeType = EADDRESSBOOKTYPE
+
</ins><span class="cx">     # structured tables.  (new, preferred)
</span><span class="cx">     _homeSchema = schema.ADDRESSBOOK_HOME
</span><span class="cx">     _bindSchema = schema.SHARED_ADDRESSBOOK_BIND
</span><span class="lines">@@ -217,32 +217,6 @@
</span><span class="cx">         return self._addressbook
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareeAddressBookName(self):
-        return self.uid()
-
-
-    def objectWithShareUID(self, shareUID):
-        &quot;&quot;&quot;
-        Retrieve the child with the given bind identifier contained in this
-        home.
-
-        @param name: a string.
-        @return: an L{ICalendar} or C{None} if no such child exists.
-        &quot;&quot;&quot;
-        return self._childClass.objectWithBindName(self, shareUID, accepted=True)
-
-
-    def invitedObjectWithShareUID(self, shareUID):
-        &quot;&quot;&quot;
-        Retrieve the child invitation with the given bind identifier contained in this
-        home.
-
-        @param name: a string.
-        @return: an L{ICalendar} or C{None} if no such child exists.
-        &quot;&quot;&quot;
-        return self._childClass.objectWithBindName(self, shareUID, accepted=False)
-
-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def ownerHomeWithChildID(self, resourceID):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -344,20 +318,6 @@
</span><span class="cx">         Sharing code shared between AddressBook and AddressBookObject
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-    def setShared(self, shared):
-        &quot;&quot;&quot;
-        Set an owned collection to shared or unshared state. Technically this is not useful as &quot;shared&quot;
-        really means it has invitees, but the current sharing spec supports a notion of a shared collection
-        that has not yet had invitees added. For the time being we will support that option by using a new
-        MESSAGE value to indicate an owned collection that is &quot;shared&quot;.
-
-        @param shared: whether or not the owned collection is &quot;shared&quot;
-        @type shared: C{bool}
-        &quot;&quot;&quot;
-        if self.owned():
-            self._bindMessage = &quot;shared&quot; if shared else None
-
-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _isSharedOrInvited(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -396,11 +356,10 @@
</span><span class="cx">     _objectSchema = schema.ADDRESSBOOK_OBJECT
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def __init__(self, home, name, resourceID, mode, status, revision=0, message=None, ownerHome=None, bindName=None):
</del><ins>+    def __init__(self, home, name, resourceID, mode, status, revision=0, message=None, ownerHome=None):
</ins><span class="cx">         ownerName = ownerHome.addressbook().name() if ownerHome else None
</span><span class="cx">         super(AddressBook, self).__init__(home, name, resourceID, mode, status, revision=revision, message=message, ownerHome=ownerHome, ownerName=ownerName)
</span><span class="cx">         self._index = PostgresLegacyABIndexEmulator(self)
</span><del>-        self._bindName = bindName
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def __repr__(self):
</span><span class="lines">@@ -435,21 +394,13 @@
</span><span class="cx">     addressbookObjectsSinceToken = CommonHomeChild.objectResourcesSinceToken
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareeName(self):
</del><ins>+    def newShareName(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        The sharee's name for a shared address book is the sharer's home ownerUID.
</del><ins>+        For shared address books the resource name of a share is the ownerUID of the owner's resource.
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        return self.ownerHome().shareeAddressBookName()
</del><ins>+        return self.ownerHome().uid()
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def bindNameIsResourceName(self):
-        &quot;&quot;&quot;
-        For shared address books the resource name of an accepted share is not the same as the name
-        in the bind table.
-        &quot;&quot;&quot;
-        return False
-
-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _loadPropertyStore(self, props=None):
</span><span class="cx">         if props is None:
</span><span class="lines">@@ -475,6 +426,13 @@
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def sharedResourceType(self):
+        &quot;&quot;&quot;
+        The sharing resource type
+        &quot;&quot;&quot;
+        return &quot;addressbook&quot;
+
+
</ins><span class="cx">     def contentType(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         The content type of addressbook objects is text/vcard.
</span><span class="lines">@@ -609,7 +567,7 @@
</span><span class="cx">     @inlineCallbacks
</span><span class="cx">     def _groupForSharedAddressBookComponent(self):
</span><span class="cx"> 
</span><del>-        n = self.shareeName()
</del><ins>+        n = self.name()
</ins><span class="cx">         fn = n
</span><span class="cx">         uid = self._groupForSharedAddressBookUID()
</span><span class="cx"> 
</span><span class="lines">@@ -677,7 +635,7 @@
</span><span class="cx">         )
</span><span class="cx">         # get ownerHomeIDs
</span><span class="cx">         for dataRow in dataRows:
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = dataRow[:cls.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = dataRow[:cls.bindColumnCount] #@UnusedVariable
</ins><span class="cx">             ownerHome = yield home.ownerHomeWithChildID(resourceID)
</span><span class="cx">             ownerHomeToDataRowMap[ownerHome] = dataRow
</span><span class="cx"> 
</span><span class="lines">@@ -686,12 +644,12 @@
</span><span class="cx">             home._txn, homeID=home._resourceID
</span><span class="cx">         )
</span><span class="cx">         for groupBindRow in groupBindRows:
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx">             ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
</span><span class="cx">             ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
</span><span class="cx">             if ownerHome not in ownerHomeToDataRowMap:
</span><span class="cx">                 groupBindRow[0] = _BIND_MODE_WRITE
</span><del>-                groupBindRow[3] = None  # bindName
</del><ins>+                groupBindRow[3] = None  # name
</ins><span class="cx">                 groupBindRow[4] = None  # bindStatus
</span><span class="cx">                 groupBindRow[6] = None  # bindMessage
</span><span class="cx">                 ownerHomeToDataRowMap[ownerHome] = groupBindRow
</span><span class="lines">@@ -709,18 +667,19 @@
</span><span class="cx"> 
</span><span class="cx">             # Create the actual objects merging in properties
</span><span class="cx">             for ownerHome, dataRow in ownerHomeToDataRowMap.iteritems():
</span><del>-                bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = dataRow[:cls.bindColumnCount] #@UnusedVariable
</del><ins>+                bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = dataRow[:cls.bindColumnCount] #@UnusedVariable
</ins><span class="cx">                 additionalBind = dataRow[cls.bindColumnCount:cls.bindColumnCount + len(cls.additionalBindColumns())]
</span><span class="cx">                 metadata = dataRow[cls.bindColumnCount + len(cls.additionalBindColumns()):]
</span><span class="cx"> 
</span><span class="cx">                 child = cls(
</span><span class="cx">                     home=home,
</span><del>-                    name=ownerHome.shareeAddressBookName(),
</del><ins>+                    name=name,
</ins><span class="cx">                     resourceID=ownerHome._resourceID,
</span><del>-                    mode=bindMode, status=bindStatus,
</del><ins>+                    mode=bindMode,
+                    status=bindStatus,
</ins><span class="cx">                     revision=bindRevision,
</span><del>-                    message=bindMessage, ownerHome=ownerHome,
-                    bindName=bindName
</del><ins>+                    message=bindMessage,
+                    ownerHome=ownerHome,
</ins><span class="cx">                 )
</span><span class="cx"> 
</span><span class="cx">                 for attr, value in zip(cls.additionalBindAttributes(), additionalBind):
</span><span class="lines">@@ -764,9 +723,7 @@
</span><span class="cx">         if queryCacher:
</span><span class="cx">             # Retrieve data from cache
</span><span class="cx">             cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
</span><del>-            cachedRows = yield queryCacher.get(cacheKey)
-            if cachedRows and (cachedRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-                rows = cachedRows
</del><ins>+            rows = yield queryCacher.get(cacheKey)
</ins><span class="cx"> 
</span><span class="cx">         if not rows:
</span><span class="cx">             # name must be a home uid
</span><span class="lines">@@ -777,7 +734,7 @@
</span><span class="cx">                 bindRows = yield cls._bindForResourceIDAndHomeID.on(
</span><span class="cx">                     home._txn, resourceID=ownerAddressBook._resourceID, homeID=home._resourceID
</span><span class="cx">                 )
</span><del>-                if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
</del><ins>+                if bindRows:
</ins><span class="cx">                     bindRows[0].insert(cls.bindColumnCount, ownerAddressBook._resourceID)
</span><span class="cx">                     bindRows[0].insert(cls.bindColumnCount + 1, bindRows[0][4])  # cachedStatus = bindStatus
</span><span class="cx">                     rows = bindRows
</span><span class="lines">@@ -786,15 +743,14 @@
</span><span class="cx">                             home._txn, homeID=home._resourceID, addressbookID=ownerAddressBook._resourceID
</span><span class="cx">                     )
</span><span class="cx">                     for groupBindRow in groupBindRows:
</span><del>-                        if (groupBindRow[4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-                            groupBindRow.insert(AddressBookObject.bindColumnCount, ownerAddressBook._resourceID)
-                            groupBindRow.insert(AddressBookObject.bindColumnCount + 1, groupBindRow[4])
-                            groupBindRow[0] = _BIND_MODE_WRITE
-                            groupBindRow[3] = None  # bindName
-                            groupBindRow[4] = None  # bindStatus
-                            groupBindRow[6] = None  # bindMessage
-                            rows = [groupBindRow]
-                            break
</del><ins>+                        groupBindRow.insert(AddressBookObject.bindColumnCount, ownerAddressBook._resourceID)
+                        groupBindRow.insert(AddressBookObject.bindColumnCount + 1, groupBindRow[4])
+                        groupBindRow[0] = _BIND_MODE_WRITE
+                        groupBindRow[3] = ownerHome.uid()  # bindName
+                        groupBindRow[4] = None  # bindStatus
+                        groupBindRow[6] = None  # bindMessage
+                        rows = [groupBindRow]
+                        break
</ins><span class="cx"> 
</span><span class="cx">             if rows and queryCacher:
</span><span class="cx">                 # Cache the result
</span><span class="lines">@@ -804,20 +760,22 @@
</span><span class="cx">             returnValue(None)
</span><span class="cx"> 
</span><span class="cx">         row = rows[0]
</span><del>-        bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage, ownerAddressBookID, cachedBindStatus = row[:cls.bindColumnCount + 2] #@UnusedVariable
</del><ins>+        bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage, ownerAddressBookID, cachedBindStatus = row[:cls.bindColumnCount + 2] #@UnusedVariable
</ins><span class="cx"> 
</span><span class="cx">         # if wrong status, exit here.  Item is in queryCache
</span><del>-        if (cachedBindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
</del><ins>+        if accepted is not None and (cachedBindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
</ins><span class="cx">             returnValue(None)
</span><span class="cx"> 
</span><span class="cx">         ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
</span><span class="cx">         child = cls(
</span><span class="cx">                 home=home,
</span><del>-                name=ownerHome.shareeAddressBookName(), resourceID=ownerAddressBookID,
-                mode=bindMode, status=bindStatus,
</del><ins>+                name=name,
+                resourceID=ownerAddressBookID,
+                mode=bindMode,
+                status=bindStatus,
</ins><span class="cx">                 revision=bindRevision,
</span><del>-                message=bindMessage, ownerHome=ownerHome,
-                bindName=bindName,
</del><ins>+                message=bindMessage,
+                ownerHome=ownerHome,
</ins><span class="cx">             )
</span><span class="cx">         yield child.initFromStore()
</span><span class="cx">         returnValue(child)
</span><span class="lines">@@ -825,57 +783,6 @@
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><span class="cx">     @inlineCallbacks
</span><del>-    def objectWithBindName(cls, home, name, accepted):
-        &quot;&quot;&quot;
-        Retrieve the child or objectResource with the given bind name C{name} contained in the given
-        C{home}.
-
-        @param home: a L{CommonHome}.
-
-        @param name: a string; the name of the L{CommonHomeChild} to retrieve.
-
-        @return: an L{CommonHomeChild} or L{ObjectResource} or C{None} if no such child
-            exists.
-        &quot;&quot;&quot;
-        bindRows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
-        if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-            bindRow = bindRows[0]
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
-
-            # alt:
-            # returnValue((yield cls.objectWithID(home, resourceID)))
-            ownerHome = yield home.ownerHomeWithChildID(resourceID)
-            if accepted:
-                returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
-            else:
-                returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
-
-        groupBindRows = yield AddressBookObject._bindForNameAndHomeID.on(
-            home._txn, name=name, homeID=home._resourceID
-        )
-        if groupBindRows and (groupBindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
-            groupBindRow = groupBindRows[0]
-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
-
-            ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
-            # alt:
-            # addressbook = yield cls.objectWithID(home, ownerAddressBookID)
-            ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
-            addressbook = yield home.childWithName(ownerHome.shareeAddressBookName())
-            if not addressbook:
-                addressbook = yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)
-                assert addressbook
-
-            if accepted:
-                returnValue((yield addressbook.objectResourceWithID(resourceID)))
-            else:
-                returnValue((yield AddressBookObject.objectWithID(addressbook, resourceID)))  # avoids object cache
-
-        returnValue(None)
-
-
-    @classmethod
-    @inlineCallbacks
</del><span class="cx">     def objectWithID(cls, home, resourceID, accepted=True):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Retrieve the child with the given C{resourceID} contained in the given
</span><span class="lines">@@ -892,40 +799,39 @@
</span><span class="cx">         bindRows = yield cls._bindForResourceIDAndHomeID.on(
</span><span class="cx">             home._txn, resourceID=resourceID, homeID=home._resourceID
</span><span class="cx">         )
</span><del>-        if bindRows and (bindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
</del><ins>+        if bindRows:
</ins><span class="cx">             bindRow = bindRows[0]
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = bindRow[:cls.bindColumnCount] #@UnusedVariable
</ins><span class="cx"> 
</span><ins>+            if accepted is not None and (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+                returnValue(None)
+
</ins><span class="cx">             ownerHome = yield home.ownerHomeWithChildID(resourceID)
</span><del>-            if accepted:
-                returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
</del><ins>+            if bindStatus == _BIND_STATUS_ACCEPTED:
+                returnValue((yield home.childWithName(ownerHome.uid())))
</ins><span class="cx">             else:
</span><del>-                returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
</del><ins>+                returnValue((yield cls.objectWithName(home, ownerHome.uid(), accepted=False)))
</ins><span class="cx"> 
</span><span class="cx">         groupBindRows = yield AddressBookObject._bindForHomeIDAndAddressBookID.on(
</span><span class="cx">                     home._txn, homeID=home._resourceID, addressbookID=resourceID
</span><span class="cx">         )
</span><del>-        if groupBindRows and (groupBindRows[0][4] == _BIND_STATUS_ACCEPTED) == bool(accepted):
</del><ins>+        if groupBindRows:
</ins><span class="cx">             groupBindRow = groupBindRows[0]
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx"> 
</span><ins>+            if accepted is not None and (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
+                returnValue(None)
+
</ins><span class="cx">             ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
</span><span class="cx">             ownerHome = yield home.ownerHomeWithChildID(ownerAddressBookID)
</span><del>-            if accepted:
-                returnValue((yield home.childWithName(ownerHome.shareeAddressBookName())))
</del><ins>+            if bindStatus == _BIND_STATUS_ACCEPTED:
+                returnValue((yield home.childWithName(ownerHome.uid())))
</ins><span class="cx">             else:
</span><del>-                returnValue((yield cls.objectWithName(home, ownerHome.shareeAddressBookName(), accepted=False)))
</del><ins>+                returnValue((yield cls.objectWithName(home, ownerHome.uid(), accepted=False)))
</ins><span class="cx"> 
</span><span class="cx">         returnValue(None)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareUID(self):
-        &quot;&quot;&quot;
-        @see: L{ICalendar.shareUID}
-        &quot;&quot;&quot;
-        return self._bindName
-
-
</del><span class="cx">     def fullyShared(self):
</span><span class="cx">         return not self.owned() and self._bindStatus == _BIND_STATUS_ACCEPTED
</span><span class="cx"> 
</span><span class="lines">@@ -944,18 +850,18 @@
</span><span class="cx">             home._txn, homeID=home._resourceID
</span><span class="cx">         )
</span><span class="cx">         for row in rows:
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
</ins><span class="cx">             ownerHome = yield home._txn.homeWithResourceID(home._homeType, resourceID, create=True)
</span><del>-            names |= set([ownerHome.shareeAddressBookName()])
</del><ins>+            names |= set([ownerHome.uid()])
</ins><span class="cx"> 
</span><span class="cx">         groupRows = yield AddressBookObject._acceptedBindForHomeID.on(
</span><span class="cx">             home._txn, homeID=home._resourceID
</span><span class="cx">         )
</span><span class="cx">         for groupRow in groupRows:
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx">             ownerAddressBookID = yield AddressBookObject.ownerAddressBookIDFromGroupID(home._txn, resourceID)
</span><span class="cx">             ownerHome = yield home._txn.homeWithResourceID(home._homeType, ownerAddressBookID, create=True)
</span><del>-            names |= set([ownerHome.shareeAddressBookName()])
</del><ins>+            names |= set([ownerHome.uid()])
</ins><span class="cx">         returnValue(tuple(names))
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -1023,7 +929,7 @@
</span><span class="cx">             readWriteGroupIDs = []
</span><span class="cx">             readOnlyGroupIDs = []
</span><span class="cx">             for groupBindRow in groupBindRows:
</span><del>-                bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+                bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx">                 if bindMode == _BIND_MODE_WRITE:
</span><span class="cx">                     readWriteGroupIDs.append(resourceID)
</span><span class="cx">                 else:
</span><span class="lines">@@ -1071,7 +977,7 @@
</span><span class="cx">         readWriteGroupIDs = []
</span><span class="cx">         readOnlyGroupIDs = []
</span><span class="cx">         for groupBindRow in groupBindRows:
</span><del>-            bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</del><ins>+            bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = groupBindRow[:AddressBookObject.bindColumnCount] #@UnusedVariable
</ins><span class="cx">             if bindMode == _BIND_MODE_WRITE:
</span><span class="cx">                 readWriteGroupIDs.append(resourceID)
</span><span class="cx">             else:
</span><span class="lines">@@ -1105,7 +1011,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def updateShare(self, shareeView, mode=None, status=None, message=None):
</del><ins>+    def updateShare(self, shareeView, mode=None, status=None, summary=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Update share mode, status, and message for a home child shared with
</span><span class="cx">         this (owned) L{CommonHomeChild}.
</span><span class="lines">@@ -1122,9 +1028,9 @@
</span><span class="cx">             L{_BIND_STATUS_INVALID}  or None to not update
</span><span class="cx">         @type status: L{str}
</span><span class="cx"> 
</span><del>-        @param message: The proposed message to go along with the share, which
</del><ins>+        @param summary: The proposed message to go along with the share, which
</ins><span class="cx">             will be used as the default display name, or None to not update
</span><del>-        @type message: L{str}
</del><ins>+        @type summary: L{str}
</ins><span class="cx"> 
</span><span class="cx">         @return: the name of the shared item in the sharee's home.
</span><span class="cx">         @rtype: a L{Deferred} which fires with a L{str}
</span><span class="lines">@@ -1137,7 +1043,7 @@
</span><span class="cx">         columnMap = dict([(k, v if v != &quot;&quot; else None)
</span><span class="cx">                           for k, v in {bind.BIND_MODE:mode,
</span><span class="cx">                             bind.BIND_STATUS:status,
</span><del>-                            bind.MESSAGE:message}.iteritems() if v is not None])
</del><ins>+                            bind.MESSAGE:summary}.iteritems() if v is not None])
</ins><span class="cx"> 
</span><span class="cx">         if len(columnMap):
</span><span class="cx"> 
</span><span class="lines">@@ -1163,21 +1069,23 @@
</span><span class="cx">                     if 0 == previouslyAcceptedBindCount:
</span><span class="cx">                         yield shareeView._initSyncToken()
</span><span class="cx">                         yield shareeView._initBindRevision()
</span><del>-                        shareeView.viewerHome()._children[self.shareeName()] = shareeView
</del><ins>+                        shareeView.viewerHome()._children[shareeView._name] = shareeView
</ins><span class="cx">                         shareeView.viewerHome()._children[shareeView._resourceID] = shareeView
</span><span class="cx">                 elif shareeView._bindStatus == _BIND_STATUS_DECLINED:
</span><span class="cx">                     if 1 == previouslyAcceptedBindCount:
</span><span class="cx">                         yield shareeView._deletedSyncToken(sharedRemoval=True)
</span><del>-                        shareeView.viewerHome()._children.pop(self.shareeName(), None)
</del><ins>+                        shareeView.viewerHome()._children.pop(shareeView._name, None)
</ins><span class="cx">                         shareeView.viewerHome()._children.pop(shareeView._resourceID, None)
</span><span class="cx"> 
</span><del>-            if message is not None:
</del><ins>+            if summary is not None:
</ins><span class="cx">                 shareeView._bindMessage = columnMap[bind.MESSAGE]
</span><span class="cx"> 
</span><span class="cx">             queryCacher = self._txn._queryCacher
</span><span class="cx">             if queryCacher:
</span><del>-                cacheKey = queryCacher.keyForObjectWithName(shareeView.viewerHome()._resourceID, self.shareeName())
-                queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</del><ins>+                cacheKey = queryCacher.keyForObjectWithName(shareeView._home._resourceID, shareeView._name)
+                yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
+                cacheKey = queryCacher.keyForObjectWithResourceID(shareeView._home._resourceID, shareeView._resourceID)
+                yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</ins><span class="cx"> 
</span><span class="cx">             shareeView._name = bindNameRows[0][0]
</span><span class="cx"> 
</span><span class="lines">@@ -1188,22 +1096,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def shareWith(self, shareeHome, mode, status=None, message=None):
-        &quot;&quot;&quot;
-            call super and set isShared = True
-        &quot;&quot;&quot;
-        bindName = yield super(AddressBook, self).shareWith(shareeHome, mode, status, message)
-
-        queryCacher = self._txn._queryCacher
-        if queryCacher:
-            cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.shareeName())
-            queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-
-        self.setShared(True)
-        returnValue(bindName)
-
-
-    @inlineCallbacks
</del><span class="cx">     def unshareWith(self, shareeHome):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Remove the shared version of this (owned) L{CommonHomeChild} from the
</span><span class="lines">@@ -1216,7 +1108,7 @@
</span><span class="cx"> 
</span><span class="cx">         @return: a L{Deferred} which will fire with the previous shareUID
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        sharedAddressBook = yield shareeHome.addressbookWithName(self.shareeName())
</del><ins>+        sharedAddressBook = yield shareeHome.addressbookWithName(self.name())
</ins><span class="cx">         if sharedAddressBook:
</span><span class="cx"> 
</span><span class="cx">             acceptedBindCount = 1 if sharedAddressBook.fullyShared() else 0
</span><span class="lines">@@ -1225,7 +1117,7 @@
</span><span class="cx">             )))
</span><span class="cx">             if acceptedBindCount == 1:
</span><span class="cx">                 yield sharedAddressBook._deletedSyncToken(sharedRemoval=True)
</span><del>-                shareeHome._children.pop(self.shareeName(), None)
</del><ins>+                shareeHome._children.pop(self.name(), None)
</ins><span class="cx">                 shareeHome._children.pop(sharedAddressBook._resourceID, None)
</span><span class="cx">             elif not sharedAddressBook.fullyShared():
</span><span class="cx">                 # FIXME: remove objects for this group only using self.removeObjectResource
</span><span class="lines">@@ -1242,7 +1134,7 @@
</span><span class="cx">             deletedBindName = deletedBindNameRows[0][0]
</span><span class="cx">             queryCacher = self._txn._queryCacher
</span><span class="cx">             if queryCacher:
</span><del>-                cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.shareeName())
</del><ins>+                cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.name())
</ins><span class="cx">                 queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx">         else:
</span><span class="cx">             deletedBindName = None
</span><span class="lines">@@ -1618,7 +1510,7 @@
</span><span class="cx"> 
</span><span class="cx">     def validAddressDataCheck(self, component, inserting): #@UnusedVariable
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Check that the calendar data is valid iCalendar.
</del><ins>+        Check that the calendar data is valid IAddressBook.
</ins><span class="cx">         @return:         tuple: (True/False if the calendar data is valid,
</span><span class="cx">                                  log message string).
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2039,6 +1931,13 @@
</span><span class="cx">         pass
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def sharedResourceType(self):
+        &quot;&quot;&quot;
+        The sharing resource type
+        &quot;&quot;&quot;
+        return &quot;group&quot;
+
+
</ins><span class="cx">     # IDataStoreObject
</span><span class="cx">     def contentType(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2059,13 +1958,6 @@
</span><span class="cx">         return self.addressbook().viewerHome()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareUID(self):
-        &quot;&quot;&quot;
-        @see: L{ICalendar.shareUID}
-        &quot;&quot;&quot;
-        return self._bindName
-
-
</del><span class="cx">     @classmethod
</span><span class="cx">     def metadataColumns(cls):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -2139,7 +2031,7 @@
</span><span class="cx">                 homeUID,
</span><span class="cx">                 homeRID,
</span><span class="cx">                 resourceID,
</span><del>-                self.addressbook().shareeName(),
</del><ins>+                self.addressbook().name(),
</ins><span class="cx">                 bindMode,
</span><span class="cx">                 bindStatus,
</span><span class="cx">                 bindMessage,
</span><span class="lines">@@ -2181,7 +2073,7 @@
</span><span class="cx"> 
</span><span class="cx">         @return: a L{Deferred} which will fire with the previously-used name.
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        sharedAddressBook = yield shareeHome.addressbookWithName(self.addressbook().shareeName())
</del><ins>+        sharedAddressBook = yield shareeHome.addressbookWithName(self.addressbook().name())
</ins><span class="cx"> 
</span><span class="cx">         if sharedAddressBook:
</span><span class="cx"> 
</span><span class="lines">@@ -2194,7 +2086,7 @@
</span><span class="cx"> 
</span><span class="cx">             if acceptedBindCount == 1:
</span><span class="cx">                 yield sharedAddressBook._deletedSyncToken(sharedRemoval=True)
</span><del>-                shareeHome._children.pop(self.addressbook().shareeName(), None)
</del><ins>+                shareeHome._children.pop(self.addressbook().name(), None)
</ins><span class="cx">                 shareeHome._children.pop(self.addressbook()._resourceID, None)
</span><span class="cx"> 
</span><span class="cx">             # Must send notification to ensure cache invalidation occurs
</span><span class="lines">@@ -2209,7 +2101,7 @@
</span><span class="cx">             deletedBindName = deletedBindNameRows[0][0]
</span><span class="cx">             queryCacher = self._txn._queryCacher
</span><span class="cx">             if queryCacher:
</span><del>-                cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().shareeName())
</del><ins>+                cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().name())
</ins><span class="cx">                 queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx">         else:
</span><span class="cx">             deletedBindName = None
</span><span class="lines">@@ -2219,7 +2111,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def shareWith(self, shareeHome, mode, status=None, message=None):
</del><ins>+    def shareWith(self, shareeHome, mode, status=None, summary=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Share this (owned) L{AddressBookObject} with another home.
</span><span class="cx"> 
</span><span class="lines">@@ -2234,9 +2126,9 @@
</span><span class="cx">             L{_BIND_STATUS_ACCEPTED}
</span><span class="cx">         @type mode: L{str}
</span><span class="cx"> 
</span><del>-        @param message: The proposed message to go along with the share, which
</del><ins>+        @param summary: The proposed message to go along with the share, which
</ins><span class="cx">             will be used as the default display name.
</span><del>-        @type mode: L{str}
</del><ins>+        @type summary: L{str}
</ins><span class="cx"> 
</span><span class="cx">         @return: the name of the shared group in the sharee home.
</span><span class="cx">         @rtype: L{str}
</span><span class="lines">@@ -2247,11 +2139,11 @@
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def doInsert(subt):
</span><del>-            newName = str(uuid4())
</del><ins>+            newName = self.newShareName()
</ins><span class="cx">             yield self._bindInsertQuery.on(
</span><span class="cx">                 subt, homeID=shareeHome._resourceID,
</span><span class="cx">                 resourceID=self._resourceID, name=newName,
</span><del>-                mode=mode, bindStatus=status, message=message
</del><ins>+                mode=mode, bindStatus=status, message=summary
</ins><span class="cx">             )
</span><span class="cx">             returnValue(newName)
</span><span class="cx">         try:
</span><span class="lines">@@ -2269,7 +2161,7 @@
</span><span class="cx">                 group = yield shareeHome.invitedObjectWithShareUID(bindName)
</span><span class="cx">             bindName = yield self.updateShare(
</span><span class="cx">                 group, mode=mode, status=status,
</span><del>-                message=message
</del><ins>+                summary=summary
</ins><span class="cx">             )
</span><span class="cx">         else:
</span><span class="cx">             if status == _BIND_STATUS_ACCEPTED:
</span><span class="lines">@@ -2279,7 +2171,7 @@
</span><span class="cx"> 
</span><span class="cx">         queryCacher = self._txn._queryCacher
</span><span class="cx">         if queryCacher:
</span><del>-            cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().shareeName())
</del><ins>+            cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, self.addressbook().name())
</ins><span class="cx">             queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx"> 
</span><span class="cx">         # Must send notification to ensure cache invalidation occurs
</span><span class="lines">@@ -2304,7 +2196,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def updateShare(self, shareeView, mode=None, status=None, message=None):
</del><ins>+    def updateShare(self, shareeView, mode=None, status=None, summary=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Update share mode, status, and message for a home child shared with
</span><span class="cx">         this (owned) L{CommonHomeChild}.
</span><span class="lines">@@ -2321,9 +2213,9 @@
</span><span class="cx">             L{_BIND_STATUS_INVALID}  or None to not update
</span><span class="cx">         @type status: L{str}
</span><span class="cx"> 
</span><del>-        @param message: The proposed message to go along with the share, which
</del><ins>+        @param summary: The proposed message to go along with the share, which
</ins><span class="cx">             will be used as the default display name, or None to not update
</span><del>-        @type message: L{str}
</del><ins>+        @type summary: L{str}
</ins><span class="cx"> 
</span><span class="cx">         @return: the name of the shared item in the sharee's home.
</span><span class="cx">         @rtype: a L{Deferred} which fires with a L{str}
</span><span class="lines">@@ -2336,7 +2228,7 @@
</span><span class="cx">         columnMap = dict([(k, v if v != &quot;&quot; else None)
</span><span class="cx">                           for k, v in {bind.BIND_MODE:mode,
</span><span class="cx">                             bind.BIND_STATUS:status,
</span><del>-                            bind.MESSAGE:message}.iteritems() if v is not None])
</del><ins>+                            bind.MESSAGE:summary}.iteritems() if v is not None])
</ins><span class="cx"> 
</span><span class="cx">         if len(columnMap):
</span><span class="cx"> 
</span><span class="lines">@@ -2364,21 +2256,21 @@
</span><span class="cx">                     if 0 == previouslyAcceptedBindCount:
</span><span class="cx">                         yield shareeView.addressbook()._initSyncToken()
</span><span class="cx">                         yield shareeView._initBindRevision()
</span><del>-                        shareeView.viewerHome()._children[self.addressbook().shareeName()] = shareeView.addressbook()
</del><ins>+                        shareeView.viewerHome()._children[self.addressbook().name()] = shareeView.addressbook()
</ins><span class="cx">                         shareeView.viewerHome()._children[shareeView._resourceID] = shareeView.addressbook()
</span><span class="cx">                 elif shareeView._bindStatus != _BIND_STATUS_INVITED:
</span><span class="cx">                     if 1 == previouslyAcceptedBindCount:
</span><span class="cx">                         yield shareeView.addressbook()._deletedSyncToken(sharedRemoval=True)
</span><del>-                        shareeView.viewerHome()._children.pop(self.addressbook().shareeName(), None)
</del><ins>+                        shareeView.viewerHome()._children.pop(self.addressbook().name(), None)
</ins><span class="cx">                         shareeView.viewerHome()._children.pop(shareeView._resourceID, None)
</span><span class="cx"> 
</span><del>-            if message is not None:
</del><ins>+            if summary is not None:
</ins><span class="cx">                 shareeView._bindMessage = columnMap[bind.MESSAGE]
</span><span class="cx"> 
</span><span class="cx">             # safer to just invalidate in all cases rather than calculate when to invalidate
</span><span class="cx">             queryCacher = self._txn._queryCacher
</span><span class="cx">             if queryCacher:
</span><del>-                cacheKey = queryCacher.keyForObjectWithName(shareeView.viewerHome()._resourceID, self.addressbook().shareeName())
</del><ins>+                cacheKey = queryCacher.keyForObjectWithName(shareeView.viewerHome()._resourceID, self.addressbook().name())
</ins><span class="cx">                 queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx"> 
</span><span class="cx">             shareeView._name = bindNameRows[0][0]
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoretesttest_sqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -741,13 +741,13 @@
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def _defer1():
</span><del>-            yield ab1.shareWith(shareeHome=sharerHome1, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message=&quot;Shared Wiki AddressBook&quot;)
</del><ins>+            yield ab1.shareWith(shareeHome=sharerHome1, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, summary=&quot;Shared Wiki AddressBook&quot;)
</ins><span class="cx">             yield txn1.commit()
</span><span class="cx">         d1 = _defer1()
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def _defer2():
</span><del>-            yield ab2.shareWith(shareeHome=sharerHome2, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, message=&quot;Shared Wiki AddressBook&quot;)
</del><ins>+            yield ab2.shareWith(shareeHome=sharerHome2, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED, summary=&quot;Shared Wiki AddressBook&quot;)
</ins><span class="cx">             yield txn2.commit()
</span><span class="cx">         d2 = _defer2()
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcarddavdatastoretesttest_sql_sharingpy"></a>
<div class="addfile"><h4>Added: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql_sharing.py (0 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql_sharing.py                                (rev 0)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/carddav/datastore/test/test_sql_sharing.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -0,0 +1,430 @@
</span><ins>+##
+# Copyright (c) 2005-2013 Apple Inc. All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an &quot;AS IS&quot; BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+##
+
+
+from twisted.internet.defer import inlineCallbacks, returnValue
+from twisted.trial.unittest import TestCase
+
+from twistedcaldav.vcard import Component as VCard
+from twext.python.clsprop import classproperty
+from txdav.common.datastore.test.util import CommonCommonTests, buildStore
+from txdav.common.datastore.sql_tables import _BIND_MODE_READ, \
+    _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_ACCEPTED
+
+
+class CalendarSharing(CommonCommonTests, TestCase):
+    &quot;&quot;&quot;
+    Test twistedcaldav.scheduyling.implicit with a Request object.
+    &quot;&quot;&quot;
+
+    @inlineCallbacks
+    def setUp(self):
+        yield super(CalendarSharing, self).setUp()
+        self._sqlStore = yield buildStore(self, self.notifierFactory)
+        yield self.populate()
+
+
+    @inlineCallbacks
+    def populate(self):
+        populateTxn = self.storeUnderTest().newTransaction()
+        for homeUID in self.requirements:
+            addressbooks = self.requirements[homeUID]
+            if addressbooks is not None:
+                home = yield populateTxn.addressbookHomeWithUID(homeUID, True)
+                addressbook = home.addressbook()
+
+                addressbookObjNames = addressbooks[addressbook.name()]
+                if addressbookObjNames is not None:
+                    for objectName in addressbookObjNames:
+                        objData = addressbookObjNames[objectName]
+                        yield addressbook.createAddressBookObjectWithName(
+                            objectName, VCard.fromString(objData)
+                        )
+
+        yield populateTxn.commit()
+        self.notifierFactory.reset()
+
+
+    @classproperty(cache=False)
+    def requirements(cls): #@NoSelf
+        return {
+        &quot;user01&quot;: {
+            &quot;addressbook&quot;: {
+            },
+        },
+        &quot;user02&quot;: {
+            &quot;addressbook&quot;: {
+            },
+        },
+        &quot;user03&quot;: {
+            &quot;addressbook&quot;: {
+            },
+        },
+    }
+
+
+    def storeUnderTest(self):
+        &quot;&quot;&quot;
+        Create and return a L{CalendarStore} for testing.
+        &quot;&quot;&quot;
+        return self._sqlStore
+
+
+    @inlineCallbacks
+    def _createShare(self):
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        inviteUID = shareeView.shareUID()
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        shareeView = yield shareeHome.acceptShare(inviteUID)
+        sharedName = shareeView.name()
+        yield self.commit()
+
+        returnValue(sharedName)
+
+
+    @inlineCallbacks
+    def test_no_shares(self):
+        &quot;&quot;&quot;
+        Test that initially there are no shares.
+        &quot;&quot;&quot;
+
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+
+    @inlineCallbacks
+    def test_invite_sharee(self):
+        &quot;&quot;&quot;
+        Test invite/uninvite creates/removes shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        self.assertEqual(invites[0].uid, shareeView.shareUID())
+        self.assertEqual(invites[0].ownerUID, &quot;user01&quot;)
+        self.assertEqual(invites[0].shareeUID, &quot;user02&quot;)
+        self.assertEqual(invites[0].shareeName, shareeView.name())
+        self.assertEqual(invites[0].mode, _BIND_MODE_READ)
+        self.assertEqual(invites[0].status, _BIND_STATUS_INVITED)
+        self.assertEqual(invites[0].summary, &quot;summary&quot;)
+        inviteUID = shareeView.shareUID()
+
+        self.assertEqual(invites[0].shareeName, &quot;user01&quot;)
+
+        sharedName = shareeView.name()
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID, ])
+
+        yield self.commit()
+
+        # Uninvite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+
+        yield addressbook.uninviteUserFromShare(&quot;user02&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [])
+
+
+    @inlineCallbacks
+    def test_accept_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept creates shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Re-accept
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_decline_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept creates shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Decline
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.declineShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Redecline
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.declineShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_accept_decline_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept/decline creates/removes shares and notifications.
+        Decline via the home.
+        &quot;&quot;&quot;
+
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Decline
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.declineShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_accept_remove_share(self):
+        &quot;&quot;&quot;
+        Test that invite+accept/decline creates/removes shares and notifications.
+        Decline via the shared collection (removal).
+        &quot;&quot;&quot;
+
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.inviteUserToShare(&quot;user02&quot;, _BIND_MODE_READ, &quot;summary&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        inviteUID = shareeView.shareUID()
+
+        sharedName = shareeView.name()
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 1)
+
+        yield self.commit()
+
+        # Accept
+        shareeHome = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        yield shareeHome.acceptShare(inviteUID)
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+        yield self.commit()
+
+        # Delete
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        yield shared.deleteShare()
+
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user01&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(notifications, [inviteUID + &quot;-reply&quot;, ])
+
+
+    @inlineCallbacks
+    def test_direct_sharee(self):
+        &quot;&quot;&quot;
+        Test invite/uninvite creates/removes shares and notifications.
+        &quot;&quot;&quot;
+
+        # Invite
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        shareeView = yield addressbook.directShareWithUser(&quot;user02&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        self.assertEqual(invites[0].uid, shareeView.shareUID())
+        self.assertEqual(invites[0].ownerUID, &quot;user01&quot;)
+        self.assertEqual(invites[0].shareeUID, &quot;user02&quot;)
+        self.assertEqual(invites[0].shareeName, shareeView.name())
+        self.assertEqual(invites[0].mode, _BIND_MODE_DIRECT)
+        self.assertEqual(invites[0].status, _BIND_STATUS_ACCEPTED)
+
+        sharedName = shareeView.name()
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        self.assertTrue(shared is not None)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 0)
+
+        yield self.commit()
+
+        # Remove
+        shared = yield self.addressbookUnderTest(home=&quot;user02&quot;, name=sharedName)
+        yield shared.deleteShare()
+
+        addressbook = yield self.addressbookUnderTest(home=&quot;user01&quot;, name=&quot;addressbook&quot;)
+        invites = yield addressbook.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 0)
+
+
+    @inlineCallbacks
+    def test_sharedNotifierID(self):
+        shared_name = yield self._createShare()
+
+        home = yield self.addressbookHomeUnderTest(name=&quot;user01&quot;)
+        self.assertEquals(home.notifierID(), (&quot;CardDAV&quot;, &quot;user01&quot;,))
+        addressbook = yield home.addressbookWithName(&quot;addressbook&quot;)
+        self.assertEquals(addressbook.notifierID(), (&quot;CardDAV&quot;, &quot;user01/addressbook&quot;,))
+        yield self.commit()
+
+        home = yield self.addressbookHomeUnderTest(name=&quot;user02&quot;)
+        self.assertEquals(home.notifierID(), (&quot;CardDAV&quot;, &quot;user02&quot;,))
+        addressbook = yield home.addressbookWithName(shared_name)
+        self.assertEquals(addressbook.notifierID(), (&quot;CardDAV&quot;, &quot;user01/addressbook&quot;,))
+        yield self.commit()
</ins></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -14,6 +14,9 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><ins>+from collections import namedtuple
+from txdav.xml import element
+from txdav.base.propertystore.base import PropertyName
</ins><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> SQL data store.
</span><span class="lines">@@ -60,7 +63,8 @@
</span><span class="cx"> from txdav.carddav.iaddressbookstore import IAddressBookTransaction
</span><span class="cx"> from txdav.common.datastore.common import HomeChildBase
</span><span class="cx"> from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
</span><del>-    _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED
</del><ins>+    _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, _BIND_STATUS_INVALID, \
+    _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_DELETED
</ins><span class="cx"> from txdav.common.datastore.sql_tables import schema, splitSQLString
</span><span class="cx"> from txdav.common.icommondatastore import ConcurrentModification
</span><span class="cx"> from txdav.common.icommondatastore import HomeChildNameNotAllowedError, \
</span><span class="lines">@@ -1433,10 +1437,43 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class CommonHome(object):
</del><ins>+class SharingHomeMixIn(object):
+    &quot;&quot;&quot;
+    Common class for CommonHome to implement sharing operations
+    &quot;&quot;&quot;
+
+    @inlineCallbacks
+    def acceptShare(self, shareUID, summary=None):
+        &quot;&quot;&quot;
+        This share is being accepted.
+        &quot;&quot;&quot;
+
+        shareeView = yield self.anyObjectWithShareUID(shareUID)
+        if shareeView is not None:
+            yield shareeView.acceptShare(summary)
+
+        returnValue(shareeView)
+
+
+    @inlineCallbacks
+    def declineShare(self, shareUID):
+        &quot;&quot;&quot;
+        This share is being declined.
+        &quot;&quot;&quot;
+
+        shareeView = yield self.anyObjectWithShareUID(shareUID)
+        if shareeView is not None:
+            yield shareeView.declineShare()
+
+        returnValue(shareeView)
+
+
+
+class CommonHome(SharingHomeMixIn):
</ins><span class="cx">     log = Logger()
</span><span class="cx"> 
</span><span class="cx">     # All these need to be initialized by derived classes for each store type
</span><ins>+    _homeType = None
</ins><span class="cx">     _homeTable = None
</span><span class="cx">     _homeMetaDataTable = None
</span><span class="cx">     _childClass = None
</span><span class="lines">@@ -1794,6 +1831,17 @@
</span><span class="cx">         return self._childClass.objectWithName(self, shareUID, accepted=False)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def anyObjectWithShareUID(self, shareUID):
+        &quot;&quot;&quot;
+        Retrieve the child accepted or otherwise with the given bind identifier contained in this
+        home.
+
+        @param name: a string.
+        @return: an L{ICalendar} or C{None} if no such child exists.
+        &quot;&quot;&quot;
+        return self._childClass.objectWithName(self, shareUID, accepted=None)
+
+
</ins><span class="cx">     @memoizedKey(&quot;resourceID&quot;, &quot;_children&quot;)
</span><span class="cx">     def childWithID(self, resourceID):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -1806,6 +1854,17 @@
</span><span class="cx">         return self._childClass.objectWithID(self, resourceID)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def allChildWithID(self, resourceID):
+        &quot;&quot;&quot;
+        Retrieve the child with the given C{resourceID} contained in this
+        home.
+
+        @param name: a string.
+        @return: an L{ICalendar} or C{None} if no such child exists.
+        &quot;&quot;&quot;
+        return self._childClass.objectWithID(self, resourceID, accepted=None)
+
+
</ins><span class="cx">     @inlineCallbacks
</span><span class="cx">     def createChildWithName(self, name):
</span><span class="cx">         if name.startswith(&quot;.&quot;):
</span><span class="lines">@@ -2699,125 +2758,13 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-class SharingInvitation(object):
-    &quot;&quot;&quot;
-    SharingInvitation covers all the information needed to expose sharing invites to upper layers. Its primarily used to
-    minimize the need to load full properties/data when only this subset of information is needed.
-    &quot;&quot;&quot;
-    def __init__(self, uid, owner_uid, owner_rid, sharee_uid, sharee_rid, resource_id, resource_name, mode, status, summary):
-        self._uid = uid
-        self._owner_uid = owner_uid
-        self._owner_rid = owner_rid
-        self._sharee_uid = sharee_uid
-        self._sharee_rid = sharee_rid
-        self._resource_id = resource_id
-        self._resource_name = resource_name
-        self._mode = mode
-        self._status = status
-        self._summary = summary
</del><ins>+SharingInvitation = namedtuple(
+    &quot;SharingInvitation&quot;,
+    [&quot;uid&quot;, &quot;ownerUID&quot;, &quot;shareeUID&quot;, &quot;shareeName&quot;, &quot;mode&quot;, &quot;status&quot;, &quot;summary&quot;]
+)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @classmethod
-    def fromCommonHomeChild(cls, homeChild):
-        return cls(
-            homeChild.shareUID(),
-            homeChild.ownerHome().uid(),
-            homeChild.ownerHome()._resourceID,
-            homeChild.viewerHome().uid(),
-            homeChild.viewerHome()._resourceID,
-            homeChild._resourceID,
-            homeChild.shareeName(),
-            homeChild.shareMode(),
-            homeChild.shareStatus(),
-            homeChild.shareMessage(),
-        )
</del><span class="cx"> 
</span><del>-
-    def uid(self):
-        &quot;&quot;&quot;
-        This maps to the resource name in the bind table, the &quot;bind name&quot;. This is used as the &quot;uid&quot;
-        for invites, and is not necessarily the name of the resource as it appears in the collection.
-        &quot;&quot;&quot;
-        return self._uid
-
-
-    def ownerUID(self):
-        &quot;&quot;&quot;
-        The ownerUID of the sharer.
-        &quot;&quot;&quot;
-        return self._owner_uid
-
-
-    def ownerHomeID(self):
-        &quot;&quot;&quot;
-        The resourceID of the sharer's L{CommonHome}.
-        &quot;&quot;&quot;
-        return self._owner_rid
-
-
-    def shareeUID(self):
-        &quot;&quot;&quot;
-        The ownerUID of the sharee.
-        &quot;&quot;&quot;
-        return self._sharee_uid
-
-
-    def shareeHomeID(self):
-        &quot;&quot;&quot;
-        The resourceID of the sharee's L{CommonHome}.
-        &quot;&quot;&quot;
-        return self._sharee_rid
-
-
-    def resourceID(self):
-        &quot;&quot;&quot;
-        The resourceID of the shared object.
-        &quot;&quot;&quot;
-        return self._resource_id
-
-
-    def resourceName(self):
-        &quot;&quot;&quot;
-        This maps to the name of the shared resource in the collection it is bound into. It is not necessarily the
-        same as the &quot;bind name&quot; which is used as the &quot;uid&quot; for invites.
-        &quot;&quot;&quot;
-        return self._resource_name
-
-
-    def mode(self):
-        &quot;&quot;&quot;
-        The sharing mode: one of the _BIND_MODE_XXX values.
-        &quot;&quot;&quot;
-        return self._mode
-
-
-    def setMode(self, mode):
-        self._mode = mode
-
-
-    def status(self):
-        &quot;&quot;&quot;
-        The sharing status: one of the _BIND_STATUS_XXX values.
-        &quot;&quot;&quot;
-        return self._status
-
-
-    def setStatus(self, status):
-        self._status = status
-
-
-    def summary(self):
-        &quot;&quot;&quot;
-        Message associated with the invitation.
-        &quot;&quot;&quot;
-        return self._summary
-
-
-    def setSummary(self, summary):
-        self._summary = summary
-
-
-
</del><span class="cx"> class SharingMixIn(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     Common class for CommonHomeChild and AddressBookObject
</span><span class="lines">@@ -2843,29 +2790,20 @@
</span><span class="cx">     @classmethod
</span><span class="cx">     def _updateBindColumnsQuery(cls, columnMap): #@NoSelf
</span><span class="cx">         bind = cls._bindSchema
</span><del>-        return Update(columnMap,
-                      Where=(bind.RESOURCE_ID == Parameter(&quot;resourceID&quot;))
-                      .And(bind.HOME_RESOURCE_ID == Parameter(&quot;homeID&quot;)),
-                      Return=bind.RESOURCE_NAME)
</del><ins>+        return Update(
+            columnMap,
+            Where=(bind.RESOURCE_ID == Parameter(&quot;resourceID&quot;))
+                   .And(bind.HOME_RESOURCE_ID == Parameter(&quot;homeID&quot;)),
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><del>-    def _updateBindQuery(cls): #@NoSelf
-        bind = cls._bindSchema
-        return cls._updateBindColumnsQuery(
-                    {bind.BIND_MODE: Parameter(&quot;mode&quot;),
-                     bind.BIND_STATUS: Parameter(&quot;status&quot;),
-                     bind.MESSAGE: Parameter(&quot;message&quot;)})
-
-
-    @classproperty
</del><span class="cx">     def _deleteBindForResourceIDAndHomeID(cls): #@NoSelf
</span><span class="cx">         bind = cls._bindSchema
</span><span class="cx">         return Delete(
</span><span class="cx">             From=bind,
</span><span class="cx">             Where=(bind.RESOURCE_ID == Parameter(&quot;resourceID&quot;))
</span><span class="cx">                   .And(bind.HOME_RESOURCE_ID == Parameter(&quot;homeID&quot;)),
</span><del>-            Return=bind.RESOURCE_NAME,
</del><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -2939,9 +2877,226 @@
</span><span class="cx">                                )
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    #
+    # Higher level API
+    #
</ins><span class="cx">     @inlineCallbacks
</span><del>-    def shareWith(self, shareeHome, mode, status=None, message=None):
</del><ins>+    def inviteUserToShare(self, shareeUID, mode, summary):
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        Invite a user to share this collection - either create the share if it does not exist, or
+        update the existing share with new values. Make sure a notification is sent as well.
+
+        @param shareeUID: UID of the sharee
+        @type shareeUID: C{str}
+        @param mode: access mode
+        @type mode: C{int}
+        @param summary: share message
+        @type summary: C{str}
+        &quot;&quot;&quot;
+
+        # Look for existing invite and update its fields or create new one
+        shareeView = yield self.shareeView(shareeUID)
+        if shareeView is not None:
+            status = _BIND_STATUS_INVITED if shareeView.shareStatus() in (_BIND_STATUS_DECLINED, _BIND_STATUS_INVALID) else None
+            yield self.updateShare(shareeView, mode=mode, status=status, summary=summary)
+        else:
+            shareeView = yield self.createShare(shareeUID=shareeUID, mode=mode, summary=summary)
+
+        # Send invite notification
+        yield self._sendInviteNotification(shareeView)
+        returnValue(shareeView)
+
+
+    @inlineCallbacks
+    def directShareWithUser(self, shareeUID):
+        &quot;&quot;&quot;
+        Create a direct share with the specified user. Note it is currently up to the app layer
+        to enforce access control - this is not ideal as we really should have control of that in
+        the store. Once we do, this api will need to verify that access is allowed for a direct share.
+
+        NB no invitations are used with direct sharing.
+
+        @param shareeUID: UID of the sharee
+        @type shareeUID: C{str}
+        &quot;&quot;&quot;
+
+        # Ignore if it already exists
+        shareeView = yield self.shareeView(shareeUID)
+        if shareeView is None:
+            shareeView = yield self.createShare(shareeUID=shareeUID, mode=_BIND_MODE_DIRECT)
+            yield shareeView.newShare()
+        returnValue(shareeView)
+
+
+    @inlineCallbacks
+    def uninviteUserFromShare(self, shareeUID):
+        &quot;&quot;&quot;
+        Remove a user from a share. Make sure a notification is sent as well.
+
+        @param shareeUID: UID of the sharee
+        @type shareeUID: C{str}
+        &quot;&quot;&quot;
+        # Cancel invites - we'll just use whatever userid we are given
+
+        shareeView = yield self.shareeView(shareeUID)
+        if shareeView is not None:
+            # If current user state is accepted then we send an invite with the new state, otherwise
+            # we cancel any existing invites for the user
+            if shareeView.shareStatus() != _BIND_STATUS_ACCEPTED:
+                yield self._removeInviteNotification(shareeView)
+            else:
+                yield self._sendInviteNotification(shareeView, notificationState=_BIND_STATUS_DELETED)
+
+            # Remove the bind
+            yield self.removeShare(shareeView)
+
+
+    @inlineCallbacks
+    def acceptShare(self, summary=None):
+        &quot;&quot;&quot;
+        This share is being accepted.
+        &quot;&quot;&quot;
+
+        if self.shareStatus() != _BIND_STATUS_ACCEPTED:
+            ownerView = yield self.ownerView()
+            yield ownerView.updateShare(self, status=_BIND_STATUS_ACCEPTED)
+            yield self.newShare(displayname=summary)
+            yield self._sendReplyNotification(ownerView, summary)
+
+
+    @inlineCallbacks
+    def declineShare(self):
+        &quot;&quot;&quot;
+        This share is being declined.
+        &quot;&quot;&quot;
+
+        if self.shareStatus() != _BIND_STATUS_DECLINED:
+            ownerView = yield self.ownerView()
+            yield ownerView.updateShare(self, status=_BIND_STATUS_DECLINED)
+            yield self._sendReplyNotification(ownerView)
+
+
+    @inlineCallbacks
+    def deleteShare(self):
+        &quot;&quot;&quot;
+        This share is being deleted - either decline or remove (for direct shares).
+        &quot;&quot;&quot;
+
+        ownerView = yield self.ownerView()
+        if self.direct():
+            yield ownerView.removeShare(self)
+        else:
+            yield self.declineShare()
+
+
+    def newShare(self, displayname=None):
+        &quot;&quot;&quot;
+        Override in derived classes to do any specific operations needed when a share
+        is first accepted.
+        &quot;&quot;&quot;
+        return succeed(None)
+
+
+    @inlineCallbacks
+    def allInvitations(self):
+        &quot;&quot;&quot;
+        Get list of all invitations (non-direct) to this object.
+        &quot;&quot;&quot;
+        invitations = yield self.sharingInvites()
+
+        # remove direct shares as those are not &quot;real&quot; invitations
+        invitations = filter(lambda x: x.mode != _BIND_MODE_DIRECT, invitations)
+        invitations.sort(key=lambda invitation: invitation.shareeUID)
+        returnValue(invitations)
+
+
+    @inlineCallbacks
+    def _sendInviteNotification(self, shareeView, notificationState=None):
+        &quot;&quot;&quot;
+        Called on the owner's resource.
+        &quot;&quot;&quot;
+
+        # When deleting the message is the sharee's display name
+        if notificationState == _BIND_STATUS_DELETED:
+            try:
+                displayname = str(shareeView.properties()[PropertyName.fromElement(element.DisplayName)])
+            except KeyError:
+                displayname = shareeView.name()
+        else:
+            displayname = shareeView.shareMessage()
+
+        notificationtype = {
+            &quot;notification-type&quot;: &quot;invite-notification&quot;,
+            &quot;shared-type&quot;: shareeView.sharedResourceType(),
+        }
+        notificationdata = {
+            &quot;notification-type&quot;: &quot;invite-notification&quot;,
+            &quot;shared-type&quot;: shareeView.sharedResourceType(),
+            &quot;dtstamp&quot;: DateTime.getNowUTC().getText(),
+            &quot;owner&quot;: shareeView.ownerHome().uid(),
+            &quot;sharee&quot;: shareeView.viewerHome().uid(),
+            &quot;uid&quot;: shareeView.shareUID(),
+            &quot;status&quot;: shareeView.shareStatus() if notificationState is None else notificationState,
+            &quot;access&quot;: shareeView.shareMode(),
+            &quot;ownerName&quot;: self.shareName(),
+            &quot;summary&quot;: displayname,
+        }
+        if hasattr(self, &quot;getSupportedComponents&quot;):
+            notificationdata[&quot;supported-components&quot;] = self.getSupportedComponents()
+
+        # Add to sharee's collection
+        notifications = yield self._txn.notificationsWithUID(shareeView.viewerHome().uid())
+        yield notifications.writeNotificationObject(shareeView.shareUID(), notificationtype, notificationdata)
+
+
+    @inlineCallbacks
+    def _sendReplyNotification(self, ownerView, summary=None):
+        &quot;&quot;&quot;
+        Create a reply notification based on the current state of this shared resource.
+        &quot;&quot;&quot;
+
+        # Generate invite XML
+        notificationUID = &quot;%s-reply&quot; % (self.shareUID(),)
+
+        notificationtype = {
+            &quot;notification-type&quot;: &quot;invite-reply&quot;,
+            &quot;shared-type&quot;: self.sharedResourceType(),
+        }
+
+        notificationdata = {
+            &quot;notification-type&quot;: &quot;invite-reply&quot;,
+            &quot;shared-type&quot;: self.sharedResourceType(),
+            &quot;dtstamp&quot;: DateTime.getNowUTC().getText(),
+            &quot;owner&quot;: self.ownerHome().uid(),
+            &quot;sharee&quot;: self.viewerHome().uid(),
+            &quot;status&quot;: self.shareStatus(),
+            &quot;ownerName&quot;: ownerView.shareName(),
+            &quot;in-reply-to&quot;: self.shareUID(),
+            &quot;summary&quot;: summary,
+        }
+
+        # Add to owner notification collection
+        notifications = yield self._txn.notificationsWithUID(self.ownerHome().uid())
+        yield notifications.writeNotificationObject(notificationUID, notificationtype, notificationdata)
+
+
+    @inlineCallbacks
+    def _removeInviteNotification(self, shareeView):
+        &quot;&quot;&quot;
+        Called on the owner's resource.
+        &quot;&quot;&quot;
+
+        # Remove from sharee's collection
+        notifications = yield self._txn.notificationsWithUID(shareeView.viewerHome().uid())
+        yield notifications.removeNotificationObjectWithUID(shareeView.shareUID())
+
+
+    #
+    # Lower level API
+    #
+    @inlineCallbacks
+    def shareWith(self, shareeHome, mode, status=None, summary=None):
+        &quot;&quot;&quot;
</ins><span class="cx">         Share this (owned) L{CommonHomeChild} with another home.
</span><span class="cx"> 
</span><span class="cx">         @param shareeHome: The home of the sharee.
</span><span class="lines">@@ -2955,9 +3110,9 @@
</span><span class="cx">             L{_BIND_STATUS_ACCEPTED}
</span><span class="cx">         @type mode: L{str}
</span><span class="cx"> 
</span><del>-        @param message: The proposed message to go along with the share, which
</del><ins>+        @param summary: The proposed message to go along with the share, which
</ins><span class="cx">             will be used as the default display name.
</span><del>-        @type mode: L{str}
</del><ins>+        @type summary: L{str}
</ins><span class="cx"> 
</span><span class="cx">         @return: the name of the shared calendar in the new calendar home.
</span><span class="cx">         @rtype: L{str}
</span><span class="lines">@@ -2968,11 +3123,11 @@
</span><span class="cx"> 
</span><span class="cx">         @inlineCallbacks
</span><span class="cx">         def doInsert(subt):
</span><del>-            newName = str(uuid4())
</del><ins>+            newName = self.newShareName()
</ins><span class="cx">             yield self._bindInsertQuery.on(
</span><span class="cx">                 subt, homeID=shareeHome._resourceID,
</span><span class="cx">                 resourceID=self._resourceID, name=newName,
</span><del>-                mode=mode, bindStatus=status, message=message
</del><ins>+                mode=mode, bindStatus=status, message=summary
</ins><span class="cx">             )
</span><span class="cx">             returnValue(newName)
</span><span class="cx">         try:
</span><span class="lines">@@ -2982,16 +3137,20 @@
</span><span class="cx">             child = yield shareeHome.childWithID(self._resourceID)
</span><span class="cx">             if not child:
</span><span class="cx">                 child = yield shareeHome.objectWithID(shareeHome, self._resourceID, accepted=False)
</span><del>-            bindName = yield self.updateShare(
</del><ins>+            yield self.updateShare(
</ins><span class="cx">                 child, mode=mode, status=status,
</span><del>-                message=message
</del><ins>+                summary=summary
</ins><span class="cx">             )
</span><ins>+            bindName = child._name
</ins><span class="cx">         else:
</span><span class="cx">             if status == _BIND_STATUS_ACCEPTED:
</span><span class="cx">                 shareeView = yield shareeHome.objectWithShareUID(bindName)
</span><span class="cx">                 yield shareeView._initSyncToken()
</span><span class="cx">                 yield shareeView._initBindRevision()
</span><span class="cx"> 
</span><ins>+        # Mark this as shared
+        yield self.setShared(True)
+
</ins><span class="cx">         # Must send notification to ensure cache invalidation occurs
</span><span class="cx">         yield self.notifyPropertyChanged()
</span><span class="cx">         yield shareeHome.notifyChanged()
</span><span class="lines">@@ -3000,26 +3159,48 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def updateShareFromSharingInvitation(self, invitation, mode=None, status=None, message=None):
</del><ins>+    def ownerView(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Like L{updateShare} except that the original invitation is provided. That is used
-        to find the actual sharee L{CommonHomeChild} which is then passed to L{updateShare}.
</del><ins>+        Return the owner resource counterpart of this shared resource.
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        # Get the child of the owner home that has the same resource id as the owned one
+        ownerView = yield self.ownerHome().childWithID(self.id())
+        returnValue(ownerView)
</ins><span class="cx"> 
</span><del>-        # Look up the shared child - might be accepted or not. If accepted use the resource name
-        # to look it up, else use the invitation uid (bind name)
-        shareeHome = yield self._txn.homeWithUID(self._home._homeType, invitation.shareeUID())
-        shareeView = yield shareeHome.childWithName(invitation.resourceName())
-        if shareeView is None:
-            shareeView = yield shareeHome.invitedObjectWithShareUID(invitation.uid())
</del><span class="cx"> 
</span><del>-        result = yield self.updateShare(shareeView, mode, status, message)
-        returnValue(result)
</del><ins>+    @inlineCallbacks
+    def shareeView(self, shareeUID):
+        &quot;&quot;&quot;
+        Return the shared resource counterpart of this owned resource for the specified sharee.
+        &quot;&quot;&quot;
</ins><span class="cx"> 
</span><ins>+        # Get the child of the sharee home that has the same resource id as the owned one
+        shareeHome = yield self._txn.homeWithUID(self._home._homeType, shareeUID)
+        shareeView = (yield shareeHome.allChildWithID(self.id())) if shareeHome is not None else None
+        returnValue(shareeView)
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx">     @inlineCallbacks
</span><del>-    def updateShare(self, shareeView, mode=None, status=None, message=None):
</del><ins>+    def createShare(self, shareeUID, mode, summary=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        Create a new shared resource. If the mode is direct, the share is created in accepted state,
+        otherwise the share is created in invited state.
+        &quot;&quot;&quot;
+        shareeHome = yield self._txn.homeWithUID(self.ownerHome()._homeType, shareeUID, create=True)
+
+        yield self.shareWith(
+            shareeHome,
+            mode=mode,
+            status=_BIND_STATUS_INVITED if mode != _BIND_MODE_DIRECT else _BIND_STATUS_ACCEPTED,
+            summary=summary,
+        )
+        shareeView = yield self.shareeView(shareeUID)
+        returnValue(shareeView)
+
+
+    @inlineCallbacks
+    def updateShare(self, shareeView, mode=None, status=None, summary=None):
+        &quot;&quot;&quot;
</ins><span class="cx">         Update share mode, status, and message for a home child shared with
</span><span class="cx">         this (owned) L{CommonHomeChild}.
</span><span class="cx"> 
</span><span class="lines">@@ -3035,9 +3216,9 @@
</span><span class="cx">             L{_BIND_STATUS_INVALID}  or None to not update
</span><span class="cx">         @type status: L{str}
</span><span class="cx"> 
</span><del>-        @param message: The proposed message to go along with the share, which
</del><ins>+        @param summary: The proposed message to go along with the share, which
</ins><span class="cx">             will be used as the default display name, or None to not update
</span><del>-        @type message: L{str}
</del><ins>+        @type summary: L{str}
</ins><span class="cx"> 
</span><span class="cx">         @return: the name of the shared item in the sharee's home.
</span><span class="cx">         @rtype: a L{Deferred} which fires with a L{str}
</span><span class="lines">@@ -3050,14 +3231,14 @@
</span><span class="cx">         columnMap = dict([(k, v if v != &quot;&quot; else None)
</span><span class="cx">                           for k, v in {bind.BIND_MODE:mode,
</span><span class="cx">                             bind.BIND_STATUS:status,
</span><del>-                            bind.MESSAGE:message}.iteritems() if v is not None])
</del><ins>+                            bind.MESSAGE:summary}.iteritems() if v is not None])
</ins><span class="cx"> 
</span><span class="cx">         if len(columnMap):
</span><span class="cx"> 
</span><del>-            sharedname = yield self._updateBindColumnsQuery(columnMap).on(
-                            self._txn,
-                            resourceID=self._resourceID, homeID=shareeView._home._resourceID
-                        )
</del><ins>+            yield self._updateBindColumnsQuery(columnMap).on(
+                self._txn,
+                resourceID=self._resourceID, homeID=shareeView._home._resourceID
+            )
</ins><span class="cx"> 
</span><span class="cx">             #update affected attributes
</span><span class="cx">             if mode is not None:
</span><span class="lines">@@ -3075,7 +3256,7 @@
</span><span class="cx">                     shareeView._home._children.pop(shareeView._name, None)
</span><span class="cx">                     shareeView._home._children.pop(shareeView._resourceID, None)
</span><span class="cx"> 
</span><del>-            if message is not None:
</del><ins>+            if summary is not None:
</ins><span class="cx">                 shareeView._bindMessage = columnMap[bind.MESSAGE]
</span><span class="cx"> 
</span><span class="cx">             queryCacher = self._txn._queryCacher
</span><span class="lines">@@ -3085,71 +3266,45 @@
</span><span class="cx">                 cacheKey = queryCacher.keyForObjectWithResourceID(shareeView._home._resourceID, shareeView._resourceID)
</span><span class="cx">                 yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</span><span class="cx"> 
</span><del>-            shareeView._name = sharedname[0][0]
-
</del><span class="cx">             # Must send notification to ensure cache invalidation occurs
</span><span class="cx">             yield self.notifyPropertyChanged()
</span><span class="cx">             yield shareeView.viewerHome().notifyChanged()
</span><span class="cx"> 
</span><del>-        returnValue(shareeView._name)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     @inlineCallbacks
</span><del>-    def unshareWithUID(self, shareeUID):
</del><ins>+    def removeShare(self, shareeView):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        Like L{unshareWith} except this is passed a sharee UID which is then used to lookup the
-        L{CommonHome} for the sharee to pass to L{unshareWith}.
-        &quot;&quot;&quot;
-
-        shareeHome = yield self._txn.homeWithUID(self._home._homeType, shareeUID)
-        result = yield self.unshareWith(shareeHome)
-        returnValue(result)
-
-
-    @inlineCallbacks
-    def unshareWith(self, shareeHome):
-        &quot;&quot;&quot;
</del><span class="cx">         Remove the shared version of this (owned) L{CommonHomeChild} from the
</span><span class="cx">         referenced L{CommonHome}.
</span><span class="cx"> 
</span><span class="cx">         @see: L{CommonHomeChild.shareWith}
</span><span class="cx"> 
</span><del>-        @param shareeHome: The home with which this L{CommonHomeChild} was
-            previously shared.
</del><ins>+        @param shareeView: The shared resource being removed.
</ins><span class="cx"> 
</span><span class="cx">         @return: a L{Deferred} which will fire with the previous shareUID
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        #remove sync tokens
-        shareeChildren = yield shareeHome.children()
-        for shareeChild in shareeChildren:
-            if not shareeChild.owned() and shareeChild._resourceID == self._resourceID:
-                yield shareeChild._deletedSyncToken(sharedRemoval=True)
-                shareeHome._children.pop(shareeChild._name, None)
-                shareeHome._children.pop(shareeChild._resourceID, None)
</del><span class="cx"> 
</span><del>-                # Must send notification to ensure cache invalidation occurs
-                yield self.notifyPropertyChanged()
-                yield shareeHome.notifyChanged()
-                break
</del><ins>+        # remove sync tokens
+        shareeHome = shareeView.viewerHome()
+        yield shareeView._deletedSyncToken(sharedRemoval=True)
+        shareeHome._children.pop(shareeView._name, None)
+        shareeHome._children.pop(shareeView._resourceID, None)
</ins><span class="cx"> 
</span><ins>+        # Must send notification to ensure cache invalidation occurs
+        yield self.notifyPropertyChanged()
+        yield shareeHome.notifyChanged()
+
</ins><span class="cx">         # delete binds including invites
</span><del>-        deletedBindNameRows = yield self._deleteBindForResourceIDAndHomeID.on(self._txn, resourceID=self._resourceID,
-             homeID=shareeHome._resourceID)
</del><ins>+        yield self._deleteBindForResourceIDAndHomeID.on(self._txn, resourceID=self._resourceID, homeID=shareeHome._resourceID)
</ins><span class="cx"> 
</span><del>-        if deletedBindNameRows:
-            deletedBindName = deletedBindNameRows[0][0]
-            queryCacher = self._txn._queryCacher
-            if queryCacher:
-                cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, shareeChild._name)
-                yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-                cacheKey = queryCacher.keyForObjectWithResourceID(shareeHome._resourceID, shareeChild._resourceID)
-                yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
-        else:
-            deletedBindName = None
</del><ins>+        queryCacher = self._txn._queryCacher
+        if queryCacher:
+            cacheKey = queryCacher.keyForObjectWithName(shareeHome._resourceID, shareeView._name)
+            yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
+            cacheKey = queryCacher.keyForObjectWithResourceID(shareeHome._resourceID, shareeView._resourceID)
+            yield queryCacher.invalidateAfterCommit(self._txn, cacheKey)
</ins><span class="cx"> 
</span><del>-        returnValue(deletedBindName)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def unshare(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -3159,12 +3314,12 @@
</span><span class="cx">             # This collection may be shared to others
</span><span class="cx">             invites = yield self.sharingInvites()
</span><span class="cx">             for invite in invites:
</span><del>-                shareeHome = (yield self._txn.homeWithResourceID(self._home._homeType, invite.shareeHomeID()))
-                (yield self.unshareWith(shareeHome))
</del><ins>+                shareeView = yield self.shareeView(invite.shareeUID)
+                yield self.removeShare(shareeView)
</ins><span class="cx">         else:
</span><span class="cx">             # This collection is shared to me
</span><span class="cx">             ownerHomeChild = yield self.ownerHome().childWithID(self._resourceID)
</span><del>-            yield ownerHomeChild.unshareWith(self._home)
</del><ins>+            yield ownerHomeChild.removeShare(self)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><span class="lines">@@ -3187,12 +3342,9 @@
</span><span class="cx">         for homeUID, homeRID, resourceID, resourceName, bindMode, bindStatus, bindMessage in acceptedRows: #@UnusedVariable
</span><span class="cx">             invite = SharingInvitation(
</span><span class="cx">                 resourceName,
</span><del>-                self._home.name(),
-                self._home._resourceID,
</del><ins>+                self.ownerHome().name(),
</ins><span class="cx">                 homeUID,
</span><del>-                homeRID,
-                resourceID,
-                resourceName if self.bindNameIsResourceName() else self.shareeName(),
</del><ins>+                resourceName,
</ins><span class="cx">                 bindMode,
</span><span class="cx">                 bindStatus,
</span><span class="cx">                 bindMessage,
</span><span class="lines">@@ -3216,13 +3368,23 @@
</span><span class="cx">         yield self.invalidateQueryCache()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareMode(self):
</del><ins>+    def sharedResourceType(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        @see: L{ICalendar.shareMode}
</del><ins>+        The sharing resource type. Needs to be overridden by each type of resource that can be shared.
+
+        @return: an identifier for the type of the share.
+        @rtype: C{str}
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        return self._bindMode
</del><ins>+        return &quot;&quot;
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def newShareName(self):
+        &quot;&quot;&quot;
+        Name used when creating a new share. By default this is a UUID.
+        &quot;&quot;&quot;
+        return str(uuid4())
+
+
</ins><span class="cx">     def owned(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @see: L{ICalendar.owned}
</span><span class="lines">@@ -3253,8 +3415,13 @@
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         assert self.owned()
</span><span class="cx"> 
</span><del>-        self._bindMessage = &quot;shared&quot; if shared else None
</del><ins>+        # Only if change is needed
+        newMessage = &quot;shared&quot; if shared else None
+        if self._bindMessage == newMessage:
+            returnValue(None)
</ins><span class="cx"> 
</span><ins>+        self._bindMessage = newMessage
+
</ins><span class="cx">         bind = self._bindSchema
</span><span class="cx">         yield Update(
</span><span class="cx">             {bind.MESSAGE: self._bindMessage},
</span><span class="lines">@@ -3266,20 +3433,42 @@
</span><span class="cx">         yield self.notifyPropertyChanged()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareeName(self):
</del><ins>+    def direct(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        The sharee's name for a shared L{CommonHomeChild} is the name of the resource by default.
</del><ins>+        Is this a &quot;direct&quot; share?
+
+        @return: a boolean indicating whether it's direct.
</ins><span class="cx">         &quot;&quot;&quot;
</span><ins>+        return self._bindMode == _BIND_MODE_DIRECT
+
+
+    def shareUID(self):
+        &quot;&quot;&quot;
+        @see: L{ICalendar.shareUID}
+        &quot;&quot;&quot;
</ins><span class="cx">         return self.name()
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def bindNameIsResourceName(self):
</del><ins>+    def shareMode(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        By default, the shared resource name of an accepted share is the same as the name in the bind table.
</del><ins>+        @see: L{ICalendar.shareMode}
</ins><span class="cx">         &quot;&quot;&quot;
</span><del>-        return True
</del><ins>+        return self._bindMode
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def shareName(self):
+        &quot;&quot;&quot;
+        This is a path like name for the resource within the home being shared. For object resource
+        shares this will be a combination of the L{CommonHomeChild} name and the L{CommonObjecrResource}
+        name. Otherwise it is just the L{CommonHomeChild} name. This is needed to expose a value to the
+        app-layer such that it can construct a URI for the actual WebDAV resource being shared.
+        &quot;&quot;&quot;
+        name = self.name()
+        if self.sharedResourceType() == &quot;group&quot;:
+            name = self.parentCollection().name() + &quot;/&quot; + name
+        return name
+
+
</ins><span class="cx">     def shareStatus(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @see: L{ICalendar.shareStatus}
</span><span class="lines">@@ -3294,13 +3483,6 @@
</span><span class="cx">         return self._bindMessage
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def shareUID(self):
-        &quot;&quot;&quot;
-        @see: L{ICalendar.shareUID}
-        &quot;&quot;&quot;
-        return self.name()
-
-
</del><span class="cx">     @classmethod
</span><span class="cx">     def metadataColumns(cls):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -3536,10 +3718,13 @@
</span><span class="cx"> 
</span><span class="cx">             child = cls(
</span><span class="cx">                 home=home,
</span><del>-                name=bindName, resourceID=resourceID,
-                mode=bindMode, status=bindStatus,
</del><ins>+                name=bindName,
+                resourceID=resourceID,
+                mode=bindMode,
+                status=bindStatus,
</ins><span class="cx">                 revision=bindRevision,
</span><del>-                message=bindMessage, ownerHome=ownerHome,
</del><ins>+                message=bindMessage,
+                ownerHome=ownerHome,
</ins><span class="cx">                 ownerName=ownerName,
</span><span class="cx">             )
</span><span class="cx">             for attr, value in zip(cls.additionalBindAttributes(), additionalBind):
</span><span class="lines">@@ -3558,11 +3743,21 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classmethod
</span><ins>+    def objectWithName(cls, home, name, accepted=True):
+        return cls.objectWithNameOrID(home, name=name, accepted=accepted)
+
+
+    @classmethod
+    def objectWithID(cls, home, resourceID, accepted=True):
+        return cls.objectWithNameOrID(home, resourceID=resourceID, accepted=accepted)
+
+
+    @classmethod
</ins><span class="cx">     @inlineCallbacks
</span><del>-    def objectWithName(cls, home, name, accepted=True):
</del><ins>+    def objectWithNameOrID(cls, home, name=None, resourceID=None, accepted=True):
</ins><span class="cx">         # replaces objectWithName()
</span><span class="cx">         &quot;&quot;&quot;
</span><del>-        Retrieve the child with the given C{name} contained in the given
</del><ins>+        Retrieve the child with the given C{name} or C{resourceID} contained in the given
</ins><span class="cx">         C{home}.
</span><span class="cx"> 
</span><span class="cx">         @param home: a L{CommonHome}.
</span><span class="lines">@@ -3577,97 +3772,65 @@
</span><span class="cx"> 
</span><span class="cx">         if queryCacher:
</span><span class="cx">             # Retrieve data from cache
</span><del>-            cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
</del><ins>+            if name:
+                cacheKey = queryCacher.keyForObjectWithName(home._resourceID, name)
+            else:
+                cacheKey = queryCacher.keyForObjectWithResourceID(home._resourceID, resourceID)
</ins><span class="cx">             rows = yield queryCacher.get(cacheKey)
</span><span class="cx"> 
</span><span class="cx">         if rows is None:
</span><span class="cx">             # No cached copy
</span><del>-            rows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
</del><ins>+            if name:
+                rows = yield cls._bindForNameAndHomeID.on(home._txn, name=name, homeID=home._resourceID)
+            else:
+                rows = yield cls._bindForResourceIDAndHomeID.on(home._txn, resourceID=resourceID, homeID=home._resourceID)
</ins><span class="cx"> 
</span><del>-            if rows and queryCacher:
-                # Cache the result
-                queryCacher.setAfterCommit(home._txn, cacheKey, rows)
-                queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithResourceID(home._resourceID, rows[0][2]), rows)
-
</del><span class="cx">         if not rows:
</span><span class="cx">             returnValue(None)
</span><span class="cx"> 
</span><span class="cx">         row = rows[0]
</span><del>-        bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
-        if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
</del><ins>+        bindMode, homeID, resourceID, name, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable
+
+        if queryCacher:
+            # Cache the result
+            queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithName(home._resourceID, name), rows)
+            queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithResourceID(home._resourceID, resourceID), rows)
+
+        if accepted is not None and (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
</ins><span class="cx">             returnValue(None)
</span><span class="cx">         additionalBind = row[cls.bindColumnCount:cls.bindColumnCount + len(cls.additionalBindColumns())]
</span><span class="cx"> 
</span><span class="cx">         if bindMode == _BIND_MODE_OWN:
</span><span class="cx">             ownerHome = home
</span><del>-            ownerName = bindName
</del><ins>+            ownerName = name
</ins><span class="cx">         else:
</span><span class="cx">             ownerHome, ownerName = yield home.ownerHomeAndChildNameForChildID(resourceID)
</span><span class="cx"> 
</span><span class="cx">         child = cls(
</span><span class="cx">             home=home,
</span><del>-            name=name, resourceID=resourceID,
-            mode=bindMode, status=bindStatus,
</del><ins>+            name=name,
+            resourceID=resourceID,
+            mode=bindMode,
+            status=bindStatus,
</ins><span class="cx">             revision=bindRevision,
</span><del>-            message=bindMessage, ownerHome=ownerHome,
</del><ins>+            message=bindMessage,
+            ownerHome=ownerHome,
</ins><span class="cx">             ownerName=ownerName
</span><span class="cx">         )
</span><span class="cx">         yield child.initFromStore(additionalBind)
</span><span class="cx">         returnValue(child)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @classmethod
-    @inlineCallbacks
-    def objectWithID(cls, home, resourceID, accepted=True):
-        &quot;&quot;&quot;
-        Retrieve the child with the given C{resourceID} contained in the given
-        C{home}.
-
-        @param home: a L{CommonHome}.
-        @param resourceID: a string.
-        @return: an L{CommonHomeChild} or C{None} if no such child
-            exists.
-        &quot;&quot;&quot;
-
-        rows = None
-        queryCacher = home._txn._queryCacher
-
-        if queryCacher:
-            # Retrieve data from cache
-            cacheKey = queryCacher.keyForObjectWithResourceID(home._resourceID, resourceID)
-            rows = yield queryCacher.get(cacheKey)
-
-        if rows is None:
-            # No cached copy
-            rows = yield cls._bindForResourceIDAndHomeID.on(home._txn, resourceID=resourceID, homeID=home._resourceID)
-
-            if rows and queryCacher:
-                # Cache the result (under both the ID and name values)
-                queryCacher.setAfterCommit(home._txn, cacheKey, rows)
-                queryCacher.setAfterCommit(home._txn, queryCacher.keyForObjectWithName(home._resourceID, rows[0][3]), rows)
-
-        if not rows:
-            returnValue(None)
-
-        row = rows[0]
-        bindMode, homeID, resourceID, bindName, bindStatus, bindRevision, bindMessage = row[:cls.bindColumnCount] #@UnusedVariable]
-        if (bindStatus == _BIND_STATUS_ACCEPTED) != bool(accepted):
-            returnValue(None)
-
-        if accepted:
-            returnValue((yield home.objectWithShareUID(bindName)))
-        else:
-            returnValue((yield home.invitedObjectWithShareUID(bindName)))
-
-
</del><span class="cx">     @classproperty
</span><span class="cx">     def _insertHomeChild(cls): #@NoSelf
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         DAL statement to create a home child with all default values.
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         child = cls._homeChildSchema
</span><del>-        return Insert({child.RESOURCE_ID: schema.RESOURCE_ID_SEQ},
-                      Return=(child.RESOURCE_ID))
</del><ins>+        return Insert(
+            {child.RESOURCE_ID: schema.RESOURCE_ID_SEQ},
+            Return=(child.RESOURCE_ID)
+        )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @classproperty
</span><span class="lines">@@ -5496,14 +5659,16 @@
</span><span class="cx">         if inserting:
</span><span class="cx">             rows = yield self._newNotificationQuery.on(
</span><span class="cx">                 self._txn, homeID=self._home._resourceID, uid=uid,
</span><del>-                notificationType=json.dumps(self._notificationType), notificationData=notificationtext, md5=self._md5
</del><ins>+                notificationType=json.dumps(self._notificationType),
+                notificationData=notificationtext, md5=self._md5
</ins><span class="cx">             )
</span><span class="cx">             self._resourceID, self._created, self._modified = rows[0]
</span><span class="cx">             self._loadPropertyStore()
</span><span class="cx">         else:
</span><span class="cx">             rows = yield self._updateNotificationQuery.on(
</span><span class="cx">                 self._txn, homeID=self._home._resourceID, uid=uid,
</span><del>-                notificationType=json.dumps(self._notificationType), notificationData=notificationtext, md5=self._md5
</del><ins>+                notificationType=json.dumps(self._notificationType),
+                notificationData=notificationtext, md5=self._md5
</ins><span class="cx">             )
</span><span class="cx">             self._modified = rows[0][0]
</span><span class="cx">         self._notificationData = notificationdata
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemacurrentoracledialectsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -101,6 +101,7 @@
</span><span class="cx"> insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('accepted', 1);
</span><span class="cx"> insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('declined', 2);
</span><span class="cx"> insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('invalid', 3);
</span><ins>+insert into CALENDAR_BIND_STATUS (DESCRIPTION, ID) values ('deleted', 4);
</ins><span class="cx"> create table CALENDAR_TRANSP (
</span><span class="cx">     &quot;ID&quot; integer primary key,
</span><span class="cx">     &quot;DESCRIPTION&quot; nvarchar2(16) unique
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_schemacurrentsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_schema/current.sql        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -181,6 +181,7 @@
</span><span class="cx"> insert into CALENDAR_BIND_STATUS values (1, 'accepted');
</span><span class="cx"> insert into CALENDAR_BIND_STATUS values (2, 'declined');
</span><span class="cx"> insert into CALENDAR_BIND_STATUS values (3, 'invalid');
</span><ins>+insert into CALENDAR_BIND_STATUS values (4, 'deleted');
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> -- Enumeration of transparency
</span><span class="lines">@@ -700,7 +701,7 @@
</span><span class="cx">   VALUE                         varchar(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><del>-insert into CALENDARSERVER values ('VERSION', '29');
</del><ins>+insert into CALENDARSERVER values ('VERSION', '30');
</ins><span class="cx"> insert into CALENDARSERVER values ('CALENDAR-DATAVERSION', '5');
</span><span class="cx"> insert into CALENDARSERVER values ('ADDRESSBOOK-DATAVERSION', '2');
</span><span class="cx"> insert into CALENDARSERVER values ('NOTIFICATION-DATAVERSION', '1');
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoresql_tablespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_tables.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_tables.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/sql_tables.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -142,6 +142,7 @@
</span><span class="cx"> _BIND_STATUS_ACCEPTED = _bindStatus('accepted')
</span><span class="cx"> _BIND_STATUS_DECLINED = _bindStatus('declined')
</span><span class="cx"> _BIND_STATUS_INVALID = _bindStatus('invalid')
</span><ins>+_BIND_STATUS_DELETED = _bindStatus('deleted')
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> _transpValues = _schemaConstants(
</span></span></pre></div>
<a id="CalendarServerbranchesuserscdaboosharinginthestoretxdavcommondatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/test/util.py (11959 => 11960)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/test/util.py        2013-11-16 05:15:04 UTC (rev 11959)
+++ CalendarServer/branches/users/cdaboo/sharing-in-the-store/txdav/common/datastore/test/util.py        2013-11-18 15:30:49 UTC (rev 11960)
</span><span class="lines">@@ -707,7 +707,36 @@
</span><span class="cx">                      .calendarObjectWithName(name)))
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def addressbookHomeUnderTest(self, txn=None, name=&quot;home1&quot;):
+        &quot;&quot;&quot;
+        Get the addressbook home detailed by C{requirements['home1']}.
+        &quot;&quot;&quot;
+        if txn is None:
+            txn = self.transactionUnderTest()
+        return txn.addressbookHomeWithUID(name)
</ins><span class="cx"> 
</span><ins>+
+    @inlineCallbacks
+    def addressbookUnderTest(self, txn=None, name=&quot;addressbook&quot;, home=&quot;home1&quot;):
+        &quot;&quot;&quot;
+        Get the addressbook detailed by C{requirements['home1']['addressbook']}.
+        &quot;&quot;&quot;
+        returnValue((yield
+            (yield self.addressbookHomeUnderTest(txn=txn, name=home)).addressbookWithName(name))
+        )
+
+
+    @inlineCallbacks
+    def addressbookObjectUnderTest(self, txn=None, name=&quot;1.vcf&quot;, addressbook_name=&quot;addressbook&quot;, home=&quot;home1&quot;):
+        &quot;&quot;&quot;
+        Get the addressbook detailed by
+        C{requirements['home1']['addressbook']['1.vcf']}.
+        &quot;&quot;&quot;
+        returnValue((yield (yield self.addressbookUnderTest(txn=txn, name=addressbook_name, home=home))
+                    .addressbookObjectWithName(name)))
+
+
+
</ins><span class="cx"> class StubNotifierFactory(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     For testing push notifications without an XMPP server.
</span></span></pre>
</div>
</div>

</body>
</html>