[CalendarServer-changes] [12813] CalendarServer/trunk/txdav

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 5 07:22:48 PST 2014


Revision: 12813
          http://trac.calendarserver.org//changeset/12813
Author:   cdaboo at apple.com
Date:     2014-03-05 07:22:47 -0800 (Wed, 05 Mar 2014)
Log Message:
-----------
Make sure pre-existing inbox items are always set to transparent. Change code to always coerce inbox to transparent.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/sql.py
    CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
    CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py
    CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py

Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/sql.py	2014-03-05 05:43:16 UTC (rev 12812)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py	2014-03-05 15:22:47 UTC (rev 12813)
@@ -1258,25 +1258,27 @@
 
     def isUsedForFreeBusy(self):
         """
-        Indicates whether the contents of this calendar contributes to free busy.
+        Indicates whether the contents of this calendar contributes to free busy. Always coerce
+        inbox to be transparent.
 
         @return: C{True} if it does, C{False} otherwise
         @rtype: C{bool}
         """
-        return self._transp == _TRANSP_OPAQUE
+        return (self._transp == _TRANSP_OPAQUE) and not self.isInbox()
 
 
     @inlineCallbacks
     def setUsedForFreeBusy(self, use_it):
         """
         Mark this calendar as being used for free busy request. Note this is a per-user setting so we are setting
-        this on the bind table entry which is related to the user viewing the calendar.
+        this on the bind table entry which is related to the user viewing the calendar. Always coerce inbox to be
+        transparent.
 
         @param use_it: C{True} if used for free busy, C{False} otherwise
         @type use_it: C{bool}
         """
 
-        self._transp = _TRANSP_OPAQUE if use_it else _TRANSP_TRANSPARENT
+        self._transp = _TRANSP_OPAQUE if use_it and not self.isInbox() else _TRANSP_TRANSPARENT
         cal = self._bindSchema
         yield Update(
             {cal.TRANSP : self._transp},

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2014-03-05 05:43:16 UTC (rev 12812)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/test_sql.py	2014-03-05 15:22:47 UTC (rev 12813)
@@ -62,7 +62,7 @@
 from txdav.common.datastore.sql import ECALENDARTYPE, CommonObjectResource, \
     CommonStoreTransactionMonitor
 from txdav.common.datastore.sql_tables import schema, _BIND_MODE_DIRECT, \
-    _BIND_STATUS_ACCEPTED
+    _BIND_STATUS_ACCEPTED, _TRANSP_OPAQUE
 from txdav.common.datastore.test.util import populateCalendarsFrom, \
     CommonCommonTests
 from txdav.common.icommondatastore import NoSuchObjectResourceError
@@ -1930,7 +1930,37 @@
         self.assertTrue(token is not None)
 
 
+    @inlineCallbacks
+    def test_inboxTransp(self):
+        """
+        Make sure inbox is always transparent no matter what is stored in the DB.
+        """
 
+        home = yield self.homeUnderTest(name="user01", create=True)
+        self.assertNotEqual(home, None)
+        inbox = yield self.calendarUnderTest(home="user01", name="inbox")
+        self.assertFalse(inbox.isUsedForFreeBusy())
+        yield inbox.setUsedForFreeBusy(True)
+        self.assertFalse(inbox.isUsedForFreeBusy())
+        yield self.commit()
+
+        inbox = yield self.calendarUnderTest(home="user01", name="inbox")
+        self.assertFalse(inbox.isUsedForFreeBusy())
+
+        cb = schema.CALENDAR_BIND
+        yield Update(
+            {cb.TRANSP: _TRANSP_OPAQUE},
+            Where=(cb.CALENDAR_RESOURCE_NAME == "inbox").And(
+                cb.CALENDAR_RESOURCE_ID == inbox.id()
+            )
+        ).on(self.transactionUnderTest())
+        yield self.commit()
+
+        inbox = yield self.calendarUnderTest(home="user01", name="inbox")
+        self.assertFalse(inbox.isUsedForFreeBusy())
+
+
+
 class SchedulingTests(CommonCommonTests, unittest.TestCase):
     """
     CalendarObject splitting tests

Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py	2014-03-05 05:43:16 UTC (rev 12812)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/calendar_upgrade_from_5_to_6.py	2014-03-05 15:22:47 UTC (rev 12813)
@@ -19,7 +19,8 @@
 
 from twisted.internet.defer import inlineCallbacks
 
-from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN
+from txdav.common.datastore.sql_tables import schema, _BIND_MODE_OWN, \
+    _TRANSP_TRANSPARENT
 from txdav.common.datastore.upgrade.sql.upgrades.util import updateCalendarDataVersion, \
     updateAllCalendarHomeDataVersions
 
@@ -37,6 +38,8 @@
 
     sqlTxn = sqlStore.newTransaction()
     cb = schema.CALENDAR_BIND
+
+    # Fix shared calendar alarms which should default to "empty"
     yield Update(
         {
             cb.ALARM_VEVENT_TIMED: "empty",
@@ -46,6 +49,14 @@
         },
         Where=(cb.BIND_MODE != _BIND_MODE_OWN)
     ).on(sqlTxn)
+
+    # Fix inbox transparency which should always be True
+    yield Update(
+        {
+            cb.TRANSP: _TRANSP_TRANSPARENT,
+        },
+        Where=(cb.CALENDAR_RESOURCE_NAME == "inbox")
+    ).on(sqlTxn)
     yield sqlTxn.commit()
 
     # Always bump the DB value

Modified: CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py	2014-03-05 05:43:16 UTC (rev 12812)
+++ CalendarServer/trunk/txdav/common/datastore/upgrade/sql/upgrades/test/test_upgrade_from_5_to_6.py	2014-03-05 15:22:47 UTC (rev 12813)
@@ -20,10 +20,11 @@
 
 from twisted.internet.defer import inlineCallbacks, returnValue
 
-from twext.enterprise.dal.syntax import Update
+from twext.enterprise.dal.syntax import Update, Select
 
 from txdav.caldav.datastore.test.util import CommonStoreTests
-from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE, _BIND_MODE_READ
+from txdav.common.datastore.sql_tables import _BIND_MODE_WRITE, _BIND_MODE_READ,\
+    _TRANSP_OPAQUE, schema
 from txdav.common.datastore.upgrade.sql.upgrades.calendar_upgrade_from_5_to_6 import doUpgrade
 
 
@@ -63,6 +64,14 @@
         for vevent, timed, alarm in detailscalendar:
             yield calendar.setDefaultAlarm(alarm, vevent, timed)
 
+        cb = schema.CALENDAR_BIND
+        yield Update(
+            {
+                cb.TRANSP: _TRANSP_OPAQUE,
+            },
+            Where=(cb.CALENDAR_RESOURCE_NAME == "inbox")
+        ).on(self.transactionUnderTest())
+
         home2 = yield self.homeUnderTest(name="user02")
         shared_name2 = yield calendar.shareWith(home2, _BIND_MODE_WRITE)
         shared = yield self.calendarUnderTest(name=shared_name2, home="user02")
@@ -98,7 +107,7 @@
 
 
     @inlineCallbacks
-    def _upgrade_check(self, detailshome, detailscalendar, detailsshared, shared_name2, shared_name3):
+    def _upgrade_alarms_check(self, detailshome, detailscalendar, detailsshared, shared_name2, shared_name3):
 
         # Check each type of collection
         home = yield self.homeUnderTest(name="user01")
@@ -134,7 +143,32 @@
 
 
     @inlineCallbacks
+    def _upgrade_inbox_check(self, detailshome, detailscalendar, detailsshared, shared_name2, shared_name3):
+
+        calendar = yield self.calendarUnderTest(name="calendar_1", home="user01")
+        self.assertTrue(calendar.isUsedForFreeBusy())
+        inbox = yield self.calendarUnderTest(name="inbox", home="user01")
+        self.assertFalse(inbox.isUsedForFreeBusy())
+
+        cb = schema.CALENDAR_BIND
+        rows = yield Select(
+            [cb.TRANSP],
+            From=cb,
+            Where=(cb.CALENDAR_RESOURCE_NAME == "inbox")
+        ).on(self.transactionUnderTest())
+        self.assertTrue(len(rows) != 0)
+        self.assertTrue(all([row[0] for row in rows]))
+
+
+    @inlineCallbacks
     def test_defaultAlarmUpgrade(self):
         detailshome, detailscalendar, detailsshared, shared_name2, shared_name3 = (yield self._upgrade_setup())
         yield doUpgrade(self._sqlCalendarStore)
-        yield self._upgrade_check(detailshome, detailscalendar, detailsshared, shared_name2, shared_name3)
+        yield self._upgrade_alarms_check(detailshome, detailscalendar, detailsshared, shared_name2, shared_name3)
+
+
+    @inlineCallbacks
+    def test_inboxTranspUpgrade(self):
+        detailshome, detailscalendar, detailsshared, shared_name2, shared_name3 = (yield self._upgrade_setup())
+        yield doUpgrade(self._sqlCalendarStore)
+        yield self._upgrade_inbox_check(detailshome, detailscalendar, detailsshared, shared_name2, shared_name3)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140305/c19e04ad/attachment-0001.html>


More information about the calendarserver-changes mailing list