<!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>[13736] CalendarServer/branches/users/gaya/groupsharee2/txdav</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/13736">13736</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-07-08 17:54:03 -0700 (Tue, 08 Jul 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Allow group and individual sharee at the same time.  Use higher-level sharing API for group sharee mods.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcaldavdatastoresqlpy">CalendarServer/branches/users/gaya/groupsharee2/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresqlpy">CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql.py</a></li>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemacurrentoracledialectsql">CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current-oracle-dialect.sql</a></li>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemacurrentsql">CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current.sql</a></li>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_45_to_46sql">CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_45_to_46.sql</a></li>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_45_to_46sql">CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_45_to_46.sql</a></li>
<li><a href="#CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_tablespy">CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_tables.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/caldav/datastore/sql.py (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/caldav/datastore/sql.py        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/caldav/datastore/sql.py        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -82,11 +82,10 @@
</span><span class="cx"> from txdav.common.datastore.sql import CommonHome, CommonHomeChild, \
</span><span class="cx">     CommonObjectResource, ECALENDARTYPE
</span><span class="cx"> from txdav.common.datastore.sql_tables import _ATTACHMENTS_MODE_NONE, \
</span><del>-    _ATTACHMENTS_MODE_WRITE, schema, _BIND_MODE_OWN, \
-    _ATTACHMENTS_MODE_READ, _TRANSP_OPAQUE, _TRANSP_TRANSPARENT, \
-    _BIND_MODE_GROUP, _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_MODE_DIRECT, \
-    _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, _BIND_STATUS_INVALID, \
-    _BIND_STATUS_INVITED, _BIND_STATUS_DELETED
</del><ins>+    _ATTACHMENTS_MODE_READ, _ATTACHMENTS_MODE_WRITE, _BIND_MODE_DIRECT, \
+    _BIND_MODE_GROUP, _BIND_MODE_GROUP_READ, _BIND_MODE_GROUP_WRITE, \
+    _BIND_MODE_OWN, _BIND_MODE_READ, _BIND_MODE_WRITE, _TRANSP_OPAQUE, \
+    _TRANSP_TRANSPARENT, schema
</ins><span class="cx"> from txdav.common.icommondatastore import IndexedSearchException, \
</span><span class="cx">     InternalDataStoreError, HomeChildNameAlreadyExistsError, \
</span><span class="cx">     HomeChildNameNotAllowedError, ObjectResourceTooBigError, \
</span><span class="lines">@@ -1755,55 +1754,7 @@
</span><span class="cx">     #===============================================================================
</span><span class="cx">     # Group sharing
</span><span class="cx">     #===============================================================================
</span><del>-    @inlineCallbacks
-    def shareWithUID(self, shareeUID, mode, status=None, summary=None, shareName=None):
-        &quot;&quot;&quot;
-        Share this (owned) L{CommonHomeChild} with another principal.
</del><span class="cx"> 
</span><del>-        @param shareeUID: The UID of the sharee.
-        @type: L{str}
-
-        @param mode: The sharing mode; L{_BIND_MODE_READ} or
-            L{_BIND_MODE_WRITE} or L{_BIND_MODE_DIRECT}
-        @type mode: L{str}
-
-        @param status: The sharing status; L{_BIND_STATUS_INVITED} or
-            L{_BIND_STATUS_ACCEPTED}
-        @type: L{str}
-
-        @param summary: The proposed message to go along with the share, which
-            will be used as the default display name.
-        @type: L{str}
-
-        @return: the name of the shared calendar in the new calendar home.
-        @rtype: L{str}
-        &quot;&quot;&quot;
-        record = yield self._txn.directoryService().recordWithUID(shareeUID.decode(&quot;utf-8&quot;))
-        if (
-            record is None or
-            record.type() != RecordType.group or not (False and
-                config.Sharing.Enabled and
-                config.Sharing.Calendars.Enabled and
-                config.Sharing.Calendars.Groups.Enabled
-            )
-        ):
-            shareeHome = yield self._txn.calendarHomeWithUID(shareeUID, create=True)
-            returnValue(
-                (yield self.shareWith(shareeHome, mode, status, summary, shareName))
-            )
-
-        # shareWith every member of group not already shared to
-        groupID = (yield self._txn.groupByUID(record.uid))[0]
-        memberUIDs = yield self._txn.groupMemberUIDs(groupID)
-        for memberUID in memberUIDs:
-            shareeHome = yield self._txn.calendarHomeWithUID(memberUID, create=True)
-            if (yield shareeHome.childWithID(self._resourceID)) is None:
-                yield self.shareWith(shareeHome, _BIND_MODE_GROUP, status)
-
-        yield self.updateShareeGroupLink(shareeUID, mode)
-        returnValue(None)
-
-
</del><span class="cx">     @inlineCallbacks
</span><span class="cx">     def reconcileGroupSharee(self, groupUID):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="lines">@@ -1823,8 +1774,10 @@
</span><span class="cx">                 [bind.HOME_RESOURCE_ID],
</span><span class="cx">                 From=bind,
</span><span class="cx">                 Where=bind.CALENDAR_RESOURCE_ID == self._resourceID.And(
</span><del>-                    bind.BIND_MODE == _BIND_MODE_GROUP
-                ),
</del><ins>+                    (bind.BIND_MODE == _BIND_MODE_GROUP).Or(
+                     bind.BIND_MODE == _BIND_MODE_GROUP_READ).Or(
+                     bind.BIND_MODE == _BIND_MODE_GROUP_WRITE)
+                )
</ins><span class="cx">             ).on(self._txn)
</span><span class="cx">             groupShareeHomeIDs = [row[0] for row in rows]
</span><span class="cx">             for groupShareeHomeID in groupShareeHomeIDs:
</span><span class="lines">@@ -1832,20 +1785,65 @@
</span><span class="cx">                 if shareeHome.uid() in memberUIDs:
</span><span class="cx">                     boundUIDs.add(shareeHome.uid())
</span><span class="cx">                 else:
</span><del>-                    shareeView = yield shareeHome.childWithID(self._resourceID)
-                    yield self.removeShare(shareeView)
</del><ins>+                    yield self.uninviteUIDFromShare(shareeHome.uid())
</ins><span class="cx">                     changed = True
</span><span class="cx"> 
</span><span class="cx">             for memberUID in memberUIDs - boundUIDs:
</span><del>-                shareeHome = yield self._txn.calendarHomeWithUID(memberUID, create=True)
-                if (yield shareeHome.childWithID(self._resourceID)) is None:
-                    yield self.shareWith(shareeHome, _BIND_MODE_GROUP)
</del><ins>+                shareeView = yield self.shareeView(memberUID)
+                newMode = _BIND_MODE_GROUP if shareeView is None else shareeView.groupModeAfterAddingOneGroupSharee()
+                if newMode is not None:
+                    yield super(Calendar, self).inviteUIDToShare(memberUID, newMode)
</ins><span class="cx">                     changed = True
</span><span class="cx"> 
</span><span class="cx">         returnValue(changed)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def groupModeAfterAddingOneGroupSharee(self):
+        &quot;&quot;&quot;
+        return group mode after adding one group sharee or None
+        &quot;&quot;&quot;
+        return {
+            _BIND_MODE_GROUP: _BIND_MODE_GROUP,
+            _BIND_MODE_READ: _BIND_MODE_GROUP_READ,
+            _BIND_MODE_GROUP_READ: _BIND_MODE_GROUP_READ,
+            _BIND_MODE_WRITE: _BIND_MODE_GROUP_WRITE,
+            _BIND_MODE_GROUP_WRITE: _BIND_MODE_GROUP_WRITE,
+        }.get(self.shareMode())
+
+
</ins><span class="cx">     @inlineCallbacks
</span><ins>+    def groupModeAfterRemovingOneGroupSharee(self):
+        &quot;&quot;&quot;
+        return group mode after removing one group sharee or None
+        &quot;&quot;&quot;
+        # if more than one group
+        gs = schema.GROUP_SHAREE
+        rows = yield Select(
+            [Count(gs.GROUP_ID)],
+            From=gs,
+            Where=(gs.CALENDAR_HOME_ID == self.ownerHome()._resourceID).And(
+                gs.CALENDAR_ID == self._resourceID)
+        ).on(self._txn)
+        if rows[0][0] &gt; 1:
+            # no mode change for group shares
+            returnValue(
+                {
+                    _BIND_MODE_GROUP: _BIND_MODE_GROUP,
+                    _BIND_MODE_GROUP_READ: _BIND_MODE_GROUP_READ,
+                    _BIND_MODE_GROUP_WRITE: _BIND_MODE_GROUP_WRITE,
+                }.get(self.shareMode())
+            )
+
+        # else return mode without any groups
+        returnValue(
+            {
+                _BIND_MODE_GROUP_READ: _BIND_MODE_READ,
+                _BIND_MODE_GROUP_WRITE: _BIND_MODE_WRITE,
+            }.get(self.shareMode())
+        )
+
+
+    @inlineCallbacks
</ins><span class="cx">     def updateShareeGroupLink(self, groupUID, mode=None):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         update schema.GROUP_SHAREE
</span><span class="lines">@@ -1893,102 +1891,33 @@
</span><span class="cx">         returnValue(changed)
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
</del><span class="cx">     def effectiveShareMode(self):
</span><del>-        if self._bindMode == _BIND_MODE_GROUP:
</del><ins>+        return self._effectiveShareMode(
+            self._bindMode, self.ownerHome()._resourceID,
+            self._resourceID, self._txn
+        )
+
+
+    @classmethod
+    @inlineCallbacks
+    def _effectiveShareMode(cls, bindMode, homeID, childID, txn):
+        if bindMode == _BIND_MODE_GROUP_WRITE:
+            returnValue(_BIND_MODE_WRITE)
+        elif bindMode in (_BIND_MODE_GROUP, _BIND_MODE_GROUP_READ):
</ins><span class="cx">             gs = schema.GROUP_SHAREE
</span><span class="cx">             rows = yield Select(
</span><span class="cx">                 [Max(gs.GROUP_BIND_MODE)], # _BIND_MODE_WRITE &gt; _BIND_MODE_READ
</span><span class="cx">                 From=gs,
</span><del>-                Where=(gs.CALENDAR_HOME_ID == self.ownerHome()._resourceID).And(
-                    gs.CALENDAR_ID == self._resourceID
</del><ins>+                Where=(gs.CALENDAR_HOME_ID == homeID).And(
+                    gs.CALENDAR_ID == childID
</ins><span class="cx">                 )
</span><del>-            ).on(self._txn)
</del><ins>+            ).on(txn)
</ins><span class="cx">             groupShareMode = rows[0][0]
</span><span class="cx">             returnValue(groupShareMode)
</span><span class="cx">         else:
</span><del>-            returnValue(self._bindMode)
</del><ins>+            returnValue(bindMode)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    @inlineCallbacks
-    def removeShare(self, shareeView):
-        &quot;&quot;&quot;
-        Remove the shared version of this (owned) L{CommonHomeChild} from the
-        referenced L{CommonHome}.
-
-        If user share and user is in shared group, change to group share.
-
-        @see: L{CommonHomeChild.shareWith}
-
-        @param shareeView: The shared resource being removed.
-
-        @return: a L{Deferred} which will fire with the previous shareUID
-        &quot;&quot;&quot;
-
-        # see if after share is removed, user is still shared by a group sharee
-        if shareeView.shareMode() in (_BIND_MODE_DIRECT, _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_MODE_GROUP):
-
-            gs = schema.GROUP_SHAREE
-            rows = yield Select(
-                [gs.GROUP_ID],
-                From=gs,
-                Where=(gs.CALENDAR_HOME_ID == self.ownerHome()._resourceID).And(
-                    gs.CALENDAR_ID == self._resourceID)
-            ).on(self._txn)
-            groupIDs = [row[0] for row in rows]
-
-            shareeHomeUID = shareeView.viewerHome().uid()
-            for groupID in groupIDs:
-                memberUIDs = yield self._txn.groupMemberUIDs(groupID) # must be cached
-                if shareeHomeUID in memberUIDs:
-                    yield self.updateShare(shareeView, mode=_BIND_MODE_GROUP)
-                    returnValue(None)
-
-        # no group sharee for this user so let super do work
-        returnValue((yield super(Calendar, self).removeShare(shareeView)))
-
-        #TODO: effectiveShareMode may change between _BIND_MODE_READ &amp; _BIND_MODE_READ.
-        #        Is that OK?
-
-
-    @inlineCallbacks
-    def removeShareWithUID(self, shareeUID):
-        &quot;&quot;&quot;
-        Unshare this (owned) L{CommonHomeChild} with another principal.
-
-        @param shareeUID: The UID of the sharee.
-        @type: L{str}
-        &quot;&quot;&quot;
-        record = yield self._txn.directoryService().recordWithUID(shareeUID.decode(&quot;utf-8&quot;))
-        if (
-            record is None or
-            record.recordType != RecordType.group or not (False and
-                config.Sharing.Enabled and
-                config.Sharing.Calendars.Enabled and
-                config.Sharing.Calendars.Groups.Enabled
-            )
-        ):
-            returnValue(None)
-
-        # get group membership
-        groupID = (yield self._txn.groupByUID(record.uid))[0]
-        memberUIDs = yield self._txn.groupMemberUIDs(groupID)
-
-        # update groupsharee so that removeShare works
-        gs = schema.GROUP_SHAREE
-        yield Delete(
-            From=gs,
-            Where=(gs.CALENDAR_HOME_ID == self.ownerHome()._resourceID).And(
-                gs.CALENDAR_ID == self._resourceID).And(
-                gs.GROUP_ID == groupID)
-        ).on(self._txn)
-
-        for memberUID in memberUIDs:
-            shareeHome = yield self._txn.calendarHomeWithUID(memberUID, create=True)
-            shareeView = yield shareeHome.childWithID(self._resourceID)
-            yield self.removeShare(shareeView)
-
-
</del><span class="cx">     #
</span><span class="cx">     # Higher level API
</span><span class="cx">     #
</span><span class="lines">@@ -2009,7 +1938,7 @@
</span><span class="cx">         record = yield self._txn.directoryService().recordWithUID(shareeUID.decode(&quot;utf-8&quot;))
</span><span class="cx">         if (
</span><span class="cx">             record is None or
</span><del>-            record.type() != RecordType.group or not (False and
</del><ins>+            record.recordType != RecordType.group or not (False and
</ins><span class="cx">                 config.Sharing.Enabled and
</span><span class="cx">                 config.Sharing.Calendars.Enabled and
</span><span class="cx">                 config.Sharing.Calendars.Groups.Enabled
</span><span class="lines">@@ -2024,9 +1953,9 @@
</span><span class="cx">         memberUIDs = yield self._txn.groupMemberUIDs(groupID)
</span><span class="cx">         for memberUID in memberUIDs:
</span><span class="cx">             shareeView = yield self.shareeView(shareeUID)
</span><del>-            if shareeView is None:
-                yield super(Calendar, self).inviteUIDToShare(memberUID, _BIND_MODE_GROUP, summary, shareName)
-            # FIX ME:
</del><ins>+            newMode = _BIND_MODE_GROUP if shareeView is None else shareeView.groupModeAfterAddingOneGroupSharee()
+            if newMode is not None:
+                yield super(Calendar, self).inviteUIDToShare(memberUID, newMode)
</ins><span class="cx"> 
</span><span class="cx">         returnValue(None)
</span><span class="cx"> 
</span><span class="lines">@@ -2069,19 +1998,12 @@
</span><span class="cx"> 
</span><span class="cx">         shareeView = yield self.shareeView(shareeUID)
</span><span class="cx">         if shareeView is not None:
</span><del>-            if shareeView.viewerHome().external():
-                yield self._sendExternalUninvite(shareeView)
</del><ins>+            newMode = yield shareeView.groupModeAfterRemovingOneGroupSharee()
+            if newMode is None:
+                yield super(Calendar, self).uninviteUIDFromShare(shareeUID)
</ins><span class="cx">             else:
</span><del>-                # 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 not shareeView.direct():
-                    if shareeView.shareStatus() != _BIND_STATUS_ACCEPTED:
-                        yield self._removeInviteNotification(shareeView)
-                    else:
-                        yield self._sendInviteNotification(shareeView, notificationState=_BIND_STATUS_DELETED)
</del><ins>+                yield super(Calendar, self).inviteUIDToShare(shareeUID, newMode)
</ins><span class="cx"> 
</span><del>-            # Remove the bind
-            yield self.removeShare(shareeView)
</del><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> icalfbtype_to_indexfbtype = {
</span></span></pre></div>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql.py (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql.py        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql.py        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -61,12 +61,12 @@
</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.podding.conduit import PoddingConduit
</span><del>-from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
-    _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, _BIND_STATUS_INVALID, \
-    _BIND_STATUS_INVITED, _BIND_MODE_DIRECT, _BIND_STATUS_DELETED, \
-    _BIND_MODE_INDIRECT, _HOME_STATUS_NORMAL, _HOME_STATUS_EXTERNAL, \
-    _HOME_STATUS_PURGING
-from txdav.common.datastore.sql_tables import schema, splitSQLString
</del><ins>+from txdav.common.datastore.sql_tables import _BIND_MODE_DIRECT, \
+    _BIND_MODE_GROUP, _BIND_MODE_GROUP_READ, _BIND_MODE_GROUP_WRITE, \
+    _BIND_MODE_INDIRECT, _BIND_MODE_OWN, _BIND_STATUS_ACCEPTED, \
+    _BIND_STATUS_DECLINED, _BIND_STATUS_DELETED, _BIND_STATUS_INVALID, \
+    _BIND_STATUS_INVITED, _HOME_STATUS_EXTERNAL, _HOME_STATUS_NORMAL, \
+    _HOME_STATUS_PURGING, schema, splitSQLString
</ins><span class="cx"> from txdav.common.icommondatastore import ConcurrentModification, \
</span><span class="cx">     RecordNotAllowedError, ExternalShareFailed, ShareNotAllowed, \
</span><span class="cx">     IndexedSearchException, NotFoundError
</span><span class="lines">@@ -81,7 +81,6 @@
</span><span class="cx"> from txdav.common.inotifications import INotificationCollection, \
</span><span class="cx">     INotificationObject
</span><span class="cx"> from txdav.idav import ChangeCategory
</span><del>-from twext.who.idirectory import RecordType
</del><span class="cx"> from txdav.xml import element
</span><span class="cx"> 
</span><span class="cx"> from uuid import uuid4, UUID
</span><span class="lines">@@ -4563,7 +4562,7 @@
</span><span class="cx">     # Higher level API
</span><span class="cx">     #
</span><span class="cx">     @inlineCallbacks
</span><del>-    def inviteUIDToShare(self, shareeUID, mode, summary, shareName=None):
</del><ins>+    def inviteUIDToShare(self, shareeUID, mode, summary=None, shareName=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Invite a user to share this collection - either create the share if it does not exist, or
</span><span class="cx">         update the existing share with new values. Make sure a notification is sent as well.
</span><span class="lines">@@ -5028,16 +5027,18 @@
</span><span class="cx"> 
</span><span class="cx">         #remove None parameters, and substitute None for empty string
</span><span class="cx">         bind = self._bindSchema
</span><del>-        columnMap = dict([(k, v if v != &quot;&quot; else None) for k, v in {
-            bind.BIND_MODE:mode,
-            bind.BIND_STATUS:status,
-            bind.MESSAGE:summary
-        }.iteritems() if v is not None])
</del><ins>+        columnMap = {}
+        if mode != None and mode != self._bindMode:
+            columnMap[bind.BIND_MODE] = mode
+        if status != None:# and status != self._bindStatus:  # FIXME:
+            columnMap[bind.BIND_STATUS] = status
+        if summary != None and summary and summary != self._bindMessage:
+            columnMap[bind.MESSAGE] = summary
</ins><span class="cx"> 
</span><span class="cx">         if columnMap:
</span><span class="cx"> 
</span><span class="cx">             # Count accepted
</span><del>-            if status is not None:
</del><ins>+            if bind.BIND_STATUS in columnMap:
</ins><span class="cx">                 previouslyAcceptedCount = yield shareeView._previousAcceptCount()
</span><span class="cx"> 
</span><span class="cx">             yield self._updateBindColumnsQuery(columnMap).on(
</span><span class="lines">@@ -5142,12 +5143,20 @@
</span><span class="cx">             returnValue([])
</span><span class="cx"> 
</span><span class="cx">         # get all accepted binds
</span><del>-        acceptedRows = yield self._sharedInvitationBindForResourceID.on(
</del><ins>+        invitedRows = yield self._sharedInvitationBindForResourceID.on(
</ins><span class="cx">             self._txn, resourceID=self._resourceID, homeID=self._home._resourceID
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx">         result = []
</span><del>-        for homeUID, homeRID, _ignore_resourceID, resourceName, bindMode, bindStatus, bindMessage in acceptedRows:
</del><ins>+        for homeUID, homeRID, _ignore_resourceID, resourceName, bindMode, bindStatus, bindMessage in invitedRows:
+
+            # performance optimzation: don't instantiate viewer or viewer home
+            if bindMode in (_BIND_MODE_GROUP, _BIND_MODE_GROUP_READ, _BIND_MODE_GROUP_WRITE):
+                bindMode = yield self._effectiveShareMode(
+                    bindMode, homeRID,
+                    self._resourceID, self._txn
+                )
+
</ins><span class="cx">             invite = SharingInvitation(
</span><span class="cx">                 resourceName,
</span><span class="cx">                 self.ownerHome().name(),
</span><span class="lines">@@ -5283,6 +5292,11 @@
</span><span class="cx">         return self._bindMode
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @classmethod
+    def _effectiveShareMode(cls, bindMode, homeID, childID, txn):
+        return bindMode
+
+
</ins><span class="cx">     def shareName(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         This is a path like name for the resource within the home being shared. For object resource
</span></span></pre></div>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemacurrentoracledialectsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current-oracle-dialect.sql (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current-oracle-dialect.sql        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -117,6 +117,8 @@
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('direct', 3);
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('indirect', 4);
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group', 5);
</span><ins>+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group,read', 6);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group,write', 7);
</ins><span class="cx"> create table CALENDAR_BIND_STATUS (
</span><span class="cx">     &quot;ID&quot; integer primary key,
</span><span class="cx">     &quot;DESCRIPTION&quot; nvarchar2(16) unique
</span><span class="lines">@@ -595,7 +597,7 @@
</span><span class="cx">     &quot;VALUE&quot; nvarchar2(255)
</span><span class="cx"> );
</span><span class="cx"> 
</span><del>-insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '45');
</del><ins>+insert into CALENDARSERVER (NAME, VALUE) values ('VERSION', '46');
</ins><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('CALENDAR-DATAVERSION', '6');
</span><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('ADDRESSBOOK-DATAVERSION', '2');
</span><span class="cx"> insert into CALENDARSERVER (NAME, VALUE) values ('NOTIFICATION-DATAVERSION', '1');
</span><span class="lines">@@ -765,7 +767,7 @@
</span><span class="cx">     JOB_ID
</span><span class="cx"> );
</span><span class="cx"> 
</span><del>-create index GROUP_ATTENDEE_ID_d497ffdb on GROUP_ATTENDEE (
</del><ins>+create index GROUP_ATTENDEE_RESOUR_855124dc on GROUP_ATTENDEE (
</ins><span class="cx">     RESOURCE_ID
</span><span class="cx"> );
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemacurrentsql"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current.sql (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current.sql        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/current.sql        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -205,6 +205,8 @@
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (3, 'direct');
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (4, 'indirect');
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (5, 'group');
</span><ins>+insert into CALENDAR_BIND_MODE values (6, 'group,read');
+insert into CALENDAR_BIND_MODE values (7, 'group,write');
</ins><span class="cx"> 
</span><span class="cx"> -- Enumeration of statuses
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemaupgradesoracledialectupgrade_from_45_to_46sql"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_45_to_46.sql (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_45_to_46.sql        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/oracle-dialect/upgrade_from_45_to_46.sql        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -19,7 +19,10 @@
</span><span class="cx"> ---------------------------------------------------
</span><span class="cx"> 
</span><span class="cx"> insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group', 5);
</span><ins>+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group,read', 6);
+insert into CALENDAR_BIND_MODE (DESCRIPTION, ID) values ('group,write', 7);
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> create table GROUP_SHAREE_RECONCILE_WORK (
</span><span class="cx">   WORK_ID                       integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</span><span class="cx">   JOB_ID                        integer not null references JOB,
</span></span></pre></div>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_schemaupgradespostgresdialectupgrade_from_45_to_46sql"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_45_to_46.sql (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_45_to_46.sql        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_schema/upgrades/postgres-dialect/upgrade_from_45_to_46.sql        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -19,7 +19,10 @@
</span><span class="cx"> ---------------------------------------------------
</span><span class="cx"> 
</span><span class="cx"> insert into CALENDAR_BIND_MODE values (5, 'group');
</span><ins>+insert into CALENDAR_BIND_MODE values (6, 'group,read');
+insert into CALENDAR_BIND_MODE values (7, 'group,write');
</ins><span class="cx"> 
</span><ins>+
</ins><span class="cx"> create table GROUP_SHAREE_RECONCILE_WORK (
</span><span class="cx">   WORK_ID                       integer primary key default nextval('WORKITEM_SEQ') not null, -- implicit index
</span><span class="cx">   JOB_ID                        integer not null references JOB,
</span></span></pre></div>
<a id="CalendarServerbranchesusersgayagroupsharee2txdavcommondatastoresql_tablespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_tables.py (13735 => 13736)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_tables.py        2014-07-08 20:21:56 UTC (rev 13735)
+++ CalendarServer/branches/users/gaya/groupsharee2/txdav/common/datastore/sql_tables.py        2014-07-09 00:54:03 UTC (rev 13736)
</span><span class="lines">@@ -231,6 +231,8 @@
</span><span class="cx"> _BIND_MODE_DIRECT = _bindMode('direct')
</span><span class="cx"> _BIND_MODE_INDIRECT = _bindMode('indirect')
</span><span class="cx"> _BIND_MODE_GROUP = _bindMode('group')
</span><ins>+_BIND_MODE_GROUP_READ = _bindMode('group,read')
+_BIND_MODE_GROUP_WRITE = _bindMode('group,write')
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> _addressBookObjectKind = _schemaConstants(
</span></span></pre>
</div>
</div>

</body>
</html>