[CalendarServer-changes] [4686] CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/ twistedcaldav

source_changes at macosforge.org source_changes at macosforge.org
Mon Nov 2 06:33:33 PST 2009


Revision: 4686
          http://trac.macosforge.org/projects/calendarserver/changeset/4686
Author:   cdaboo at apple.com
Date:     2009-11-02 06:33:30 -0800 (Mon, 02 Nov 2009)
Log Message:
-----------
Remove filtering stuff from CalendarData class and make use of new filtering apis instead.

Modified Paths:
--------------
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/caldavxml.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/calendardata.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/privateevents.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_calendardata.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_privateevents.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/get.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/report_common.py
    CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/static.py

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/caldavxml.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/caldavxml.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/caldavxml.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -31,7 +31,7 @@
 
 from twisted.web2.dav import davxml
 
-from twistedcaldav.dateops import clipPeriod, timeRangesOverlap
+from twistedcaldav.dateops import timeRangesOverlap
 from twistedcaldav.ical import Component as iComponent
 from twistedcaldav.ical import Property as iProperty
 from twistedcaldav.ical import parse_date_or_datetime
@@ -397,6 +397,8 @@
     @classmethod
     def fromCalendar(clazz, calendar):
         if isinstance(calendar, str):
+            if not calendar:
+                raise ValueError("Missing calendar data")
             return clazz(davxml.PCDATAElement(calendar))
         elif isinstance(calendar, iComponent):
             assert calendar.name() == "VCALENDAR", "Not a calendar: %r" % (calendar,)
@@ -487,205 +489,6 @@
         
         return False
 
-    def elementFromResource(self, resource, timezone=None):
-        """
-        Return a new CalendarData element comprised of the possibly filtered
-        calendar data from the specified resource. If no filter is being applied
-        read the data directly from the resource without parsing it. If a filter
-        is required, parse the iCal data and filter using this CalendarData.
-        @param resource: the resource whose calendar data is to be returned.
-        @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
-        @return: an L{CalendarData} with the (filtered) calendar data.
-        """
-        return self.elementFromCalendar(resource.iCalendarText(), timezone)
-
-    def elementFromCalendar(self, calendar, timezone=None):
-        """
-        Return a new CalendarData element comprised of the possibly filtered
-        calendar.
-        @param calendar: the calendar that is to be filtered and returned.
-        @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
-        @return: an L{CalendarData} with the (filtered) calendar data.
-        """
-        
-        # Check for filtering or not
-        filtered = self.getFromICalendar(calendar, timezone)
-        return CalendarData.fromCalendar(filtered)
-
-    def elementFromResourceWithAccessRestrictions(self, resource, access, timezone=None):
-        """
-        Return a new CalendarData element comprised of the possibly filtered
-        calendar data from the specified resource. If no filter is being applied
-        read the data directly from the resource without parsing it. If a filter
-        is required, parse the iCal data and filter using this CalendarData.
-        
-        Also, apply appropriate access restriction filtering to the data.
-
-        @param resource: the resource whose calendar data is to be returned.
-        @param access: private event access restriction level.
-        @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
-        @return: an L{CalendarData} with the (filtered) calendar data.
-        """
-        return self.elementFromCalendarWithAccessRestrictions(resource.iCalendarText(), access, timezone)
-
-    def elementFromCalendarWithAccessRestrictions(self, calendar, access, timezone=None):
-        """
-        Return a new CalendarData element comprised of the possibly filtered
-        calendar.
-        
-        Also, apply appropriate access restriction filtering to the data.
-
-        @param calendar: the calendar that is to be filtered and returned.
-        @param access: private event access restriction level.
-        @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
-        @return: an L{CalendarData} with the (filtered) calendar data.
-        """
-        
-        # Do normal filtering first
-        filtered_calendar = self.getFromICalendar(calendar, timezone)
-        
-        if access in (iComponent.ACCESS_CONFIDENTIAL, iComponent.ACCESS_RESTRICTED):
-            # Create a CALDAV:calendar-data element with the appropriate iCalendar Component/Property
-            # filter in place for the access restriction in use
-            
-            extra_access = ()
-            if access == iComponent.ACCESS_RESTRICTED:
-                extra_access = (
-                    Property(name="SUMMARY"),
-                    Property(name="LOCATION"),
-                )
-
-            filter = CalendarData(
-                CalendarComponent(
-                    
-                    # VCALENDAR properties
-                    Property(name="PRODID"),
-                    Property(name="VERSION"),
-                    Property(name="CALSCALE"),
-                    Property(name=iComponent.ACCESS_PROPERTY),
-
-                    # VEVENT
-                    CalendarComponent(
-                        Property(name="UID"),
-                        Property(name="RECURRENCE-ID"),
-                        Property(name="SEQUENCE"),
-                        Property(name="DTSTAMP"),
-                        Property(name="STATUS"),
-                        Property(name="TRANSP"),
-                        Property(name="DTSTART"),
-                        Property(name="DTEND"),
-                        Property(name="DURATION"),
-                        Property(name="RRULE"),
-                        Property(name="RDATE"),
-                        Property(name="EXRULE"),
-                        Property(name="EXDATE"),
-                        *extra_access,
-                        **{"name":"VEVENT"}
-                    ),
-                    
-                    # VTODO
-                    CalendarComponent(
-                        Property(name="UID"),
-                        Property(name="RECURRENCE-ID"),
-                        Property(name="SEQUENCE"),
-                        Property(name="DTSTAMP"),
-                        Property(name="STATUS"),
-                        Property(name="DTSTART"),
-                        Property(name="COMPLETED"),
-                        Property(name="DUE"),
-                        Property(name="DURATION"),
-                        Property(name="RRULE"),
-                        Property(name="RDATE"),
-                        Property(name="EXRULE"),
-                        Property(name="EXDATE"),
-                        *extra_access,
-                        **{"name":"VTODO"}
-                    ),
-                    
-                    # VJOURNAL
-                    CalendarComponent(
-                        Property(name="UID"),
-                        Property(name="RECURRENCE-ID"),
-                        Property(name="SEQUENCE"),
-                        Property(name="DTSTAMP"),
-                        Property(name="STATUS"),
-                        Property(name="TRANSP"),
-                        Property(name="DTSTART"),
-                        Property(name="RRULE"),
-                        Property(name="RDATE"),
-                        Property(name="EXRULE"),
-                        Property(name="EXDATE"),
-                        *extra_access,
-                        **{"name":"VJOURNAL"}
-                    ),
-                    
-                    # VFREEBUSY
-                    CalendarComponent(
-                        Property(name="UID"),
-                        Property(name="DTSTAMP"),
-                        Property(name="DTSTART"),
-                        Property(name="DTEND"),
-                        Property(name="DURATION"),
-                        Property(name="FREEBUSY"),
-                        *extra_access,
-                        **{"name":"VFREEBUSY"}
-                    ),
-                    
-                    # VTIMEZONE
-                    CalendarComponent(
-                        AllProperties(),
-                        AllComponents(),
-                        name="VTIMEZONE",
-                    ),
-                    name="VCALENDAR",
-                ),
-            )
-
-            # Now "filter" the resource calendar data through the CALDAV:calendar-data element
-            return filter.elementFromCalendar(filtered_calendar, timezone)
-        else:
-            return CalendarData.fromCalendar(filtered_calendar)
-
-    def getFromICalendar(self, calendar, timezone=None):
-        """
-        @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
-
-        Returns a calendar object containing the data in the given calendar
-        which is specified by this CalendarData.
-        """
-        if calendar is None or isinstance(calendar, str) and not calendar:
-            raise ValueError("Not a calendar: %r" % (calendar,))
-
-        # Empty element: get all data
-        if not self.children: return calendar
-
-        # If we were passed a string, parse it out as a Component
-        if isinstance(calendar, str):
-            try:
-                calendar = iComponent.fromString(calendar)
-            except ValueError:
-                raise ValueError("Not a calendar: %r" % (calendar,))
-
-        if calendar is None or calendar.name() != "VCALENDAR":
-            raise ValueError("Not a calendar: %r" % (calendar,))
-
-        # Pre-process the calendar data based on expand and limit options
-        if self.freebusy_set:
-            calendar = self.limitFreeBusy(calendar)
-
-        # Filter data based on any provided CALDAV:comp element, or use all current data
-        if self.component is not None:
-            calendar = self.component.getFromICalendar(calendar)
-        
-        # Post-process the calendar data based on the expand and limit options
-        if self.recurrence_set:
-            if isinstance(self.recurrence_set, LimitRecurrenceSet):
-                calendar = self.limitRecurrence(calendar)
-            elif isinstance(self.recurrence_set, Expand):
-                calendar = self.expandRecurrence(calendar, timezone)
-        
-        return calendar
-
     def calendar(self):
         """
         Returns a calendar component derived from this element.
@@ -709,55 +512,6 @@
 
         return str(data)
 
-    def expandRecurrence(self, calendar, timezone=None):
-        """
-        Expand the recurrence set into individual items.
-        @param calendar: the L{Component} for the calendar to operate on.
-        @param timezone: the L{Component} the VTIMEZONE to use for floating/all-day.
-        @return: the L{Component} for the result.
-        """
-        return calendar.expand(self.recurrence_set.start, self.recurrence_set.end, timezone)
-    
-    def limitRecurrence(self, calendar):
-        """
-        Limit the set of overridden instances returned to only those
-        that are needed to describe the range of instances covered
-        by the specified time range.
-        @param calendar: the L{Component} for the calendar to operate on.
-        @return: the L{Component} for the result.
-        """
-        raise NotImplementedError()
-        return calendar
-    
-    def limitFreeBusy(self, calendar):
-        """
-        Limit the range of any FREEBUSY properties in the calendar, returning
-        a new calendar if limits were applied, or the same one if no limits were applied.
-        @param calendar: the L{Component} for the calendar to operate on.
-        @return: the L{Component} for the result.
-        """
-        
-        # First check for any VFREEBUSYs - can ignore limit if there are none
-        if calendar.mainType() != "VFREEBUSY":
-            return calendar
-        
-        # Create duplicate calendar and filter FREEBUSY properties
-        calendar = calendar.duplicate()
-        for component in calendar.subcomponents():
-            if component.name() != "VFREEBUSY":
-                continue
-            for property in component.properties("FREEBUSY"):
-                newvalue = []
-                for period in property.value():
-                    clipped = clipPeriod(period, (self.freebusy_set.start, self.freebusy_set.end))
-                    if clipped:
-                        newvalue.append(clipped)
-                if len(newvalue):
-                    property.setValue(newvalue)
-                else:
-                    component.removeProperty(property)
-        return calendar
-
 class CalendarComponent (CalDAVElement):
     """
     Defines which component types to return.

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/calendardata.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/calendardata.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/calendardata.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -57,29 +57,29 @@
         # If we were passed a string, parse it out as a Component
         if isinstance(ical, str):
             try:
-                calendar = Component.fromString(ical)
+                ical = Component.fromString(ical)
             except ValueError:
                 raise ValueError("Not a calendar: %r" % (ical,))
 
-        if calendar is None or calendar.name() != "VCALENDAR":
-            raise ValueError("Not a calendar: %r" % (calendar,))
+        if ical is None or ical.name() != "VCALENDAR":
+            raise ValueError("Not a calendar: %r" % (ical,))
 
         # Pre-process the calendar data based on expand and limit options
         if self.calendardata.freebusy_set:
-            calendar = self.limitFreeBusy(calendar)
+            ical = self.limitFreeBusy(ical)
 
         # Filter data based on any provided CALDAV:comp element, or use all current data
         if self.calendardata.component is not None:
-            calendar = self.compFilter(self.calendardata.component, calendar)
+            ical = self.compFilter(self.calendardata.component, ical)
         
         # Post-process the calendar data based on the expand and limit options
         if self.calendardata.recurrence_set:
             if isinstance(self.calendardata.recurrence_set, LimitRecurrenceSet):
-                calendar = self.limitRecurrence(calendar)
+                ical = self.limitRecurrence(ical)
             elif isinstance(self.calendardata.recurrence_set, Expand):
-                calendar = self.expandRecurrence(calendar, self.timezone)
+                ical = self.expandRecurrence(ical, self.timezone)
         
-        return calendar
+        return ical
 
     def compFilter(self, comp, component):
         """

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/privateevents.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/privateevents.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/privateevents.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -19,6 +19,7 @@
 from twistedcaldav.caldavxml import Property, CalendarData, CalendarComponent,\
     AllProperties, AllComponents
 from twistedcaldav.datafilters.calendardata import CalendarDataFilter
+from twistedcaldav.ical import Component
 
 __all__ = [
     "PrivateEventFilter",
@@ -75,22 +76,22 @@
         @return: L{Component} for the filtered calendar data
         """
         
-        if self.isowner or self.accessRestriction == PrivateEventFilter.ACCESS_PUBLIC:
+        if self.isowner or self.accessRestriction == Component.ACCESS_PUBLIC or self.accessRestriction is None:
             # No need to filter for the owner or public event
             return ical
         
-        elif self.accessRestriction == PrivateEventFilter.ACCESS_PRIVATE:
+        elif self.accessRestriction == Component.ACCESS_PRIVATE:
             # We should never get here because ACCESS_PRIVATE is protected via an ACL
             raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Access Denied"))
 
-        elif self.accessRestriction == PrivateEventFilter.ACCESS_PUBLIC:
+        elif self.accessRestriction == Component.ACCESS_PUBLIC:
             return ical
-        elif self.accessRestriction in (PrivateEventFilter.ACCESS_CONFIDENTIAL, PrivateEventFilter.ACCESS_RESTRICTED):
+        elif self.accessRestriction in (Component.ACCESS_CONFIDENTIAL, Component.ACCESS_RESTRICTED):
             # Create a CALDAV:calendar-data element with the appropriate iCalendar Component/Property
             # filter in place for the access restriction in use
             
             extra_access = ()
-            if self.accessRestriction == PrivateEventFilter.ACCESS_RESTRICTED:
+            if self.accessRestriction == Component.ACCESS_RESTRICTED:
                 extra_access = (
                     Property(name="SUMMARY"),
                     Property(name="LOCATION"),
@@ -103,7 +104,7 @@
                     Property(name="PRODID"),
                     Property(name="VERSION"),
                     Property(name="CALSCALE"),
-                    Property(name=PrivateEventFilter.ACCESS_PROPERTY),
+                    Property(name=Component.ACCESS_PROPERTY),
 
                     # VEVENT
                     CalendarComponent(
@@ -186,7 +187,7 @@
             return CalendarDataFilter(calendardata).filter(ical)
         else:
             # Unknown access restriction
-            raise HTTPError(StatusResponse(responsecode.FORBIDDEN))
+            raise HTTPError(StatusResponse(responsecode.FORBIDDEN, "Access Denied"))
     
     def merge(self, icalnew, icalold):
         """

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_calendardata.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_calendardata.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_calendardata.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -18,6 +18,7 @@
 from twistedcaldav.datafilters.calendardata import CalendarDataFilter
 from twistedcaldav.caldavxml import CalendarData, CalendarComponent,\
     AllComponents, AllProperties, Property
+from twistedcaldav.ical import Component
 
 class CalendarDataTest (twistedcaldav.test.util.TestCase):
 
@@ -38,7 +39,8 @@
 """.replace("\n", "\r\n")
         
         empty = CalendarData()
-        self.assertEqual(str(CalendarDataFilter(empty).filter(data)), data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), data)
 
     def test_vcalendar_no_effect(self):
         
@@ -61,7 +63,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(no_effect).filter(data)), data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)
  
         no_effect = CalendarData(
             CalendarComponent(
@@ -70,7 +73,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(no_effect).filter(data)), data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)
 
     def test_vcalendar_no_props(self):
         
@@ -109,7 +113,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(empty).filter(data)), result)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), result)
 
     def test_vcalendar_no_comp(self):
         
@@ -141,7 +146,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(empty).filter(data)), result)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), result)
 
     def test_vevent_no_effect(self):
         
@@ -168,7 +174,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(no_effect).filter(data)), data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(no_effect).filter(item)), data)
 
     def test_vevent_other_component(self):
         
@@ -201,7 +208,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(other_component).filter(data)), result)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(other_component).filter(item)), result)
 
     def test_vevent_no_props(self):
         
@@ -248,11 +256,11 @@
             )
         )
         
-        filtered = str(CalendarDataFilter(empty).filter(data))
-        filtered = "".join([line for line in filtered.splitlines(True) if not line.startswith("UID:")])
+        for item in (data, Component.fromString(data),):
+            filtered = str(CalendarDataFilter(empty).filter(item))
+            filtered = "".join([line for line in filtered.splitlines(True) if not line.startswith("UID:")])
+            self.assertEqual(filtered, result)
 
-        self.assertEqual(str(CalendarDataFilter(empty).filter(data)), result)
-
     def test_vevent_no_comp(self):
         
         data = """BEGIN:VCALENDAR
@@ -298,7 +306,8 @@
                 name="VCALENDAR"
             )
         )
-        self.assertEqual(str(CalendarDataFilter(empty).filter(data)), result)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), result)
 
     def test_vevent_some_props(self):
         
@@ -357,5 +366,6 @@
             )
         )
         
-        self.assertEqual(str(CalendarDataFilter(empty).filter(data)), result)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(CalendarDataFilter(empty).filter(item)), result)
 

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_privateevents.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_privateevents.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/datafilters/test/test_privateevents.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -17,6 +17,7 @@
 from twisted.web2.http import HTTPError
 import twistedcaldav.test.util
 from twistedcaldav.datafilters.privateevents import PrivateEventFilter
+from twistedcaldav.ical import Component
 
 class PrivateEventsTest (twistedcaldav.test.util.TestCase):
 
@@ -36,15 +37,35 @@
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_PUBLIC, True).filter(data)), data)
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_PUBLIC, False).filter(data)), data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, True).filter(item)), data)
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, False).filter(item)), data)
 
+    def test_public_none(self):
+        
+        data = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART:20080601T120000Z
+DTEND:20080601T130000Z
+ATTENDEE:mailto:user1 at example.com
+ATTENDEE:mailto:user2 at example.com
+ORGANIZER;CN=User 01:mailto:user1 at example.com
+END:VEVENT
+END:VCALENDAR
+""".replace("\n", "\r\n")
+        
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(PrivateEventFilter(None, True).filter(item)), data)
+            self.assertEqual(str(PrivateEventFilter(None, False).filter(item)), data)
+
     def test_public(self):
         
         data = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-X-CALENDARSERVER-ACCESS:PUBLIC
 BEGIN:VEVENT
 UID:12345-67890
 DTSTART:20080601T120000Z
@@ -53,18 +74,19 @@
 ATTENDEE:mailto:user2 at example.com
 ORGANIZER;CN=User 01:mailto:user1 at example.com
 END:VEVENT
+X-CALENDARSERVER-ACCESS:PUBLIC
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_PUBLIC, True).filter(data)), data)
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_PUBLIC, False).filter(data)), data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, True).filter(item)), data)
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PUBLIC, False).filter(item)), data)
 
     def test_private(self):
         
         data = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-X-CALENDARSERVER-ACCESS:PRIVATE
 BEGIN:VEVENT
 UID:12345-67890
 DTSTART:20080601T120000Z
@@ -73,30 +95,32 @@
 ATTENDEE:mailto:user2 at example.com
 ORGANIZER;CN=User 01:mailto:user1 at example.com
 END:VEVENT
+X-CALENDARSERVER-ACCESS:PRIVATE
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_PRIVATE, True).filter(data)), data)
-        pfilter = PrivateEventFilter(PrivateEventFilter.ACCESS_PRIVATE, False)
-        self.assertRaises(HTTPError, pfilter.filter, data)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_PRIVATE, True).filter(item)), data)
+            pfilter = PrivateEventFilter(Component.ACCESS_PRIVATE, False)
+            self.assertRaises(HTTPError, pfilter.filter, item)
 
     def test_confidential(self):
         
         data = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-X-CALENDARSERVER-ACCESS:CONFIDENTIAL
 BEGIN:VEVENT
 UID:12345-67890
 DTSTART:20080601T120000Z
 DTEND:20080601T130000Z
 ATTENDEE:mailto:user1 at example.com
 ATTENDEE:mailto:user2 at example.com
+DESCRIPTION:In confidence
+LOCATION:My office
 ORGANIZER;CN=User 01:mailto:user1 at example.com
 SUMMARY:Confidential
-DESCRIPTION:In confidence
-LOCATION:My office
 END:VEVENT
+X-CALENDARSERVER-ACCESS:CONFIDENTIAL
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
@@ -112,26 +136,27 @@
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_CONFIDENTIAL, True).filter(data)), data)
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_CONFIDENTIAL, False).filter(data)), filtered)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_CONFIDENTIAL, True).filter(item)), data)
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_CONFIDENTIAL, False).filter(item)), filtered)
 
     def test_restricted(self):
         
         data = """BEGIN:VCALENDAR
 VERSION:2.0
 PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
-X-CALENDARSERVER-ACCESS:CONFIDENTIAL
 BEGIN:VEVENT
 UID:12345-67890
 DTSTART:20080601T120000Z
 DTEND:20080601T130000Z
 ATTENDEE:mailto:user1 at example.com
 ATTENDEE:mailto:user2 at example.com
+DESCRIPTION:In confidence
+LOCATION:My office
 ORGANIZER;CN=User 01:mailto:user1 at example.com
 SUMMARY:Confidential
-DESCRIPTION:In confidence
-LOCATION:My office
 END:VEVENT
+X-CALENDARSERVER-ACCESS:RESTRICTED
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
@@ -145,9 +170,10 @@
 LOCATION:My office
 SUMMARY:Confidential
 END:VEVENT
-X-CALENDARSERVER-ACCESS:CONFIDENTIAL
+X-CALENDARSERVER-ACCESS:RESTRICTED
 END:VCALENDAR
 """.replace("\n", "\r\n")
         
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_RESTRICTED, True).filter(data)), data)
-        self.assertEqual(str(PrivateEventFilter(PrivateEventFilter.ACCESS_RESTRICTED, False).filter(data)), filtered)
+        for item in (data, Component.fromString(data),):
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_RESTRICTED, True).filter(item)), data)
+            self.assertEqual(str(PrivateEventFilter(Component.ACCESS_RESTRICTED, False).filter(item)), filtered)

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/get.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/get.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/get.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2005-2008 Apple Inc. All rights reserved.
+# Copyright (c) 2005-2009 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -27,10 +27,9 @@
 from twisted.web2.http_headers import MimeType
 from twisted.web2.stream import MemoryStream
 
-from twistedcaldav import caldavxml
 from twistedcaldav.caldavxml import ScheduleTag
 from twistedcaldav.customxml import TwistedCalendarAccessProperty
-from twistedcaldav.ical import Component
+from twistedcaldav.datafilters.privateevents import PrivateEventFilter
 
 @inlineCallbacks
 def http_GET(self, request):
@@ -42,7 +41,7 @@
         except HTTPError:
             access = None
             
-        if access in (Component.ACCESS_CONFIDENTIAL, Component.ACCESS_RESTRICTED):
+        if access:
     
             # Check authorization first
             yield self.authorize(request, (davxml.Read(),))
@@ -50,15 +49,13 @@
             # Non DAV:owner's have limited access to the data
             isowner = (yield self.isOwner(request, adminprincipals=True, readprincipals=True))
             
-            if not isowner:
-                # Now "filter" the resource calendar data through the CALDAV:calendar-data element and apply
-                # access restrictions to the data.
-                caldata = caldavxml.CalendarData().elementFromResourceWithAccessRestrictions(self, access).calendarData()
+            # Now "filter" the resource calendar data
+            caldata = PrivateEventFilter(access, isowner).filter(self.iCalendarText())
 
-                response = Response()
-                response.stream = MemoryStream(caldata)
-                response.headers.setHeader("content-type", MimeType.fromString("text/calendar; charset=utf-8"))
-                returnValue(response)
+            response = Response()
+            response.stream = MemoryStream(str(caldata))
+            response.headers.setHeader("content-type", MimeType.fromString("text/calendar; charset=utf-8"))
+            returnValue(response)
 
 
     # Do normal GET behavior

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/report_common.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/report_common.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/method/report_common.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -1,5 +1,5 @@
 ##
-# Copyright (c) 2006-2008 Apple Inc. All rights reserved.
+# Copyright (c) 2006-2009 Apple Inc. All rights reserved.
 #
 # Licensed under the Apache License, Version 2.0 (the "License");
 # you may not use this file except in compliance with the License.
@@ -51,8 +51,10 @@
 from twisted.web2.http import HTTPError
 
 from twistedcaldav import caldavxml
-from twistedcaldav.caldavxml import caldav_namespace
+from twistedcaldav.caldavxml import caldav_namespace, CalendarData
 from twistedcaldav.customxml import TwistedCalendarAccessProperty
+from twistedcaldav.datafilters.calendardata import CalendarDataFilter
+from twistedcaldav.datafilters.privateevents import PrivateEventFilter
 from twistedcaldav.dateops import clipPeriod, normalizePeriodList, timeRangesOverlap
 from twistedcaldav.ical import Component, Property, iCalendarProductID
 from twistedcaldav.instance import InstanceList
@@ -244,20 +246,16 @@
     for property in props:
         if isinstance(property, caldavxml.CalendarData):
             # Handle private events access restrictions
-            if not isowner:
-                try:
-                    access = resource.readDeadProperty(TwistedCalendarAccessProperty)
-                except HTTPError:
-                    access = None
-            else:
+            try:
+                access = resource.readDeadProperty(TwistedCalendarAccessProperty)
+            except HTTPError:
                 access = None
 
-            if calendar:
-                propvalue = property.elementFromCalendarWithAccessRestrictions(calendar, access, timezone)
-            else:
-                propvalue = property.elementFromResourceWithAccessRestrictions(resource, access, timezone)
-            if propvalue is None:
-                raise ValueError("Invalid CalDAV:calendar-data for request: %r" % (property,))
+            if calendar is None:
+                calendar = resource.iCalendarText()
+            filtered = PrivateEventFilter(access, isowner).filter(calendar)
+            filtered = CalendarDataFilter(property, timezone).filter(filtered)
+            propvalue = CalendarData().fromCalendar(filtered)
             properties_by_status[responsecode.OK].append(propvalue)
             continue
     

Modified: CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/static.py
===================================================================
--- CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/static.py	2009-10-30 20:11:23 UTC (rev 4685)
+++ CalendarServer/branches/users/cdaboo/per-user-icalendar-4669/twistedcaldav/static.py	2009-11-02 14:33:30 UTC (rev 4686)
@@ -59,6 +59,7 @@
 from twistedcaldav.caldavxml import caldav_namespace
 from twistedcaldav.config import config
 from twistedcaldav.customxml import TwistedCalendarAccessProperty, TwistedScheduleMatchETags
+from twistedcaldav.datafilters.privateevents import PrivateEventFilter
 from twistedcaldav.extensions import DAVFile, CachingPropertyStore
 from twistedcaldav.memcacheprops import MemcachePropertyCollection
 from twistedcaldav.freebusyurl import FreeBusyURLResource
@@ -303,15 +304,11 @@
         except HTTPError:
             access = None
 
-        if access in (iComponent.ACCESS_CONFIDENTIAL, iComponent.ACCESS_RESTRICTED):
+        # Now "filter" the resource calendar data
+        caldata = PrivateEventFilter(access, isowner).filter(self.iCalendarText())
 
-            if not isowner:
-                # Now "filter" the resource calendar data through the CALDAV:calendar-data element and apply
-                # access restrictions to the data.
-                return caldavxml.CalendarData().elementFromResourceWithAccessRestrictions(self, access).calendarData()
+        return str(caldata)
 
-        return self.iCalendarText()
-
     def iCalendarText(self, name=None):
         if self.isPseudoCalendarCollection():
             if name is None:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20091102/21fdd1b7/attachment-0001.html>


More information about the calendarserver-changes mailing list