<!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>[14689] 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/14689">14689</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2015-04-20 11:35:33 -0700 (Mon, 20 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Direct sharee's copy gets displayname from sharer's fullname if displayname not explicitly set</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="#CalendarServertrunktxdavcaldavdatastoretesttest_sql_sharingpy">CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py</a></li>
<li><a href="#CalendarServertrunktxdavcommondatastoresql_sharingpy">CalendarServer/trunk/txdav/common/datastore/sql_sharing.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 (14688 => 14689)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/sharing.py        2015-04-20 18:00:40 UTC (rev 14688)
+++ CalendarServer/trunk/twistedcaldav/sharing.py        2015-04-20 18:35:33 UTC (rev 14689)
</span><span class="lines">@@ -205,7 +205,10 @@
</span><span class="cx">             ))
</span><span class="cx"> 
</span><span class="cx">         # Accept it
</span><del>-        shareeView = yield self._newStoreObject.directShareWithUser(sharee.principalUID())
</del><ins>+        shareeView = yield self._newStoreObject.directShareWithUser(
+            sharee.principalUID(),
+            displayName=self.displayName()
+        )
</ins><span class="cx"> 
</span><span class="cx">         # Return the URL of the shared calendar
</span><span class="cx">         sharedAsURL = joinURL(shareeHomeResource.url(), shareeView.name())
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (14688 => 14689)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2015-04-20 18:00:40 UTC (rev 14688)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2015-04-20 18:35:33 UTC (rev 14689)
</span><span class="lines">@@ -1577,14 +1577,24 @@
</span><span class="cx">             ownerView = yield self.ownerView()
</span><span class="cx">             try:
</span><span class="cx">                 displayname = ownerView.properties()[PropertyName.fromElement(element.DisplayName)]
</span><del>-                self.properties()[PropertyName.fromElement(element.DisplayName)] = displayname
</del><span class="cx">             except KeyError:
</span><del>-                pass
</del><ins>+                # displayname is not set, so use the owner's fullname
+                record = yield ownerView.ownerHome().directoryRecord()
+                if record is not None:
+                    displayname = element.DisplayName.fromString(record.fullNames[0].encode(&quot;utf-8&quot;))
+
+            if displayname is not None:
+                try:
+                    self.properties()[PropertyName.fromElement(element.DisplayName)] = displayname
+                except KeyError:
+                    pass
+
</ins><span class="cx">             try:
</span><span class="cx">                 color = ownerView.properties()[PropertyName.fromElement(customxml.CalendarColor)]
</span><span class="cx">                 self.properties()[PropertyName.fromElement(customxml.CalendarColor)] = color
</span><span class="cx">             except KeyError:
</span><span class="cx">                 pass
</span><ins>+
</ins><span class="cx">         elif displayname:
</span><span class="cx">             self.properties()[PropertyName.fromElement(element.DisplayName)] = element.DisplayName.fromString(displayname)
</span><span class="cx"> 
</span><span class="lines">@@ -2332,7 +2342,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def directShareWithUser(self, shareeUID, shareName=None):
</del><ins>+    def directShareWithUser(self, shareeUID, shareName=None, displayName=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Create a direct share with the specified user. Note it is currently up to the app layer
</span><span class="cx">         to enforce access control - this is not ideal as we really should have control of that in
</span><span class="lines">@@ -2349,7 +2359,7 @@
</span><span class="cx">             yield self.updateShare(shareeView, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED)
</span><span class="cx">             returnValue(shareeView)
</span><span class="cx">         else:
</span><del>-            returnValue((yield super(Calendar, self).directShareWithUser(shareeUID, shareName)))
</del><ins>+            returnValue((yield super(Calendar, self).directShareWithUser(shareeUID, shareName, displayName)))
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoretesttest_sql_sharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py (14688 => 14689)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py        2015-04-20 18:00:40 UTC (rev 14688)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py        2015-04-20 18:35:33 UTC (rev 14689)
</span><span class="lines">@@ -33,7 +33,7 @@
</span><span class="cx"> from txdav.common.datastore.test.util import CommonCommonTests
</span><span class="cx"> from txdav.common.datastore.test.util import populateCalendarsFrom
</span><span class="cx"> from txdav.xml.base import WebDAVTextElement
</span><del>-from txdav.xml.element import registerElement, registerElementClass
</del><ins>+from txdav.xml.element import registerElement, registerElementClass, DisplayName
</ins><span class="cx"> import os
</span><span class="cx"> 
</span><span class="cx"> class BaseSharingTests(CommonCommonTests, TestCase):
</span><span class="lines">@@ -440,9 +440,10 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def test_direct_sharee(self):
</del><ins>+    def test_direct_sharee_without_displayname(self):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Test invite/uninvite creates/removes shares and notifications.
</span><ins>+        The displayname for the sharee's copy is taken from the sharer's fullname
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><span class="cx">         # Invite
</span><span class="lines">@@ -463,6 +464,7 @@
</span><span class="cx">         sharedName = shareeView.name()
</span><span class="cx">         shared = yield self.calendarUnderTest(home=&quot;user02&quot;, name=sharedName)
</span><span class="cx">         self.assertTrue(shared is not None)
</span><ins>+        self.assertEquals(shared.displayName(), u&quot;User 01&quot;)
</ins><span class="cx"> 
</span><span class="cx">         notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;, create=True)
</span><span class="cx">         notifications = yield notifyHome.listNotificationObjects()
</span><span class="lines">@@ -484,6 +486,54 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><ins>+    def test_direct_sharee_with_displayname(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;)
+        calendar.properties()[PropertyName.fromElement(DisplayName)] = (
+            DisplayName.fromString(&quot;xyzzy&quot;)
+        )
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+        self.assertFalse(calendar.isShared())
+
+        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].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)
+        self.assertEquals(shared.displayName(), &quot;xyzzy&quot;)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID(&quot;user02&quot;, create=True)
+        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
</ins><span class="cx">     def test_sharedNotifierID(self):
</span><span class="cx">         shared_name = yield self._createShare()
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServertrunktxdavcommondatastoresql_sharingpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/common/datastore/sql_sharing.py (14688 => 14689)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/common/datastore/sql_sharing.py        2015-04-20 18:00:40 UTC (rev 14688)
+++ CalendarServer/trunk/txdav/common/datastore/sql_sharing.py        2015-04-20 18:35:33 UTC (rev 14689)
</span><span class="lines">@@ -438,7 +438,7 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     @inlineCallbacks
</span><del>-    def directShareWithUser(self, shareeUID, shareName=None):
</del><ins>+    def directShareWithUser(self, shareeUID, shareName=None, displayName=None):
</ins><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Create a direct share with the specified user. Note it is currently up to the app layer
</span><span class="cx">         to enforce access control - this is not ideal as we really should have control of that in
</span><span class="lines">@@ -454,7 +454,7 @@
</span><span class="cx">         shareeView = yield self.shareeView(shareeUID)
</span><span class="cx">         if shareeView is None:
</span><span class="cx">             shareeView = yield self.createShare(shareeUID=shareeUID, mode=_BIND_MODE_DIRECT, shareName=shareName)
</span><del>-            yield shareeView.newShare()
</del><ins>+            yield shareeView.newShare(displayname=displayName)
</ins><span class="cx"> 
</span><span class="cx">             # Check for external
</span><span class="cx">             if shareeView.viewerHome().external():
</span></span></pre>
</div>
</div>

</body>
</html>