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

source_changes at macosforge.org source_changes at macosforge.org
Thu Apr 17 08:24:49 PDT 2014


Revision: 13305
          http://trac.calendarserver.org//changeset/13305
Author:   cdaboo at apple.com
Date:     2014-04-17 08:24:49 -0700 (Thu, 17 Apr 2014)
Log Message:
-----------
Fix some issues with group expansion.

Modified Paths:
--------------
    CalendarServer/trunk/txdav/caldav/datastore/test/common.py
    CalendarServer/trunk/txdav/carddav/datastore/test/common.py
    CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py
    CalendarServer/trunk/txdav/common/datastore/test/util.py
    CalendarServer/trunk/txdav/who/groups.py
    CalendarServer/trunk/txdav/who/test/test_group_attendees.py

Modified: CalendarServer/trunk/txdav/caldav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2014-04-17 00:26:27 UTC (rev 13304)
+++ CalendarServer/trunk/txdav/caldav/datastore/test/common.py	2014-04-17 15:24:49 UTC (rev 13305)
@@ -252,7 +252,6 @@
             "calendar_empty": {},
             "not_a_calendar": None
         },
-        "not_a_home": None,
         "home_splits": {
             "calendar_1": {
                 "1.ics": (cal1SplitsRoot.child("1.ics").getContent(), metadata1),
@@ -297,7 +296,6 @@
             "calendar_empty": {},
             "not_a_calendar": None
         },
-        "not_a_home": None,
         "home_splits": {
             "calendar_1": {
                 "1.ics": md5Values[0],

Modified: CalendarServer/trunk/txdav/carddav/datastore/test/common.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/test/common.py	2014-04-17 00:26:27 UTC (rev 13304)
+++ CalendarServer/trunk/txdav/carddav/datastore/test/common.py	2014-04-17 15:24:49 UTC (rev 13305)
@@ -170,7 +170,6 @@
                 "6.vcf": adbk3Root.child("6.vcf").getContent(),
             },
         },
-        "not_a_home": None
     }
     md5s = {
         "home1": {
@@ -200,7 +199,6 @@
                 "6.vcf": md5Values[5],
             },
         },
-        "not_a_home": None
     }
 
     def storeUnderTest(self):

Modified: CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py
===================================================================
--- CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py	2014-04-17 00:26:27 UTC (rev 13304)
+++ CalendarServer/trunk/txdav/carddav/datastore/test/test_sql.py	2014-04-17 15:24:49 UTC (rev 13305)
@@ -80,8 +80,8 @@
         populateTxn = self.storeUnderTest().newTransaction()
         for homeUID in self.requirements:
             addressbooks = self.requirements[homeUID]
+            home = yield populateTxn.addressbookHomeWithUID(homeUID, True)
             if addressbooks is not None:
-                home = yield populateTxn.addressbookHomeWithUID(homeUID, True)
                 addressbook = home.addressbook()
 
                 addressbookObjNames = addressbooks[addressbook.name()]

Modified: CalendarServer/trunk/txdav/common/datastore/test/util.py
===================================================================
--- CalendarServer/trunk/txdav/common/datastore/test/util.py	2014-04-17 00:26:27 UTC (rev 13304)
+++ CalendarServer/trunk/txdav/common/datastore/test/util.py	2014-04-17 15:24:49 UTC (rev 13305)
@@ -488,8 +488,8 @@
         populateTxn._migrating = True
     for homeUID in requirements:
         calendars = requirements[homeUID]
+        home = yield populateTxn.calendarHomeWithUID(homeUID, True)
         if calendars is not None:
-            home = yield populateTxn.calendarHomeWithUID(homeUID, True)
             # We don't want the default calendar or inbox to appear unless it's
             # explicitly listed.
             try:
@@ -516,6 +516,7 @@
                             internal_state=ComponentUpdateState.RAW,
                             options=metadata,
                         )
+
     yield populateTxn.commit()
 
 

Modified: CalendarServer/trunk/txdav/who/groups.py
===================================================================
--- CalendarServer/trunk/txdav/who/groups.py	2014-04-17 00:26:27 UTC (rev 13304)
+++ CalendarServer/trunk/txdav/who/groups.py	2014-04-17 15:24:49 UTC (rev 13305)
@@ -24,7 +24,7 @@
 from twext.enterprise.jobqueue import WorkItem, PeerConnectionPool
 from twisted.internet.defer import inlineCallbacks, returnValue
 from txdav.common.datastore.sql_tables import schema
-from txdav.caldav.datastore.sql import Calendar
+from txdav.caldav.datastore.sql import CalendarStoreFeatures
 import datetime
 import hashlib
 
@@ -175,26 +175,14 @@
             )
         ).on(self.transaction)
 
-        # get calendar id
-        co = schema.CALENDAR_OBJECT
-        rows = yield Select(
-                [co.CALENDAR_RESOURCE_ID, ],
-                From=co,
-                Where=co.RESOURCE_ID == self.resourceID,
-        ).on(self.transaction)
-        calendarID = rows[0][0]
+        # get db object
+        calendarObject = (yield CalendarStoreFeatures(self.transaction._store).calendarObjectWithID(self.transaction, self.resourceID))
+        component = yield calendarObject.componentForUser()
 
-        # get home id
-        calendarHomeID = (yield Calendar._ownerHomeWithResourceID.on(
-            self.transaction, resourceID=calendarID)
-        )[0][0]
+        # Change a copy of the original, as we need the original cached on the resource
+        # so we can do a diff to test implicit scheduling changes
+        component = component.duplicate()
 
-        # get db objects
-        calendarHome = yield self.transaction.calendarHomeWithResourceID(calendarHomeID)
-        calendar = yield calendarHome.childWithID(calendarID)
-        calendarObject = yield calendar.objectResourceWithID(self.resourceID)
-        component = yield calendarObject.component()
-
         # TODO: Check performance because:
         #    1) if the component is changed then expandGroupAttendee() will be called again to validate
         #    2) The group and members are in the group cache so could use them here

Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py
===================================================================
--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py	2014-04-17 00:26:27 UTC (rev 13304)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py	2014-04-17 15:24:49 UTC (rev 13305)
@@ -70,15 +70,23 @@
         self.notifierFactory.reset()
 
     requirements = {
-        "10000000-0000-0000-0000-000000000001" : {
-            "calendar" : {}
-        },
-        "10000000-0000-0000-0000-000000000002" : {
-            "calendar" : {}
-        },
+        "10000000-0000-0000-0000-000000000001" : None,
+        "10000000-0000-0000-0000-000000000002" : None,
+        "10000000-0000-0000-0000-000000000006" : None,
+        "10000000-0000-0000-0000-000000000007" : None,
+        "10000000-0000-0000-0000-000000000008" : None,
+        "10000000-0000-0000-0000-000000000009" : None,
+        "10000000-0000-0000-0000-000000000010" : None,
     }
 
     @inlineCallbacks
+    def _verifyObjectResourceCount(self, home, expected_count):
+        cal6 = yield self.calendarUnderTest(name="calendar", home=home)
+        count = yield cal6.countObjectResources()
+        self.assertEqual(count, expected_count)
+
+
+    @inlineCallbacks
     def test_simplePUT(self):
         """
         Test that group attendee is expanded on PUT
@@ -121,6 +129,9 @@
 END:VCALENDAR
 """
 
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000006", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000007", 0)
+
         vcalendar1 = Component.fromString(data_put_1)
         yield calendar.createCalendarObjectWithName("data1.ics", vcalendar1)
         yield self.commit()
@@ -129,7 +140,10 @@
         vcalendar2 = yield cobj1.component()
         self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
 
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000006", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000007", 1)
 
+
     @inlineCallbacks
     def test_unknownPUT(self):
         """
@@ -236,6 +250,12 @@
         """
         Test that nested groups are expanded expanded on PUT
         """
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000006", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000007", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000008", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000009", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000010", 0)
+
         calendar = yield self.calendarUnderTest(name="calendar", home="10000000-0000-0000-0000-000000000001")
 
         data_put_1 = """BEGIN:VCALENDAR
@@ -285,12 +305,23 @@
         vcalendar2 = yield cobj1.component()
         self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
 
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000006", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000007", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000008", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000009", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000010", 1)
 
+
     @inlineCallbacks
     def test_multiGroupPUT(self):
         """
         Test that expanded users in two primary groups have groups in MEMBERS param
         """
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000006", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000007", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000008", 0)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000009", 0)
+
         calendar = yield self.calendarUnderTest(name="calendar", home="10000000-0000-0000-0000-000000000001")
 
         data_put_1 = """BEGIN:VCALENDAR
@@ -343,11 +374,16 @@
         vcalendar2 = yield cobj1.component()
         self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
 
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000006", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000007", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000008", 1)
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000009", 1)
 
+
     @inlineCallbacks
     def test_groupChange(self):
         """
-        Test that group attendee is expanded on PUT
+        Test that group attendee changes are applied to existing resources.
         """
         data_put_1 = """BEGIN:VCALENDAR
 CALSCALE:GREGORIAN
@@ -366,23 +402,6 @@
 END:VEVENT
 END:VCALENDAR"""
 
-        data_get_1 = """BEGIN:VCALENDAR
-VERSION:2.0
-CALSCALE:GREGORIAN
-PRODID:-//Example Inc.//Example Calendar//EN
-BEGIN:VEVENT
-UID:event1 at ninevah.local
-DTSTART;TZID=US/Eastern:20140101T100000
-DURATION:PT1H
-ATTENDEE;CN=User 01;EMAIL=user01 at example.com;RSVP=TRUE:urn:uuid:10000000-0000-0000-0000-000000000001
-ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:20000000-0000-0000-0000-000000000002
-CREATED:20060101T150000Z
-ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:10000000-0000-0000-0000-000000000001
-SUMMARY:event 1
-END:VEVENT
-END:VCALENDAR
-"""
-
         data_get_2 = """BEGIN:VCALENDAR
 VERSION:2.0
 CALSCALE:GREGORIAN
@@ -410,17 +429,15 @@
 DURATION:PT1H
 ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE:urn:uuid:10000000-0000-0000-0000-000000000002
 ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01 at example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:20000000-0000-0000-0000-000000000001
-ATTENDEE;CN=User 01;EMAIL=user01 at example.com;MEMBER="urn:uuid:20000000-0000-0000-0000-000000000001";PARTSTAT=NEEDS-ACTION:urn:uuid:10000000-0000-0000-0000-000000000001
+ATTENDEE;CN=User 01;EMAIL=user01 at example.com;MEMBER="urn:uuid:20000000-0000-0000-0000-000000000001";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:10000000-0000-0000-0000-000000000001
 CREATED:20060101T150000Z
 ORGANIZER;CN=User 02;EMAIL=user02 at example.com:urn:uuid:10000000-0000-0000-0000-000000000002
+SEQUENCE:1
 SUMMARY:event 1
 END:VEVENT
 END:VCALENDAR
 """
 
-        #TODO: should User 01 have SCHEDULE-STATUS=3.7 ?
-
-
         @inlineCallbacks
         def expandedMembers(self, records=None):
             yield None
@@ -442,6 +459,9 @@
         vcalendar2 = yield cobj1.component()
         self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_2))
 
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000001", 0)
+        yield self.commit()
+
         self.patch(CalendarDirectoryRecordMixin, "expandedMembers", unpatchedExpandedMembers)
 
         groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
@@ -454,3 +474,34 @@
         cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="10000000-0000-0000-0000-000000000002")
         vcalendar3 = yield cobj1.component()
         self.assertEqual(normalize_iCalStr(vcalendar3), normalize_iCalStr(data_get_3))
+
+        yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000001", 1)
+        yield self.commit()
+
+        self.patch(CalendarDirectoryRecordMixin, "expandedMembers", expandedMembers)
+        groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+        wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), "20000000-0000-0000-0000-000000000001")
+        yield self.commit()
+        self.assertEqual(len(wps), 1)
+        for wp in wps:
+            yield wp.whenExecuted()
+
+        cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="10000000-0000-0000-0000-000000000002")
+        vcalendar3 = yield cobj1.component()
+        self.assertEqual(normalize_iCalStr(vcalendar3), normalize_iCalStr(data_get_2))
+
+        cal1 = yield self.calendarUnderTest(name="calendar", home="10000000-0000-0000-0000-000000000001")
+        cobjs = yield cal1.objectResources()
+        self.assertEqual(len(cobjs), 1)
+        comp1 = yield cobjs[0].componentForUser()
+        self.assertTrue("STATUS:CANCELLED" in str(comp1))
+
+
+    @inlineCallbacks
+    def test_groupRemoval(self):
+        """
+        Test that removing a group also removes the expanded attendees. This needs to make sure
+        that an attendee in two groups is NOT removed if only one of those groups is removed
+        """
+
+        self.fail("FIXME: implement this test")
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140417/1981c40d/attachment-0001.html>


More information about the calendarserver-changes mailing list