[CalendarServer-changes] [14689] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Apr 20 11:35:34 PDT 2015


Revision: 14689
          http://trac.calendarserver.org//changeset/14689
Author:   sagen at apple.com
Date:     2015-04-20 11:35:33 -0700 (Mon, 20 Apr 2015)
Log Message:
-----------
Direct sharee's copy gets displayname from sharer's fullname if displayname not explicitly set

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/sharing.py
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py
    CalendarServer/trunk/txdav/common/datastore/sql_sharing.py

Modified: CalendarServer/trunk/twistedcaldav/sharing.py
===================================================================
--- 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)
@@ -205,7 +205,10 @@
             ))
 
         # Accept it
-        shareeView = yield self._newStoreObject.directShareWithUser(sharee.principalUID())
+        shareeView = yield self._newStoreObject.directShareWithUser(
+            sharee.principalUID(),
+            displayName=self.displayName()
+        )
 
         # Return the URL of the shared calendar
         sharedAsURL = joinURL(shareeHomeResource.url(), shareeView.name())

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- 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)
@@ -1577,14 +1577,24 @@
             ownerView = yield self.ownerView()
             try:
                 displayname = ownerView.properties()[PropertyName.fromElement(element.DisplayName)]
-                self.properties()[PropertyName.fromElement(element.DisplayName)] = displayname
             except KeyError:
-                pass
+                # 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("utf-8"))
+
+            if displayname is not None:
+                try:
+                    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)
 
@@ -2332,7 +2342,7 @@
 
 
     @inlineCallbacks
-    def directShareWithUser(self, shareeUID, shareName=None):
+    def directShareWithUser(self, shareeUID, shareName=None, displayName=None):
         """
         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
@@ -2349,7 +2359,7 @@
             yield self.updateShare(shareeView, mode=_BIND_MODE_DIRECT, status=_BIND_STATUS_ACCEPTED)
             returnValue(shareeView)
         else:
-            returnValue((yield super(Calendar, self).directShareWithUser(shareeUID, shareName)))
+            returnValue((yield super(Calendar, self).directShareWithUser(shareeUID, shareName, displayName)))
 
 
     @inlineCallbacks

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql_sharing.py
===================================================================
--- 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)
@@ -33,7 +33,7 @@
 from txdav.common.datastore.test.util import CommonCommonTests
 from txdav.common.datastore.test.util import populateCalendarsFrom
 from txdav.xml.base import WebDAVTextElement
-from txdav.xml.element import registerElement, registerElementClass
+from txdav.xml.element import registerElement, registerElementClass, DisplayName
 import os
 
 class BaseSharingTests(CommonCommonTests, TestCase):
@@ -440,9 +440,10 @@
 
 
     @inlineCallbacks
-    def test_direct_sharee(self):
+    def test_direct_sharee_without_displayname(self):
         """
         Test invite/uninvite creates/removes shares and notifications.
+        The displayname for the sharee's copy is taken from the sharer's fullname
         """
 
         # Invite
@@ -463,6 +464,7 @@
         sharedName = shareeView.name()
         shared = yield self.calendarUnderTest(home="user02", name=sharedName)
         self.assertTrue(shared is not None)
+        self.assertEquals(shared.displayName(), u"User 01")
 
         notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02", create=True)
         notifications = yield notifyHome.listNotificationObjects()
@@ -484,6 +486,54 @@
 
 
     @inlineCallbacks
+    def test_direct_sharee_with_displayname(self):
+        """
+        Test invite/uninvite creates/removes shares and notifications.
+        """
+
+        # Invite
+        calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+        calendar.properties()[PropertyName.fromElement(DisplayName)] = (
+            DisplayName.fromString("xyzzy")
+        )
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+        self.assertFalse(calendar.isShared())
+
+        shareeView = yield calendar.directShareWithUser("user02")
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 1)
+        self.assertEqual(invites[0].uid, shareeView.shareUID())
+        self.assertEqual(invites[0].ownerUID, "user01")
+        self.assertEqual(invites[0].shareeUID, "user02")
+        self.assertEqual(invites[0].mode, _BIND_MODE_DIRECT)
+        self.assertEqual(invites[0].status, _BIND_STATUS_ACCEPTED)
+
+        sharedName = shareeView.name()
+        shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+        self.assertTrue(shared is not None)
+        self.assertEquals(shared.displayName(), "xyzzy")
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02", create=True)
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 0)
+
+        yield self.commit()
+
+        # Remove
+        shared = yield self.calendarUnderTest(home="user02", name=sharedName)
+        yield shared.deleteShare()
+
+        calendar = yield self.calendarUnderTest(home="user01", name="calendar")
+        invites = yield calendar.sharingInvites()
+        self.assertEqual(len(invites), 0)
+
+        notifyHome = yield self.transactionUnderTest().notificationsWithUID("user02")
+        notifications = yield notifyHome.listNotificationObjects()
+        self.assertEqual(len(notifications), 0)
+
+
+    @inlineCallbacks
     def test_sharedNotifierID(self):
         shared_name = yield self._createShare()
 

Modified: CalendarServer/trunk/txdav/common/datastore/sql_sharing.py
===================================================================
--- 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)
@@ -438,7 +438,7 @@
 
 
     @inlineCallbacks
-    def directShareWithUser(self, shareeUID, shareName=None):
+    def directShareWithUser(self, shareeUID, shareName=None, displayName=None):
         """
         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
@@ -454,7 +454,7 @@
         shareeView = yield self.shareeView(shareeUID)
         if shareeView is None:
             shareeView = yield self.createShare(shareeUID=shareeUID, mode=_BIND_MODE_DIRECT, shareName=shareName)
-            yield shareeView.newShare()
+            yield shareeView.newShare(displayname=displayName)
 
             # Check for external
             if shareeView.viewerHome().external():
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20150420/540d73b8/attachment.html>


More information about the calendarserver-changes mailing list