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

source_changes at macosforge.org source_changes at macosforge.org
Tue Dec 5 01:07:10 PST 2006


Revision: 677
          http://trac.macosforge.org/projects/calendarserver/changeset/677
Author:   wsanchez at apple.com
Date:     2006-12-05 01:07:09 -0800 (Tue, 05 Dec 2006)

Log Message:
-----------
Get rid of findAnyCalendarUser, findCalendarUser, outboxForCalendarUser, inboxForCalendarUser.

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/itip.py
    CalendarServer/trunk/twistedcaldav/method/schedule_common.py
    CalendarServer/trunk/twistedcaldav/resource.py

Modified: CalendarServer/trunk/twistedcaldav/itip.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/itip.py	2006-12-05 08:39:29 UTC (rev 676)
+++ CalendarServer/trunk/twistedcaldav/itip.py	2006-12-05 09:07:09 UTC (rev 677)
@@ -553,9 +553,7 @@
     # Get the Inbox of the ORGANIZER
     organizer = replycal.getOrganizer()
     assert organizer is not None
-    inboxURL = waitForDeferred(CalendarPrincipalCollectionResource.inboxForCalendarUser(request, organizer))
-    yield inboxURL
-    inboxURL = inboxURL.getResult()
+    inboxURL = principal.principalForCalendarUserAddress(organizer).scheduleInboxURL()
     assert inboxURL
     
     # Determine whether current principal has CALDAV:schedule right on that Inbox

Modified: CalendarServer/trunk/twistedcaldav/method/schedule_common.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/method/schedule_common.py	2006-12-05 08:39:29 UTC (rev 676)
+++ CalendarServer/trunk/twistedcaldav/method/schedule_common.py	2006-12-05 09:07:09 UTC (rev 677)
@@ -30,7 +30,6 @@
 from twisted.web2.dav.http import ErrorResponse
 from twisted.web2.dav.util import joinURL
 from twisted.web2.http import HTTPError
-from twistedcaldav.resource import findAnyCalendarUser
 
 from twistedcaldav import caldavxml
 from twistedcaldav import customxml
@@ -74,9 +73,10 @@
         originator = originator[0]
     
     # Verify that Originator is a valid calendar user (has an INBOX)
-    inboxURL = waitForDeferred(CalendarPrincipalCollectionResource.inboxForCalendarUser(request, originator))
-    yield inboxURL
-    inboxURL = inboxURL.getResult()
+    inboxURL = None
+    oprincipal = self.principalForCalendarUserAddress(originator)
+    if oprincipal is not None:
+        inboxURL = oprincipal.scheduleInboxURL()
     if inboxURL is None:
         log.err("Could not find Inbox for originator: %s" % (originator,))
         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "originator-allowed")))
@@ -125,12 +125,13 @@
         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "valid-calendar-data")))
     
     # Verify that the ORGANIZER's cu address maps to the request.uri
+    outboxURL = None
     organizer = calendar.getOrganizer()
-    if organizer:
-        outboxURL = waitForDeferred(CalendarPrincipalCollectionResource.outboxForCalendarUser(request, organizer))
-        yield outboxURL
-        outboxURL = outboxURL.getResult()
-    if (organizer is None) or (outboxURL is None):
+    if organizer is not None:
+        oprincipal = self.principalForCalendarUserAddress(organizer)
+        if oprincipal is not None:
+            outboxURL = oprincipal.scheduleOutboxURL()
+    if outboxURL is None:
         log.err("ORGANIZER in calendar data is not valid: %s" % (calendar,))
         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "organizer-allowed")))
 
@@ -138,9 +139,6 @@
     if (calendar.propertyValue("METHOD") in ("PUBLISH", "REQUEST", "ADD", "CANCEL", "DECLINECOUNTER")) and (outboxURL != request.uri):
         log.err("ORGANIZER in calendar data does not match owner of Outbox: %s" % (calendar,))
         raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "organizer-allowed")))
-    oprincipal = waitForDeferred(findAnyCalendarUser(request, organizer))
-    yield oprincipal
-    oprincipal = oprincipal.getResult()
 
     # Prevent spoofing when doing reply-like METHODs
     if calendar.propertyValue("METHOD") in ("REPLY", "COUNTER", "REFRESH"):
@@ -154,10 +152,11 @@
             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed")))
             
         # Attendee's Outbox MUST be the request URI
-        aoutboxURL = waitForDeferred(CalendarPrincipalCollectionResource.outboxForCalendarUser(request, attendees[0]))
-        yield aoutboxURL
-        aoutboxURL = aoutboxURL.getResult()
-        if (aoutboxURL is None) or (aoutboxURL != request.uri):
+        aoutboxURL = None
+        aprincipal = self.principalForCalendarUserAddress(attendees[0])
+        if aprincipal is not None:
+            aoutboxURL = aprincipal.scheduleOutboxURL()
+        if aoutboxURL is None or aoutboxURL != request.uri:
             log.err("ATTENDEE in calendar data does not match owner of Outbox: %s" % (calendar,))
             raise HTTPError(ErrorResponse(responsecode.FORBIDDEN, (caldav_namespace, "attendee-allowed")))
 
@@ -197,22 +196,21 @@
         child = child.getResult()
         responses.setLocation(childURL)
         
-        d = waitForDeferred(
-                maybeDeferred(
-                    storeCalendarObjectResource,
-                    request=request,
-                    sourcecal = False,
-                    destination = child,
-                    destination_uri = childURL,
-                    calendardata = str(calendar),
-                    destinationparent = self,
-                    destinationcal = True,
-                    isiTIP = True
-                )
-            )
-        yield d
-
         try:
+            d = waitForDeferred(
+                    maybeDeferred(
+                        storeCalendarObjectResource,
+                        request=request,
+                        sourcecal = False,
+                        destination = child,
+                        destination_uri = childURL,
+                        calendardata = str(calendar),
+                        destinationparent = self,
+                        destinationcal = True,
+                        isiTIP = True
+                    )
+                )
+            yield d
             d.getResult()
         except:
             log.err("Error while handling %s: %s" % (method, failure.Failure(),))
@@ -232,18 +230,17 @@
     autoresponses = []
     for recipient in recipients:
         # Get the principal resource for this recipient
-        principal = waitForDeferred(findAnyCalendarUser(request, recipient))
-        yield principal
-        principal = principal.getResult()
+        principal = self.principalForCalendarUserAddress(recipient)
 
         # Map recipient to their inbox
+        inbox = None
         if principal is not None:
             inboxURL = principal.scheduleInboxURL()
             if inboxURL:
                 inbox = waitForDeferred(request.locateResource(inboxURL))
                 yield inbox
                 inbox = inbox.getResult()
-        if principal is None or inboxURL is None or inbox is None:
+        if inbox is None:
             log.err("Could not find Inbox for recipient: %s" % (recipient,))
             err = HTTPError(ErrorResponse(responsecode.NOT_FOUND, (caldav_namespace, "recipient-exists")))
             responses.add(recipient, failure.Failure(exc_value=err), reqstatus="3.7;Invalid Calendar User")

Modified: CalendarServer/trunk/twistedcaldav/resource.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/resource.py	2006-12-05 08:39:29 UTC (rev 676)
+++ CalendarServer/trunk/twistedcaldav/resource.py	2006-12-05 09:07:09 UTC (rev 677)
@@ -443,6 +443,13 @@
         """
         return caldavxml.CalendarData.fromCalendar(self.iCalendar(name))
 
+    def principalForCalendarUserAddress(self, address):
+        for principalCollection in self.principalCollections():
+            principal = principalCollection.principalForCalendarUserAddress(address)
+            if principal is not None:
+                return principal
+        return None
+
     def supportedReports(self):
         result = super(CalDAVResource, self).supportedReports()
         result.append(davxml.Report(caldavxml.CalendarQuery(),))
@@ -494,46 +501,6 @@
     """
     implements(IDAVPrincipalCollectionResource)
 
-    @classmethod
-    def outboxForCalendarUser(clazz, request, address):
-        """
-        Find the URL of the calendar outbox for the specified calendar user
-        address.
-        @param request: an L{IRequest} object for the request being processed.
-        @param address: the calendar user address to look up.
-        @return: the URI of the calendar outbox, or C{None} if no outbox for
-            exists for the user.
-        """
-        def _defer(principal):
-            if principal:
-                return principal.scheduleOutboxURL()
-            else:
-                return None
-
-        d = findAnyCalendarUser(request, address)
-        d.addCallback(_defer)
-        return d
-
-    @classmethod
-    def inboxForCalendarUser(clazz, request, address):
-        """
-        Find the URL of the calendar inbox for the specified calendar user
-        address.
-        @param request: an L{IRequest} object for the request being processed.
-        @param address: the calendar user address to look up.
-        @return: the URI of the calendar inbox, or C{None} if no inbox exists
-            for the user
-        """
-        def _defer(principal):
-            if principal:
-                return principal.scheduleInboxURL()
-            else:
-                return None
-
-        d = findAnyCalendarUser(request, address)
-        d.addCallback(_defer)
-        return d
-
     def isCollection(self):
         return True
 
@@ -543,31 +510,6 @@
     def isPseudoCalendarCollection(self):
         return False
 
-    def findCalendarUser(self, request, address):
-        """
-        Find the calendar user principal associated with the specified calendar
-        user address.
-        @param request: an L{IRequest} object for the request being processed.
-        @param address: the calendar user address to lookup.
-        @return: the L{CalendarPrincipalResource} for the specified calendar
-            user, or C{None} if the user is not found.
-        """
-        
-        # Look at cuaddress property on each child and do attempt a match
-        for childname in self.listChildren():
-            child = waitForDeferred(request.locateChildResource(self, childname))
-            yield child
-            child = child.getResult()
-            if not isinstance(child, CalendarPrincipalResource):
-                continue
-            if address in child.calendarUserAddresses():
-                yield child
-                return
-        
-        yield None
-
-    findCalendarUser = deferredGenerator(findCalendarUser)
-
     def principalForCalendarUserAddress(self, address):
         return None
 
@@ -602,30 +544,6 @@
             ),
         )
 
-# FIXME: Replace this
-def findAnyCalendarUser(request, address):
-    """
-    Find the calendar user principal associated with the specified calendar
-    user address in any of the currently defined principal collections.
-    @param request: an L{IRequest} object for the request being processed.
-    @param address: the calendar user address to look up.
-    @return: the L{CalendarPrincipalResource} for the specified calendar
-        user, or C{None} if the user is not found.
-    """
-    for collection in self.principalCollections():
-        if isinstance(collection, CalendarPrincipalCollectionResource):
-            principal = waitForDeferred(collection.findCalendarUser(request, address))
-            yield principal
-            principal = principal.getResult()
-
-            if principal is not None:
-                yield principal
-                return
-    else:
-        yield None
-
-findAnyCalendarUser = deferredGenerator(findAnyCalendarUser)
-
 class CalendarPrincipalResource (DAVPrincipalResource):
     """
     CalDAV principal resource.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20061205/d8027e03/attachment.html


More information about the calendarserver-changes mailing list