[CalendarServer-changes] [13709] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Tue Jul 1 09:39:18 PDT 2014


Revision: 13709
          http://trac.calendarserver.org//changeset/13709
Author:   cdaboo at apple.com
Date:     2014-07-01 09:39:18 -0700 (Tue, 01 Jul 2014)
Log Message:
-----------
Make sure non-standard timezones are not stripped from calendar data in the db or when returned to clients.

Modified Paths:
--------------
    CalendarServer/trunk/calendarserver/tools/anonymize.py
    CalendarServer/trunk/calendarserver/tools/dbinspect.py
    CalendarServer/trunk/requirements-dev.txt
    CalendarServer/trunk/requirements-stable.txt
    CalendarServer/trunk/twistedcaldav/ical.py
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py

Modified: CalendarServer/trunk/calendarserver/tools/anonymize.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/anonymize.py	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/calendarserver/tools/anonymize.py	2014-07-01 16:39:18 UTC (rev 13709)
@@ -342,7 +342,7 @@
             except KeyError:
                 pass
 
-    return pyobj.getText(includeTimezones=True)
+    return pyobj.getText(includeTimezones=Calendar.ALL_TIMEZONES)
 
 
 

Modified: CalendarServer/trunk/calendarserver/tools/dbinspect.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/dbinspect.py	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/calendarserver/tools/dbinspect.py	2014-07-01 16:39:18 UTC (rev 13709)
@@ -772,7 +772,7 @@
             event = yield calendar.calendarObjectWithName(name)
             ical_data = yield event.component()
             ical_data = PerUserDataFilter(uid).filter(ical_data)
-            ical_data.stripKnownTimezones()
+            ical_data.stripStandardTimezones()
 
             table = tables.Table()
             table.addRow(("Calendar:", calendar.name(),))
@@ -782,7 +782,7 @@
             table.addRow(("Modified", event.modified()))
             print("\n")
             table.printTable()
-            print(ical_data.getTextWithTimezones(includeTimezones=False))
+            print(ical_data.getTextWithoutTimezones())
 
 
 

Modified: CalendarServer/trunk/requirements-dev.txt
===================================================================
--- CalendarServer/trunk/requirements-dev.txt	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/requirements-dev.txt	2014-07-01 16:39:18 UTC (rev 13709)
@@ -7,4 +7,4 @@
 mockldap
 q
 --editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVClientLibrary/trunk@13420#egg=CalDAVClientLibrary
---editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13702#egg=CalDAVTester
+--editable svn+http://svn.calendarserver.org/repository/calendarserver/CalDAVTester/trunk@13708#egg=CalDAVTester

Modified: CalendarServer/trunk/requirements-stable.txt
===================================================================
--- CalendarServer/trunk/requirements-stable.txt	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/requirements-stable.txt	2014-07-01 16:39:18 UTC (rev 13709)
@@ -7,7 +7,7 @@
 -e .
 -e svn+http://svn.calendarserver.org/repository/calendarserver/twext/trunk@13696#egg=twextpy
 -e svn+http://svn.calendarserver.org/repository/calendarserver/PyKerberos/trunk@13420#egg=kerberos
--e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13689#egg=pycalendar
+-e svn+http://svn.calendarserver.org/repository/calendarserver/PyCalendar/trunk@13707#egg=pycalendar
 
 # Specify specific versions of our dependencies so that we're all testing the same config.
 

Modified: CalendarServer/trunk/twistedcaldav/ical.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/ical.py	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/twistedcaldav/ical.py	2014-07-01 16:39:18 UTC (rev 13709)
@@ -45,7 +45,7 @@
 from twistedcaldav.dateops import timeRangesOverlap, normalizeForIndex, differenceDateTime, \
     normalizeForExpand
 from twistedcaldav.instance import InstanceList, InvalidOverriddenInstanceError
-from twistedcaldav.timezones import hasTZ, TimezoneException
+from twistedcaldav.timezones import hasTZ
 
 from txdav.caldav.datastore.scheduling.utils import normalizeCUAddr
 
@@ -602,13 +602,31 @@
 
 
     def getText(self, format=None):
-        return self.getTextWithTimezones(False, format)
+        """
+        Return text representation and include non-standard timezones.
+        """
+        return self._getTextWithTimezones(includeTimezones=Calendar.NONSTD_TIMEZONES, format=format)
 
 
     def getTextWithTimezones(self, includeTimezones, format=None):
         """
         Return text representation and include timezones if the option is on.
         """
+        includeTimezones = Calendar.ALL_TIMEZONES if includeTimezones else Calendar.NONSTD_TIMEZONES
+        return self._getTextWithTimezones(includeTimezones=includeTimezones, format=format)
+
+
+    def getTextWithoutTimezones(self, format=None):
+        """
+        Return text representation without including timezones.
+        """
+        return self._getTextWithTimezones(includeTimezones=Calendar.NO_TIMEZONES, format=format)
+
+
+    def _getTextWithTimezones(self, includeTimezones, format=None):
+        """
+        Return text representation and include timezones if the option is on.
+        """
         assert self.name() == "VCALENDAR", "Must be a VCALENDAR: {0!r}".format(self,)
 
         result = self._pycalendar.getText(includeTimezones=includeTimezones, format=format)
@@ -1781,28 +1799,13 @@
         return self._resource_type
 
 
-    def stripKnownTimezones(self):
+    def stripStandardTimezones(self):
         """
         Remove timezones that this server knows about
         """
+        return self._pycalendar.stripStandardTimezones()
 
-        changed = False
-        for subcomponent in tuple(self.subcomponents()):
-            if subcomponent.name() == "VTIMEZONE":
-                tzid = subcomponent.propertyValue("TZID")
-                try:
-                    hasTZ(tzid)
-                except TimezoneException:
-                    # tzid not available - do not strip
-                    pass
-                else:
-                    # tzid known - strip component out
-                    self.removeComponent(subcomponent)
-                    changed = True
 
-        return changed
-
-
     def validCalendarData(self, doFix=True, doRaise=True, validateRecurrences=False):
         """
         @return: tuple of fixed, unfixed issues

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2014-07-01 16:39:18 UTC (rev 13709)
@@ -1894,7 +1894,7 @@
 
         # Possible timezone stripping
         if config.EnableTimezonesByReference:
-            component.stripKnownTimezones()
+            component.stripStandardTimezones()
 
         # Do validation on external requests
         if internal_state == ComponentUpdateState.NORMAL:

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2014-07-01 16:37:13 UTC (rev 13708)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2014-07-01 16:39:18 UTC (rev 13709)
@@ -39,6 +39,7 @@
 from twistedcaldav.dateops import datetimeMktime
 from twistedcaldav.ical import Component, normalize_iCalStr, diff_iCalStrs
 from twistedcaldav.instance import InvalidOverriddenInstanceError
+from twistedcaldav.timezones import TimezoneCache
 
 from txdav.base.propertystore.base import PropertyName
 from txdav.caldav.datastore.query.filter import Filter
@@ -2017,7 +2018,103 @@
         yield self.abort()
 
 
+    @inlineCallbacks
+    def test_standardTimezone(self):
+        """
+        Make sure a standard timezone is not stored and not returned in the calendar data when timezones
+        by reference is on.
+        """
+        data = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:America/New_York
+X-LIC-LOCATION:America/New_York
+BEGIN:STANDARD
+DTSTART:18000101T000000
+RDATE:18000101T000000
+TZNAME:GMT+1
+TZOFFSETFROM:-0100
+TZOFFSETTO:-0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART;TZID=America/New_York:20130806T000000
+DURATION:PT1H
+DTSTAMP:20051222T210507Z
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+"""
 
+        self.patch(config, "EnableTimezonesByReference", True)
+        TimezoneCache.create()
+        self.addCleanup(TimezoneCache.clear)
+
+        yield self.homeUnderTest(name="user01", create=True)
+        calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+        yield calendar.createCalendarObjectWithName("data1.ics", Component.fromString(data))
+        yield self.commit()
+
+        obj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+        txt = yield obj._text()
+        self.assertTrue("BEGIN:VTIMEZONE" not in txt)
+        cal = yield obj.componentForUser("user01")
+        self.assertEqual(len(tuple(cal.subcomponents())), 1)
+        txt = cal.getTextWithTimezones(False)
+        self.assertTrue("BEGIN:VTIMEZONE" not in txt)
+
+
+    @inlineCallbacks
+    def test_nonStandardTimezone(self):
+        """
+        Make sure a non-standard timezone is stored and returned in the calendar data when timezones
+        by reference is on.
+        """
+        data = """BEGIN:VCALENDAR
+VERSION:2.0
+PRODID:-//CALENDARSERVER.ORG//NONSGML Version 1//EN
+BEGIN:VTIMEZONE
+TZID:GMTPlusOne
+X-LIC-LOCATION:GMTPlusOne
+BEGIN:STANDARD
+DTSTART:18000101T000000
+RDATE:18000101T000000
+TZNAME:GMT+1
+TZOFFSETFROM:-0100
+TZOFFSETTO:-0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+UID:12345-67890
+DTSTART;TZID=GMTPlusOne:20130806T000000
+DURATION:PT1H
+DTSTAMP:20051222T210507Z
+SUMMARY:1
+END:VEVENT
+END:VCALENDAR
+"""
+
+        self.patch(config, "EnableTimezonesByReference", True)
+        TimezoneCache.create()
+        self.addCleanup(TimezoneCache.clear)
+
+        yield self.homeUnderTest(name="user01", create=True)
+        calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+        yield calendar.createCalendarObjectWithName("data1.ics", Component.fromString(data))
+        yield self.commit()
+
+        obj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+        txt = yield obj._text()
+        self.assertTrue("TZID:GMTPlusOne" in txt)
+        cal = yield obj.componentForUser("user01")
+        self.assertEqual(len(tuple(cal.subcomponents())), 2)
+        txt = cal.getTextWithTimezones(False)
+        self.assertTrue("BEGIN:VTIMEZONE" in txt)
+
+
+
 class SchedulingTests(CommonCommonTests, unittest.TestCase):
     """
     CalendarObject splitting tests
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140701/0fc0b985/attachment-0001.html>


More information about the calendarserver-changes mailing list