<!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>[13846] CalendarServer/trunk</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/13846">13846</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-08-07 00:41:08 -0700 (Thu, 07 Aug 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>fix invite and access privs for group sharees</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavsharingpy">CalendarServer/trunk/twistedcaldav/sharing.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresqlpy">CalendarServer/trunk/txdav/common/datastore/sql.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavsharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/sharing.py (13845 => 13846)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/sharing.py        2014-08-07 05:32:02 UTC (rev 13845)
+++ CalendarServer/trunk/twistedcaldav/sharing.py        2014-08-07 07:41:08 UTC (rev 13846)
</span><span class="lines">@@ -25,29 +25,30 @@
</span><span class="cx">     &quot;SharedHomeMixin&quot;,
</span><span class="cx"> ]
</span><span class="cx"> 
</span><del>-from txweb2 import responsecode
-from txweb2.http import HTTPError, Response, XMLResponse
-from txweb2.dav.http import ErrorResponse, MultiStatusResponse
-from txweb2.dav.resource import TwistedACLInheritable
-from txweb2.dav.util import allDataFromStream, joinURL
</del><ins>+from twext.who.idirectory import RecordType
</ins><span class="cx"> 
</span><del>-from txdav.common.datastore.sql_tables import _BIND_MODE_OWN, \
-    _BIND_MODE_READ, _BIND_MODE_WRITE, _BIND_STATUS_INVITED, \
-    _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
-    _BIND_STATUS_INVALID, _ABO_KIND_GROUP, _BIND_STATUS_DELETED, \
-    _BIND_MODE_DIRECT, _BIND_MODE_INDIRECT
-from txdav.xml import element
-
</del><span class="cx"> from twisted.internet.defer import succeed, inlineCallbacks, DeferredList, \
</span><span class="cx">     returnValue
</span><span class="cx"> 
</span><span class="cx"> from twistedcaldav import customxml, caldavxml
</span><span class="cx"> from twistedcaldav.config import config
</span><span class="cx"> from twistedcaldav.customxml import calendarserver_namespace
</span><del>-from txdav.who.wiki import RecordType as WikiRecordType, WikiAccessLevel
</del><span class="cx"> from twistedcaldav.linkresource import LinkFollowerMixIn
</span><span class="cx"> 
</span><ins>+from txdav.common.datastore.sql_tables import _ABO_KIND_GROUP, \
+    _BIND_MODE_DIRECT, _BIND_MODE_INDIRECT, _BIND_MODE_OWN, _BIND_MODE_READ, \
+    _BIND_MODE_WRITE, _BIND_STATUS_ACCEPTED, _BIND_STATUS_DECLINED, \
+    _BIND_STATUS_DELETED, _BIND_STATUS_INVALID, _BIND_STATUS_INVITED
+from txdav.xml import element
+from txdav.who.wiki import RecordType as WikiRecordType, WikiAccessLevel
</ins><span class="cx"> 
</span><ins>+from txweb2 import responsecode
+from txweb2.dav.http import ErrorResponse, MultiStatusResponse
+from txweb2.dav.resource import TwistedACLInheritable
+from txweb2.dav.util import allDataFromStream, joinURL
+from txweb2.http import HTTPError, Response, XMLResponse
+
+
</ins><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="lines">@@ -434,6 +435,28 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><ins>+    def principalForCalendarGroupAddress(self, groupid):
+        &quot;&quot;&quot;
+        Get principal for group address if extant
+        &quot;&quot;&quot;
+
+        if (
+            config.Sharing.Enabled and
+            config.Sharing.Calendars.Enabled and
+            config.Sharing.Calendars.Groups.Enabled
+        ):
+            # see if group
+            for principalCollection in self.principalCollections():
+                record = yield principalCollection.directory.recordWithCalendarUserAddress(groupid)
+                if record is not None and record.recordType == RecordType.group:
+                    groupPrincipal = yield principalCollection.principalForRecord(record)
+                    if groupPrincipal is not None:
+                        returnValue(groupPrincipal)
+
+        returnValue(None)
+
+
+    @inlineCallbacks
</ins><span class="cx">     def validateInvites(self, request, invitations=None):
</span><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="lines">@@ -447,6 +470,14 @@
</span><span class="cx">                 if not (yield self.validUserIDForShare(&quot;urn:x-uid:&quot; + invitation.shareeUID, request)):
</span><span class="cx">                     self.log.error(&quot;Invalid sharee detected: {uid}&quot;, uid=invitation.shareeUID)
</span><span class="cx">                     invitation = invitation._replace(status=_BIND_STATUS_INVALID)
</span><ins>+
+            invitation = invitation._replace(
+                mode=(
+                    yield self._newStoreObject._effectiveShareMode(
+                        invitation.mode, invitation.shareeUID, self._newStoreObject._txn
+                    )
+                )
+            )
</ins><span class="cx">             adjusted_invitations.append(invitation)
</span><span class="cx"> 
</span><span class="cx">         returnValue(adjusted_invitations)
</span><span class="lines">@@ -513,8 +544,10 @@
</span><span class="cx"> 
</span><span class="cx">         # We currently only handle local users
</span><span class="cx">         sharee = yield self.principalForCalendarUserAddress(userid)
</span><del>-        if not sharee:
-            returnValue(False)
</del><ins>+        if sharee is None:
+            sharee = yield self.principalForCalendarGroupAddress(userid)
+            if sharee is None:
+                returnValue(False)
</ins><span class="cx"> 
</span><span class="cx">         result = (yield self._newStoreObject.inviteUIDToShare(
</span><span class="cx">             sharee.principalUID(),
</span><span class="lines">@@ -640,7 +673,9 @@
</span><span class="cx"> 
</span><span class="cx">                 # Validate each userid on add only
</span><span class="cx">                 uid = (yield self.validUserIDForShare(userid, request))
</span><del>-                (okusers if uid is not None else badusers).add(userid)
</del><ins>+                if uid is None:
+                    uid = yield self.principalForCalendarGroupAddress(userid)
+                (badusers if uid is None else okusers).add(userid)
</ins><span class="cx">             elif isinstance(item, customxml.InviteRemove):
</span><span class="cx">                 userid, access = _handleInviteRemove(item)
</span><span class="cx">                 removeDict[userid] = access
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13845 => 13846)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-08-07 05:32:02 UTC (rev 13845)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-08-07 07:41:08 UTC (rev 13846)
</span><span class="lines">@@ -1950,11 +1950,15 @@
</span><span class="cx">         returnValue(changed)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @classmethod
</ins><span class="cx">     @inlineCallbacks
</span><del>-    def effectiveShareMode(self):
-        if self._bindMode == _BIND_MODE_GROUP_WRITE:
</del><ins>+    def _effectiveShareMode(cls, bindMode, viewerUID, txn):
+        &quot;&quot;&quot;
+        Get the effective share mode without a calendar object
+        &quot;&quot;&quot;
+        if bindMode == _BIND_MODE_GROUP_WRITE:
</ins><span class="cx">             returnValue(_BIND_MODE_WRITE)
</span><del>-        elif self._bindMode in (_BIND_MODE_GROUP, _BIND_MODE_GROUP_READ):
</del><ins>+        elif bindMode in (_BIND_MODE_GROUP, _BIND_MODE_GROUP_READ):
</ins><span class="cx">             gs = schema.GROUP_SHAREE
</span><span class="cx">             gm = schema.GROUP_MEMBERSHIP
</span><span class="cx">             rows = yield Select(
</span><span class="lines">@@ -1971,12 +1975,19 @@
</span><span class="cx">                         )
</span><span class="cx">                     )
</span><span class="cx">                 )
</span><del>-            ).on(self._txn, uid=self.viewerHome().uid())
</del><ins>+            ).on(txn, uid=viewerUID)
</ins><span class="cx">             returnValue(rows[0][0])
</span><span class="cx">         else:
</span><del>-            returnValue(self._bindMode)
</del><ins>+            returnValue(bindMode)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    def effectiveShareMode(self):
+        &quot;&quot;&quot;
+        Get the high level sharemode for calendars shared to users or groups
+        &quot;&quot;&quot;
+        return self._effectiveShareMode(self._bindMode, self.viewerHome().uid(), self._txn)
+
+
</ins><span class="cx">     #
</span><span class="cx">     # Higher level API
</span><span class="cx">     #
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql.py (13845 => 13846)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql.py        2014-08-07 05:32:02 UTC (rev 13845)
+++ CalendarServer/trunk/txdav/common/datastore/sql.py        2014-08-07 07:41:08 UTC (rev 13846)
</span><span class="lines">@@ -5282,6 +5282,14 @@
</span><span class="cx">         return self._bindMode
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @classmethod
+    def _effectiveShareMode(cls, bindMode, viewerUID, txn):
+        &quot;&quot;&quot;
+        Get the effective share mode without a calendar object
+        &quot;&quot;&quot;
+        return bindMode
+
+
</ins><span class="cx">     def effectiveShareMode(self):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         @see: L{ICalendar.shareMode}
</span></span></pre>
</div>
</div>

</body>
</html>