[CalendarServer-changes] [7056] CalendarServer/trunk/twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Sat Feb 19 19:38:36 PST 2011


Revision: 7056
          http://trac.macosforge.org/projects/calendarserver/changeset/7056
Author:   cdaboo at apple.com
Date:     2011-02-19 19:38:32 -0800 (Sat, 19 Feb 2011)
Log Message:
-----------
Hide caldav or carddav properties when the principal is not enabled for a particular service.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml
    CalendarServer/trunk/twistedcaldav/directory/test/augments.xml
    CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
    CalendarServer/trunk/twistedcaldav/resource.py

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2011-02-19 23:46:45 UTC (rev 7055)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2011-02-20 03:38:32 UTC (rev 7056)
@@ -315,12 +315,12 @@
         # First see if the address is a principal URI
         principal = self._principalForURI(address)
         if principal:
-            if isinstance(principal, DirectoryCalendarPrincipalResource):
+            if isinstance(principal, DirectoryCalendarPrincipalResource) and principal.record.enabledForCalendaring:
                 return principal
         else:
             # Next try looking it up in the directory
             record = self.directory.recordWithCalendarUserAddress(address)
-            if record is not None and record.enabled:
+            if record is not None and record.enabled and record.enabledForCalendaring:
                 return self.principalForRecord(record)
 
         log.debug("No principal for calendar user address: %r" % (address,))
@@ -819,6 +819,12 @@
     def liveProperties(self):
         return DirectoryPrincipalResource.liveProperties(self) + CalendarPrincipalResource.liveProperties(self)
 
+    def calendarsEnabled(self):
+        return config.EnableCalDAV and self.record.enabledForCalendaring
+    
+    def addressBooksEnabled(self):
+        return config.EnableCardDAV and self.record.enabledForAddressBooks
+    
     @inlineCallbacks
     def readProperty(self, property, request):
         # Ouch, multiple inheritance.
@@ -828,11 +834,17 @@
         returnValue(result)
 
     def extraDirectoryBodyItems(self, request):
-        return "".join((
-            """\nCalendar homes:\n"""          , format_list(format_link(u) for u in self.calendarHomeURLs()),
-            """\nCalendar user addresses:\n""" , format_list(format_link(a) for a in self.calendarUserAddresses()),
-            """\nAddress Book homes:\n"""       , format_list(format_link(u) for u in self.addressBookHomeURLs()),
-        ))
+        extra = ""
+        if self.record.enabledForCalendaring:
+            extra += "".join((
+                """\nCalendar homes:\n"""          , format_list(format_link(u) for u in self.calendarHomeURLs()),
+                """\nCalendar user addresses:\n""" , format_list(format_link(a) for a in self.calendarUserAddresses()),
+            ))
+        if self.record.enabledForAddressBooks:
+            extra += "".join((
+                """\nAddress Book homes:\n"""       , format_list(format_link(u) for u in self.addressBookHomeURLs()),
+            ))
+        return extra
 
     ##
     # CalDAV

Modified: CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml	2011-02-19 23:46:45 UTC (rev 7055)
+++ CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml	2011-02-20 03:38:32 UTC (rev 7056)
@@ -81,6 +81,20 @@
     <name>c</name>
     <email-address>c at example.com</email-address>
   </user>
+  <user>
+    <uid>usercalonly</uid>
+    <guid>9E1FFAC4-3CCD-45A1-8272-D161C92D2EEE</guid>
+    <password>a</password>
+    <name>a calonly</name>
+    <email-address>a-calonly at example.com</email-address>
+  </user>
+  <user>
+    <uid>useradbkonly</uid>
+    <guid>7678EC8A-A069-4E82-9066-7279C6718507</guid>
+    <password>a</password>
+    <name>a adbkonly</name>
+    <email-address>a-adbkonly at example.com</email-address>
+  </user>
   <user repeat="2">
     <uid>user%02d</uid>
     <guid>user%02d</guid>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/augments.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/augments.xml	2011-02-19 23:46:45 UTC (rev 7055)
+++ CalendarServer/trunk/twistedcaldav/directory/test/augments.xml	2011-02-20 03:38:32 UTC (rev 7056)
@@ -158,4 +158,14 @@
     <enable>true</enable>
     <enable-calendar>true</enable-calendar>
   </record>
+  <record>
+    <uid>9E1FFAC4-3CCD-45A1-8272-D161C92D2EEE</uid>
+    <enable>true</enable>
+    <enable-calendar>true</enable-calendar>
+  </record>
+  <record>
+    <uid>7678EC8A-A069-4E82-9066-7279C6718507</uid>
+    <enable>true</enable>
+    <enable-addressbook>true</enable-addressbook>
+  </record>
 </augments>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2011-02-19 23:46:45 UTC (rev 7055)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2011-02-20 03:38:32 UTC (rev 7056)
@@ -21,10 +21,13 @@
 from twext.web2.dav import davxml
 from twext.web2.dav.fileop import rmdir
 from twext.web2.dav.resource import AccessDeniedError
+from twext.web2.http import HTTPError
 from twext.web2.test.test_server import SimpleRequest
 
 from twistedcaldav.cache import DisabledCacheNotifier
+from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
+from twistedcaldav.customxml import calendarserver_namespace
 from twistedcaldav.directory import augment, calendaruserproxy
 from twistedcaldav.directory.addressbook import DirectoryAddressBookHomeProvisioningResource
 from twistedcaldav.directory.calendar import DirectoryCalendarHomeProvisioningResource
@@ -35,8 +38,9 @@
 from twistedcaldav.directory.principal import DirectoryPrincipalTypeProvisioningResource
 from twistedcaldav.directory.principal import DirectoryPrincipalResource
 from twistedcaldav.directory.principal import DirectoryCalendarPrincipalResource
+from twistedcaldav import carddavxml
+import twistedcaldav.test.util
 
-import twistedcaldav.test.util
 from txdav.common.datastore.file import CommonDataStore
 
 
@@ -236,7 +240,7 @@
             None
         )
 
-
+    @inlineCallbacks
     def test_enabledForCalendaring(self):
         """
         DirectoryPrincipalProvisioningResource.principalForCalendarUserAddress()
@@ -248,8 +252,52 @@
                 self.assertTrue(isinstance(principal, DirectoryCalendarPrincipalResource))
             else:
                 self.assertTrue(isinstance(principal, DirectoryPrincipalResource))
-                self.assertFalse(isinstance(principal, DirectoryCalendarPrincipalResource))
+                if record.enabledForAddressBooks:
+                    self.assertTrue(isinstance(principal, DirectoryCalendarPrincipalResource))
+                else:
+                    self.assertFalse(isinstance(principal, DirectoryCalendarPrincipalResource))
 
+            @inlineCallbacks
+            def hasProperty(property):
+                self.assertTrue(property in principal.liveProperties())
+                yield principal.readProperty(property, None)
+                
+            @inlineCallbacks
+            def doesNotHaveProperty(property):
+                self.assertTrue(property not in principal.liveProperties())
+                try:
+                    yield principal.readProperty(property, None)
+                except HTTPError:
+                    pass
+                except:
+                    self.fail("Wrong exception type")
+                else:
+                    self.fail("No exception principal: %s, property %s" % (principal, property,))
+                
+            if record.enabledForCalendaring:
+                yield hasProperty((caldav_namespace, "calendar-home-set"))
+                yield hasProperty((caldav_namespace, "calendar-user-address-set"))
+                yield hasProperty((caldav_namespace, "schedule-inbox-URL"))
+                yield hasProperty((caldav_namespace, "schedule-outbox-URL"))
+                yield hasProperty((caldav_namespace, "calendar-user-type"))
+                yield hasProperty((calendarserver_namespace, "calendar-proxy-read-for"))
+                yield hasProperty((calendarserver_namespace, "calendar-proxy-write-for"))
+                yield hasProperty((calendarserver_namespace, "auto-schedule"))
+            else:
+                yield doesNotHaveProperty((caldav_namespace, "calendar-home-set"))
+                yield doesNotHaveProperty((caldav_namespace, "calendar-user-address-set"))
+                yield doesNotHaveProperty((caldav_namespace, "schedule-inbox-URL"))
+                yield doesNotHaveProperty((caldav_namespace, "schedule-outbox-URL"))
+                yield doesNotHaveProperty((caldav_namespace, "calendar-user-type"))
+                yield doesNotHaveProperty((calendarserver_namespace, "calendar-proxy-read-for"))
+                yield doesNotHaveProperty((calendarserver_namespace, "calendar-proxy-write-for"))
+                yield doesNotHaveProperty((calendarserver_namespace, "auto-schedule"))
+
+            if record.enabledForAddressBooks:
+                yield hasProperty(carddavxml.AddressBookHomeSet.qname())
+            else:
+                yield doesNotHaveProperty(carddavxml.AddressBookHomeSet.qname())
+
     def test_enabledAsOrganizer(self):
         """
         DirectoryPrincipalProvisioningResource.principalForCalendarUserAddress()

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2011-02-19 23:46:45 UTC (rev 7055)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2011-02-20 03:38:32 UTC (rev 7056)
@@ -1774,7 +1774,7 @@
         
         baseProperties = ()
         
-        if config.EnableCalDAV:
+        if self.calendarsEnabled():
             baseProperties += (
                 (caldav_namespace, "calendar-home-set"        ),
                 (caldav_namespace, "calendar-user-address-set"),
@@ -1786,7 +1786,7 @@
                 (calendarserver_namespace, "auto-schedule" ),
             )
         
-        if config.EnableCardDAV:
+        if self.addressBooksEnabled():
             baseProperties += (carddavxml.AddressBookHomeSet.qname(),)
             if config.DirectoryAddressBook.Enabled:
                 baseProperties += (carddavxml.DirectoryGateway.qname(),)
@@ -1802,6 +1802,12 @@
     def isCollection(self):
         return True
 
+    def calendarsEnabled(self):
+        return config.EnableCalDAV
+    
+    def addressBooksEnabled(self):
+        return config.EnableCardDAV
+    
     @inlineCallbacks
     def readProperty(self, property, request):
         if type(property) is tuple:
@@ -1811,7 +1817,7 @@
 
         namespace, name = qname
 
-        if namespace == caldav_namespace:
+        if namespace == caldav_namespace and self.calendarsEnabled():
             if name == "calendar-home-set":
                 returnValue(caldavxml.CalendarHomeSet(
                     *[davxml.HRef(url) for url in self.calendarHomeURLs()]
@@ -1854,23 +1860,23 @@
                 else:
                     returnValue(customxml.NotificationURL(davxml.HRef(url)))
 
-            elif name == "calendar-proxy-read-for":
+            elif name == "calendar-proxy-read-for" and self.calendarsEnabled():
                 results = (yield self.proxyFor(False))
                 returnValue(customxml.CalendarProxyReadFor(
                     *[davxml.HRef(principal.principalURL()) for principal in results]
                 ))
 
-            elif name == "calendar-proxy-write-for":
+            elif name == "calendar-proxy-write-for" and self.calendarsEnabled():
                 results = (yield self.proxyFor(True))
                 returnValue(customxml.CalendarProxyWriteFor(
                     *[davxml.HRef(principal.principalURL()) for principal in results]
                 ))
 
-            elif name == "auto-schedule":
+            elif name == "auto-schedule" and self.calendarsEnabled():
                 autoSchedule = self.getAutoSchedule()
                 returnValue(customxml.AutoSchedule("true" if autoSchedule else "false"))
 
-        elif config.EnableCardDAV and namespace == carddav_namespace:
+        elif namespace == carddav_namespace and self.addressBooksEnabled():
             if name == "addressbook-home-set":
                 returnValue(carddavxml.AddressBookHomeSet(
                     *[davxml.HRef(url) for url in self.addressBookHomeURLs()]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20110219/faa52da5/attachment-0001.html>


More information about the calendarserver-changes mailing list