[CalendarServer-changes] [12045] CalendarServer/branches/users/sagen/groupcacher
source_changes at macosforge.org
source_changes at macosforge.org
Wed Mar 12 11:23:03 PDT 2014
Revision: 12045
http://trac.calendarserver.org//changeset/12045
Author: gaya at apple.com
Date: 2013-12-09 15:19:58 -0800 (Mon, 09 Dec 2013)
Log Message:
-----------
first working twext.who.test.test_groups.GroupAttendeeReconciliation.test_groupAttendeeReconciliation
Modified Paths:
--------------
CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py
CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml
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 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/groups.py 2013-12-09 23:19:58 UTC (rev 12045)
@@ -25,7 +25,6 @@
from twext.who.delegates import allGroupDelegates
from twext.who.idirectory import RecordType
from twisted.internet.defer import inlineCallbacks, returnValue
-from txdav.caldav.datastore.util import normalizationLookup
from txdav.common.datastore.sql_tables import schema
import datetime
import hashlib
@@ -160,7 +159,7 @@
individualGUIDs = [row[0] for row in rows]
component = yield calendarObject.component()
- changed = component.expandGroupAttendee(self.groupGUID, individualGUIDs, normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
+ changed = component.expandGroupAttendee(self.groupGUID, individualGUIDs, self.directoryService().recordWithCalendarUserAddress)
if changed:
yield calendarObject.setComponent(component)
@@ -168,7 +167,7 @@
@inlineCallbacks
-def _expandedMembers(record, members=None, records=None):
+def expandedMembers(record, members=None, records=None):
"""
Return the expanded set of member records. Intermediate groups are not returned
in the results, but their members are.
@@ -184,7 +183,7 @@
if member not in records:
if member.recordType != RecordType.group:
members.add(member)
- yield _expandedMembers(member, members, records)
+ yield expandedMembers(member, members, records)
returnValue(members)
@@ -227,7 +226,7 @@
# and updates the GROUP_MEMBERSHIP table
record = (yield self.directory.recordWithGUID(groupGUID))
membershipHashContent = hashlib.md5()
- members = (yield _expandedMembers(record))
+ members = (yield expandedMembers(record))
members = list(members)
members.sort(cmp=lambda x, y: cmp(x.guid, y.guid))
for member in members:
@@ -282,7 +281,7 @@
returnValue(members)
- # @inlineCallbacks
+ @inlineCallbacks
def scheduleEventReconciliations(self, txn, groupID, groupGUID):
"""
Find all events who have this groupID as an attendee and create
Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml 2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/accounts/accounts.xml 2013-12-09 23:19:58 UTC (rev 12045)
@@ -122,6 +122,7 @@
<guid>group02</guid>
<password>group02</password>
<name>Group 02</name>
+ <email-address>group02 at example.com</email-address>
<members>
<member type="users">user06</member>
<member type="users">user07</member>
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 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_groups.py 2013-12-09 23:19:58 UTC (rev 12045)
@@ -18,7 +18,7 @@
Group membership caching implementation tests
"""
-from twext.who.groups import GroupCacher, _expandedMembers
+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
@@ -43,20 +43,20 @@
@inlineCallbacks
def test_expandedMembers(self):
"""
- Verify _expandedMembers() returns a "flattened" set of records
+ Verify expandedMembers() returns a "flattened" set of records
belonging to a group (and does not return sub-groups themselves,
only their members)
"""
record = yield self.xmlService.recordWithUID("__top_group_1__")
memberUIDs = set()
- for member in (yield _expandedMembers(record)):
+ for member in (yield expandedMembers(record)):
memberUIDs.add(member.uid)
self.assertEquals(memberUIDs, set(["__cdaboo__",
"__glyph__", "__sagen__", "__wsanchez__"]))
# Non group records return an empty set() of members
record = yield self.xmlService.recordWithUID("__sagen__")
- members = yield _expandedMembers(record)
+ members = yield expandedMembers(record)
self.assertEquals(0, len(list(members)))
@@ -301,24 +301,6 @@
CALSCALE:GREGORIAN
PRODID:-//Example Inc.//Example Calendar//EN
VERSION:2.0
-BEGIN:VTIMEZONE
-LAST-MODIFIED:20040110T032845Z
-TZID:US/Eastern
-BEGIN:DAYLIGHT
-DTSTART:20000404T020000
-RRULE:FREQ=YEARLY;BYDAY=1SU;BYMONTH=4
-TZNAME:EDT
-TZOFFSETFROM:-0500
-TZOFFSETTO:-0400
-END:DAYLIGHT
-BEGIN:STANDARD
-DTSTART:20001026T020000
-RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
-TZNAME:EST
-TZOFFSETFROM:-0400
-TZOFFSETTO:-0500
-END:STANDARD
-END:VTIMEZONE
BEGIN:VEVENT
DTSTAMP:20051222T205953Z
CREATED:20060101T150000Z
@@ -329,7 +311,7 @@
ORGANIZER:MAILTO:user01 at example.com
ATTENDEE:mailto:user01 at example.com
ATTENDEE:mailto:user02 at example.com
-ATTENDEE:MAILTO:group01 at example.com
+ATTENDEE:MAILTO:group02 at example.com
END:VEVENT
END:VCALENDAR"""
@@ -343,7 +325,9 @@
DURATION:PT1H
ATTENDEE;CN=User 01;EMAIL=user01 at example.com;RSVP=TRUE:urn:uuid:user01
ATTENDEE;CN=User 02;EMAIL=user02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:uuid:user02
-ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01 at example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group01
+ATTENDEE;CN=Group 02;CUTYPE=GROUP;EMAIL=group02 at example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:uuid:group02
+ATTENDEE;CN=User 06;EMAIL=user06 at example.com;MEMBER="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: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 1
@@ -358,6 +342,4 @@
cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="user01")
vcalendar = yield cobj.component()
- print("normalize_iCalStr(vcalendar)=%s" % (normalize_iCalStr(vcalendar),))
- print("normalize_iCalStr(data_get)=%s" % (normalize_iCalStr(data_get),))
self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get))
Modified: CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py 2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/twistedcaldav/ical.py 2013-12-09 23:19:58 UTC (rev 12045)
@@ -3355,7 +3355,7 @@
component.normalizeCalendarUserAddresses(lookupFunction, principalFunction, toUUID)
- def expandGroupAttendee(self, groupGUID, individualGUIDs, lookupFunction, principalFunction):
+ def expandGroupAttendee(self, groupGUID, individualGUIDs, principalFunction):
individualUUIDs = set(["urn:uuid:" + individualGUID for individualGUID in individualGUIDs])
groupUUID = "urn:uuid:" + groupGUID
@@ -3369,7 +3369,7 @@
# add new member attendees
for individualUUID in individualUUIDs - oldAttendeeUUIDs:
- directoryRecord = lookupFunction(individualUUID, principalFunction, config)
+ directoryRecord = principalFunction(individualUUID)
newAttendeeProp = directoryRecord.attendee(params={"MEMBER": groupUUID})
component.addProperty(newAttendeeProp)
changed = True
Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py 2013-12-09 22:31:51 UTC (rev 12044)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/caldav/datastore/sql.py 2013-12-09 23:19:58 UTC (rev 12045)
@@ -43,6 +43,7 @@
from twext.python.vcomponent import VComponent
from twext.web2.http_headers import MimeType, generateContentType
from twext.web2.stream import readStream
+from twext.who.groups import expandedMembers
from twisted.internet.defer import inlineCallbacks, returnValue, succeed
from twisted.python import hashlib
@@ -87,7 +88,7 @@
InvalidObjectResourceError, ObjectResourceNameAlreadyExistsError, \
ObjectResourceNameNotAllowedError, TooManyObjectResourcesError, \
InvalidUIDError, UIDExistsError, UIDExistsElsewhereError, \
- InvalidResourceMove, InvalidComponentForStoreError
+ InvalidResourceMove, InvalidComponentForStoreError, AllRetriesFailed
from txdav.idav import ChangeCategory
@@ -1614,28 +1615,38 @@
return
attendeeProps = component.getAllAttendeeProperties()
- groupGUIDs = [
+ groupGUIDs = set([
attendeeProp.value()[len("urn:uuid:"):] for attendeeProp in attendeeProps
if attendeeProp.parameterValue("CUTYPE") == "GROUP"
- ]
+ ])
- # FIXME: need to add event to Group resource ID here
- # need get get members here because they may not be cached yet
+ for groupGUID in groupGUIDs:
- for groupGUID in groupGUIDs:
+ groupRecord = yield self.directoryService().recordWithGUID(groupGUID)
+ 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))
+ membershipHash = membershipHashContent.hexdigest()
+
+ # associate group ID with self
groupID, name, membershipHash = yield self._txn.groupByGUID(groupGUID)
+ try:
+ groupAttendee = schema.GROUP_ATTENDEE
+ yield Insert({
+ groupAttendee.RESOURCE_ID: self._resourceID,
+ groupAttendee.GROUP_ID: groupID,
+ groupAttendee.MEMBERSHIP_HASH: membershipHash,
+ })
+ except AllRetriesFailed:
+ pass
- groupMemember = schema.GROUP_MEMBERSHIP
- rows = yield Select(
- [groupMemember.MEMBER_GUID, ],
- From=groupMemember,
- Where=groupMemember.GROUP_ID == groupID,
- ).on(self._txn)
- individualGUIDs = [row[0] for row in rows]
+ # get members
+ component.expandGroupAttendee(groupGUID, individualGUIDs, self.directoryService().recordWithCalendarUserAddress)
- component.expandGroupAttendee(groupGUID, individualGUIDs, normalizationLookup, self.directoryService().recordWithCalendarUserAddress)
-
def validCalendarDataCheck(self, component, inserting): #@UnusedVariable
"""
Check that the calendar data is valid iCalendar.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/fdf4676d/attachment.html>
More information about the calendarserver-changes
mailing list