[CalendarServer-changes] [12049] CalendarServer/branches/users/sagen/groupcacher
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:17:17 PDT 2014
Revision: 12049
http://trac.calendarserver.org//changeset/12049
Author: gaya at apple.com
Date: 2013-12-09 20:49:05 -0800 (Mon, 09 Dec 2013)
Log Message:
-----------
More group attendee tests
Modified Paths:
--------------
CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py
CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py
CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py
CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py
Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py 2013-12-09 23:56:05 UTC (rev 12048)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py 2013-12-10 04:49:05 UTC (rev 12049)
@@ -156,10 +156,10 @@
From=groupMemember,
Where=groupMemember.GROUP_ID == self.groupID,
).on(self.transaction)
- individualGUIDs = [row[0] for row in rows]
+ memberGUIDs = [row[0] for row in rows]
component = yield calendarObject.component()
- changed = component.expandGroupAttendee(self.groupGUID, individualGUIDs, self.directoryService().recordWithCalendarUserAddress)
+ changed = component.expandGroupAttendee(self.groupGUID, memberGUIDs, self.directoryService().recordWithCalendarUserAddress)
if changed:
yield calendarObject.setComponent(component)
@@ -181,7 +181,8 @@
records.add(record)
for member in (yield record.members()):
if member not in records:
- if member.recordType != RecordType.group:
+ #TODO: HACK for old-style XML. FIX
+ if member.recordType != RecordType.group and str(member.recordType) != "groups":
members.add(member)
yield expandedMembers(member, members, records)
Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py 2013-12-09 23:56:05 UTC (rev 12048)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py 2013-12-10 04:49:05 UTC (rev 12049)
@@ -18,13 +18,20 @@
Group membership caching implementation tests
"""
+from calendarserver.tap.util import directoryFromConfig
from twext.who.groups import GroupCacher, expandedMembers
from twext.who.idirectory import RecordType
from twext.who.test.test_xml import xmlService
from twisted.internet.defer import inlineCallbacks
+from twisted.trial import unittest
+from twistedcaldav.config import config
+from twistedcaldav.ical import Component, normalize_iCalStr
from twistedcaldav.test.util import StoreTestCase
+from txdav.caldav.datastore.test.util import buildCalendarStore, \
+ populateCalendarsFrom, CommonCommonTests
from txdav.common.icommondatastore import NotFoundError
from uuid import UUID
+import os
class GroupCacherTest(StoreTestCase):
@@ -234,18 +241,6 @@
"""
-
-from twisted.trial import unittest
-from twistedcaldav.config import config
-from twistedcaldav.ical import Component, normalize_iCalStr
-
-from txdav.caldav.datastore.test.util import buildCalendarStore
-from txdav.common.datastore.test.util import populateCalendarsFrom, \
- CommonCommonTests
-
-import os
-from calendarserver.tap.util import directoryFromConfig
-
class GroupAttendeeReconciliation(CommonCommonTests, unittest.TestCase):
"""
GroupAttendeeReconciliation tests
@@ -253,9 +248,11 @@
@inlineCallbacks
def setUp(self):
- config.Scheduling.Options.AllowGroupAsAttendee = True
+ self.patch(config.Scheduling.Options, "AllowGroupAsAttendee", "True")
yield super(GroupAttendeeReconciliation, self).setUp()
+ self.xmlService = xmlService(self.mktemp(), xmlData=testXMLConfig)
+
self.patch(config.DirectoryService.params, "xmlFile",
os.path.join(
os.path.dirname(__file__), "accounts", "accounts.xml"
@@ -297,7 +294,7 @@
"""
calendar = yield self.calendarUnderTest(name="calendar", home="user01")
- data_put_2 = """BEGIN:VCALENDAR
+ data_put_1 = """BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Example Inc.//Example Calendar//EN
VERSION:2.0
@@ -306,20 +303,20 @@
CREATED:20060101T150000Z
DTSTART;TZID=US/Eastern:20140101T100000
DURATION:PT1H
-SUMMARY:event 2
-UID:event2 at ninevah.local
+SUMMARY:event 1
+UID:event1 at ninevah.local
ORGANIZER:MAILTO:user01 at example.com
ATTENDEE:mailto:user01 at example.com
ATTENDEE:MAILTO:group02 at example.com
END:VEVENT
END:VCALENDAR"""
- data_get_2 = """BEGIN:VCALENDAR
+ data_get_1 = """BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//Example Inc.//Example Calendar//EN
BEGIN:VEVENT
-UID:event2 at ninevah.local
+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:user01
@@ -328,28 +325,28 @@
ATTENDEE;CN=User 07;EMAIL=user07 at example.com;MEMBER="urn:uuid:group02";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user07
CREATED:20060101T150000Z
ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
-SUMMARY:event 2
+SUMMARY:event 1
END:VEVENT
END:VCALENDAR
"""
- vcalendar2 = Component.fromString(data_put_2)
- cobj2 = yield calendar.createCalendarObjectWithName("data2.ics", vcalendar2)
+ vcalendar1 = Component.fromString(data_put_1)
+ cobj1 = yield calendar.createCalendarObjectWithName("data1.ics", vcalendar1)
yield self.commit()
- cobj2 = yield self.calendarObjectUnderTest(name="data2.ics", calendar_name="calendar", home="user01")
- vcalendar2 = yield cobj2.component()
- self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_2))
+ cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+ vcalendar2 = yield cobj1.component()
+ self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
@inlineCallbacks
def test_unknownPUT(self):
"""
- Test that group attendee is expanded on PUT
+ Test unknown group with CUTYPE=GROUP handled
"""
calendar = yield self.calendarUnderTest(name="calendar", home="user01")
- data_put_2 = """BEGIN:VCALENDAR
+ data_put_1 = """BEGIN:VCALENDAR
CALSCALE:GREGORIAN
PRODID:-//Example Inc.//Example Calendar//EN
VERSION:2.0
@@ -358,38 +355,38 @@
CREATED:20060101T150000Z
DTSTART;TZID=US/Eastern:20140101T100000
DURATION:PT1H
-SUMMARY:event 2
-UID:event2 at ninevah.local
+SUMMARY:event 1
+UID:event1 at ninevah.local
ORGANIZER:MAILTO:user01 at example.com
ATTENDEE:mailto:user01 at example.com
ATTENDEE;CUTYPE=GROUP:urn:uuid:groupUnknown
END:VEVENT
END:VCALENDAR"""
- data_get_2 = """BEGIN:VCALENDAR
+ data_get_1 = """BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:-//Example Inc.//Example Calendar//EN
BEGIN:VEVENT
-UID:event2 at ninevah.local
+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:user01
ATTENDEE;CUTYPE=GROUP;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:groupUnknown
CREATED:20060101T150000Z
ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
-SUMMARY:event 2
+SUMMARY:event 1
END:VEVENT
END:VCALENDAR
"""
- vcalendar2 = Component.fromString(data_put_2)
- cobj2 = yield calendar.createCalendarObjectWithName("data2.ics", vcalendar2)
+ vcalendar1 = Component.fromString(data_put_1)
+ cobj1 = yield calendar.createCalendarObjectWithName("data1.ics", vcalendar1)
yield self.commit()
- cobj2 = yield self.calendarObjectUnderTest(name="data2.ics", calendar_name="calendar", home="user01")
- vcalendar2 = yield cobj2.component()
- self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_2))
+ cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+ vcalendar2 = yield cobj1.component()
+ self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
@inlineCallbacks
@@ -441,3 +438,115 @@
cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
vcalendar1 = yield cobj1.component()
self.assertEqual(normalize_iCalStr(vcalendar1), normalize_iCalStr(data_get_1))
+
+
+ @inlineCallbacks
+ def test_nestedPUT(self):
+ """
+ Test that nested groups are expanded expanded on PUT
+ """
+ calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+
+ data_put_1 = """BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART;TZID=US/Eastern:20140101T100000
+DURATION:PT1H
+SUMMARY:event 1
+UID:event1 at ninevah.local
+ORGANIZER:MAILTO:user01 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:urn:uuid:group04
+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:user01
+ATTENDEE;CN=Group 04;CUTYPE=GROUP;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group04
+ATTENDEE;CN=User 06;EMAIL=user06 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user06
+ATTENDEE;CN=User 07;EMAIL=user07 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user07
+ATTENDEE;CN=User 08;EMAIL=user08 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user08
+ATTENDEE;CN=User 09;EMAIL=user09 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user09
+ATTENDEE;CN=User 10;EMAIL=user10 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user10
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ vcalendar1 = Component.fromString(data_put_1)
+ cobj1 = yield calendar.createCalendarObjectWithName("data1.ics", vcalendar1)
+ yield self.commit()
+
+ cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+ vcalendar2 = yield cobj1.component()
+ self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
+
+
+ @inlineCallbacks
+ def test_twoGroupPUT(self):
+ """
+ Test that expanded users in two primary groups have groups in MEMBERS param
+ """
+ calendar = yield self.calendarUnderTest(name="calendar", home="user01")
+
+ data_put_1 = """BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART;TZID=US/Eastern:20140101T100000
+DURATION:PT1H
+SUMMARY:event 1
+UID:event1 at ninevah.local
+ORGANIZER:MAILTO:user01 at example.com
+ATTENDEE:mailto:user01 at example.com
+ATTENDEE:MAILTO:group02 at example.com
+ATTENDEE:urn:uuid:group04
+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:user01
+ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group02
+ATTENDEE;CN=Group 04;CUTYPE=GROUP;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group04
+ATTENDEE;CN=User 06;EMAIL=user06 at example.com;MEMBER="urn:uuid:group04","urn:uuid:group02";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user06
+ATTENDEE;CN=User 07;EMAIL=user07 at example.com;MEMBER="urn:uuid:group04","urn:uuid:group02";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user07
+ATTENDEE;CN=User 08;EMAIL=user08 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user08
+ATTENDEE;CN=User 09;EMAIL=user09 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user09
+ATTENDEE;CN=User 10;EMAIL=user10 at example.com;MEMBER="urn:uuid:group04";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user10
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 01;EMAIL=user01 at example.com:urn:uuid:user01
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ vcalendar1 = Component.fromString(data_put_1)
+ cobj1 = yield calendar.createCalendarObjectWithName("data1.ics", vcalendar1)
+ yield self.commit()
+
+ cobj1 = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
+ vcalendar2 = yield cobj1.component()
+ self.assertEqual(normalize_iCalStr(vcalendar2), normalize_iCalStr(data_get_1))
Modified: CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py 2013-12-09 23:56:05 UTC (rev 12048)
+++ CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py 2013-12-10 04:49:05 UTC (rev 12049)
@@ -3355,21 +3355,21 @@
component.normalizeCalendarUserAddresses(lookupFunction, principalFunction, toUUID)
- def expandGroupAttendee(self, groupGUID, individualGUIDs, principalFunction):
+ def expandGroupAttendee(self, groupGUID, memberGUIDs, principalFunction):
- individualUUIDs = set(["urn:uuid:" + individualGUID for individualGUID in individualGUIDs])
+ memberUUIDs = set(["urn:uuid:" + memberGUID for memberGUID in memberGUIDs])
groupUUID = "urn:uuid:" + groupGUID
changed = False
for component in self.subcomponents():
if component.name() in ignoredComponents:
continue
- oldAttendeeProps = component.properties("ATTENDEE")
+ oldAttendeeProps = tuple(component.properties("ATTENDEE"))
oldAttendeeUUIDs = set([attendeeProp.value() for attendeeProp in oldAttendeeProps])
# add new member attendees
- for individualUUID in individualUUIDs - oldAttendeeUUIDs:
- directoryRecord = principalFunction(individualUUID)
+ for memberUUID in memberUUIDs - oldAttendeeUUIDs:
+ directoryRecord = principalFunction(memberUUID)
newAttendeeProp = directoryRecord.attendee(params={"MEMBER": groupUUID})
component.addProperty(newAttendeeProp)
changed = True
@@ -3377,16 +3377,16 @@
# remove attendee or update MEMBER attribute for non-primary attendees in this group,
for attendeeProp in oldAttendeeProps:
if attendeeProp.hasParameter("MEMBER"):
- parameterValues = attendeeProp.parameterValues("MEMBER")
+ parameterValues = tuple(attendeeProp.parameterValues("MEMBER"))
if groupUUID in parameterValues:
- if attendeeProp.value() not in individualUUIDs:
+ if attendeeProp.value() not in memberUUIDs:
attendeeProp.removeParameterValue("MEMBER", groupUUID)
if not attendeeProp.parameterValues("MEMBER"):
component.removeProperty(attendeeProp)
changed = True
else:
- if attendeeProp.value() in individualUUIDs:
- attendeeProp.setParameter("MEMBER", parameterValues + [groupUUID, ])
+ if attendeeProp.value() in memberUUIDs:
+ attendeeProp.setParameter("MEMBER", parameterValues + tuple([groupUUID, ]))
changed = True
return changed
Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py 2013-12-09 23:56:05 UTC (rev 12048)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py 2013-12-10 04:49:05 UTC (rev 12049)
@@ -1627,9 +1627,9 @@
members = yield expandedMembers(groupRecord)
membershipHashContent = hashlib.md5()
members = yield expandedMembers(groupRecord)
- individualGUIDs = sorted([member.guid for member in members])
- for individualGUID in individualGUIDs:
- membershipHashContent.update(str(individualGUID))
+ memberGUIDs = sorted([member.guid for member in members])
+ for memberGUID in memberGUIDs:
+ membershipHashContent.update(str(memberGUID))
membershipHash = membershipHashContent.hexdigest()
# associate group ID with self
@@ -1645,7 +1645,7 @@
pass
# get members
- component.expandGroupAttendee(groupGUID, individualGUIDs, self.directoryService().recordWithCalendarUserAddress)
+ component.expandGroupAttendee(groupGUID, memberGUIDs, self.directoryService().recordWithCalendarUserAddress)
def validCalendarDataCheck(self, component, inserting): #@UnusedVariable
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/b9564fa9/attachment.html>
More information about the calendarserver-changes
mailing list