<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[13512] CalendarServer/trunk</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/13512">13512</a></dd>
<dt>Author</dt> <dd>gaya@apple.com</dd>
<dt>Date</dt> <dd>2014-05-19 20:39:30 -0700 (Mon, 19 May 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Remove GROUP_ATTENDDEE rows for old events</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktxdavcaldavdatastoresqlpy">CalendarServer/trunk/txdav/caldav/datastore/sql.py</a></li>
<li><a href="#CalendarServertrunktxdavwhotesttest_group_attendeespy">CalendarServer/trunk/txdav/who/test/test_group_attendees.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (13511 => 13512)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/stdconfig.py        2014-05-20 01:09:59 UTC (rev 13511)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py        2014-05-20 03:39:30 UTC (rev 13512)
</span><span class="lines">@@ -1041,6 +1041,7 @@
</span><span class="cx"> "GroupAttendees" : {
</span><span class="cx"> "Enabled": False,
</span><span class="cx"> "ReconciliationDelaySeconds" : 5,
</span><ins>+ "UpdateOldEventLimitSeconds" : 1 * 24 * 60 * 60, # 1 day
</ins><span class="cx"> },
</span><span class="cx">
</span><span class="cx"> "AutomaticPurging": {
</span></span></pre></div>
<a id="CalendarServertrunktxdavcaldavdatastoresqlpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/caldav/datastore/sql.py (13511 => 13512)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-05-20 01:09:59 UTC (rev 13511)
+++ CalendarServer/trunk/txdav/caldav/datastore/sql.py        2014-05-20 03:39:30 UTC (rev 13512)
</span><span class="lines">@@ -1964,8 +1964,7 @@
</span><span class="cx"> changed = component.reconcileGroupAttendees(groupCUAToAttendeeMemberPropMap)
</span><span class="cx">
</span><span class="cx"> # save for post processing when self._resourceID is non-zero
</span><del>- if inserting and groupCUAToAttendeeMemberPropMap:
- self._groupCUAToAttendeeMemberPropMap = groupCUAToAttendeeMemberPropMap
</del><ins>+ self._groupCUAToAttendeeMemberPropMap = groupCUAToAttendeeMemberPropMap
</ins><span class="cx">
</span><span class="cx"> returnValue(changed)
</span><span class="cx">
</span><span class="lines">@@ -2037,17 +2036,50 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><del>- def deleteGROUP_ATTENDEE(self, groupCUAToAttendeeMemberPropMap=None):
- """
- delete groupp attendee rows for this resource
- """
- ga = schema.GROUP_ATTENDEE
- rows = yield Delete(
- From=ga,
- Where=ga.RESOURCE_ID == self._resourceID,
- Return=[ga.GROUP_ID]
- ).on(self._txn)
- returnValue(bool(rows))
</del><ins>+ def deleteOldGROUP_ATTENDEE(self, component, instances, inserting, txn):
+
+ # If this event is old, break possible tie to group update
+ if hasattr(self, "_groupCUAToAttendeeMemberPropMap"):
+
+ if (component.masterComponent() is None or not component.isRecurring()):
+ cutoffDate_datatime = (
+ datetime.datetime.utcnow() +
+ datetime.timedelta(seconds=config.GroupAttendees.UpdateOldEventLimitSeconds)
+ )
+ tr = schema.TIME_RANGE
+ rows = yield Select(
+ [Count(tr.CALENDAR_OBJECT_RESOURCE_ID)],
+ From=tr,
+ Where=(
+ tr.CALENDAR_OBJECT_RESOURCE_ID == self._resourceID).And(
+ tr.END_DATE > cutoffDate_datatime
+ ),
+ ).on(txn)
+ isOld = rows[0][0] == 0
+
+ else:
+ if instances:
+ cutoffDate_DateTime = (
+ DateTime.getNowUTC() +
+ Duration(seconds=config.GroupAttendees.UpdateOldEventLimitSeconds)
+ )
+ maxInstanceKey = sorted(instance for instance in instances)[-1]
+ isOld = cutoffDate_DateTime > instances[maxInstanceKey].end
+ else:
+ isOld = True
+
+ if isOld:
+ if inserting:
+ # don't create GROUP_ATTENDEE rows in updateGROUP_ATTENDEE()
+ del self._groupCUAToAttendeeMemberPropMap
+ else:
+ # delete existing group rows
+ ga = schema.GROUP_ATTENDEE
+ rows = yield Delete(
+ From=ga,
+ Where=ga.RESOURCE_ID == self._resourceID,
+ #Return=[ga.GROUP_ID]
+ ).on(txn)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> def validCalendarDataCheck(self, component, inserting):
</span><span class="lines">@@ -2742,7 +2774,8 @@
</span><span class="cx"> yield self.updateDatabase(component, inserting=inserting)
</span><span class="cx">
</span><span class="cx"> # update GROUP_ATTENDEE table rows
</span><del>- yield self.updateGROUP_ATTENDEE()
</del><ins>+ if inserting:
+ yield self.updateGROUP_ATTENDEE()
</ins><span class="cx">
</span><span class="cx"> # Post process managed attachments
</span><span class="cx"> if internal_state in (
</span><span class="lines">@@ -2806,6 +2839,7 @@
</span><span class="cx"> # freebusy related properties have changed (e.g. an attendee reply and refresh). In those cases
</span><span class="cx"> # the component will have a special attribute present to let us know to suppress the instance indexing.
</span><span class="cx"> instanceIndexingRequired = not getattr(component, "noInstanceIndexing", False) or inserting or reCreate
</span><ins>+ instances = None
</ins><span class="cx">
</span><span class="cx"> if instanceIndexingRequired:
</span><span class="cx">
</span><span class="lines">@@ -2879,7 +2913,7 @@
</span><span class="cx">
</span><span class="cx"> # Now coerce indexing to off if needed
</span><span class="cx"> if not doInstanceIndexing:
</span><del>- instances = None
</del><ins>+ #instances = None # used by deleteOldGROUP_ATTENDEE() call at end
</ins><span class="cx"> recurrenceLowerLimit = None
</span><span class="cx"> recurrenceLimit = DateTime(1900, 1, 1, 0, 0, 0, tzid=Timezone(utc=True))
</span><span class="cx">
</span><span class="lines">@@ -2988,6 +3022,8 @@
</span><span class="cx">
</span><span class="cx"> if instanceIndexingRequired and doInstanceIndexing:
</span><span class="cx"> yield self._addInstances(component, instances, truncateLowerLimit, isInboxItem, txn)
</span><ins>+
+ yield self.deleteOldGROUP_ATTENDEE(component, instances, inserting, txn)
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span></span></pre></div>
<a id="CalendarServertrunktxdavwhotesttest_group_attendeespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/who/test/test_group_attendees.py (13511 => 13512)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-05-20 01:09:59 UTC (rev 13511)
+++ CalendarServer/trunk/txdav/who/test/test_group_attendees.py        2014-05-20 03:39:30 UTC (rev 13512)
</span><span class="lines">@@ -58,6 +58,7 @@
</span><span class="cx"> super(GroupAttendeeReconciliation, self).configure()
</span><span class="cx"> config.GroupAttendees.Enabled = True
</span><span class="cx"> config.GroupAttendees.ReconciliationDelaySeconds = 0
</span><ins>+ config.GroupAttendees.UpdateOldEventLimitSeconds = 0
</ins><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -670,6 +671,64 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><ins>+ def test_groupPutOldEvent(self):
+ """
+ Test that old event with group attendee is expaned but not linked to group update
+ """
+
+ 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@ninevah.local
+ORGANIZER:MAILTO:user02@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:MAILTO:group01@example.com
+END:VEVENT
+END:VCALENDAR"""
+
+ data_get_1 = """BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+BEGIN:VEVENT
+UID:event1@ninevah.local
+DTSTART;TZID=US/Eastern:20140101T100000
+DURATION:PT1H
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000001
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;MEMBER="urn:x-uid:20000000-0000-0000-0000-000000000001";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000001
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 02;EMAIL=user02@example.com:urn:x-uid:10000000-0000-0000-0000-000000000002
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+"""
+ groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+
+ calendar = yield self.calendarUnderTest(name="calendar", home="10000000-0000-0000-0000-000000000002")
+ vcalendar = Component.fromString(data_put_1)
+ yield calendar.createCalendarObjectWithName("data1.ics", vcalendar)
+ yield self.commit()
+
+ wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), "20000000-0000-0000-0000-000000000001")
+ if len(wps): # This is needed because the test currently fails and does actually create job items we have to wait for
+ yield self.commit()
+ yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+ self.assertEqual(len(wps), 0)
+
+ cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="10000000-0000-0000-0000-000000000002")
+ vcalendar = yield cobj.component()
+ self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_1))
+
+
+ @inlineCallbacks
</ins><span class="cx"> def test_groupChangeOldEvent(self):
</span><span class="cx"> """
</span><span class="cx"> Test that group attendee changes not applied to old events
</span><span class="lines">@@ -784,10 +843,139 @@
</span><span class="cx"> yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
</span><span class="cx"> self.assertEqual(len(wps), 0)
</span><span class="cx">
</span><del>- test_groupChangeOldEvent.todo = "Doesn't work yet"
</del><span class="cx">
</span><ins>+ @inlineCallbacks
+ def test_groupChangeOldNoMasterEvent(self):
+ """
+ Test that group attendee changes not applied to old events with no master event
+ """
+ yield None
</ins><span class="cx">
</span><ins>+ test_groupChangeOldNoMasterEvent.todo = "Create test data"
+
+
</ins><span class="cx"> @inlineCallbacks
</span><ins>+ def test_groupChangeOldRecurringEvent(self):
+ """
+ Test that group attendee changes not applied to old recurring events
+ """
+
+ 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:20120101T100000
+DURATION:PT1H
+RRULE:FREQ=DAILY;UNTIL=20240101T100000
+SUMMARY:event 1
+UID:event1@ninevah.local
+ORGANIZER:MAILTO:user02@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:MAILTO:group01@example.com
+END:VEVENT
+END:VCALENDAR"""
+
+ data_put_2 = """BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+VERSION:2.0
+BEGIN:VEVENT
+DTSTAMP:20051222T205953Z
+CREATED:20060101T150000Z
+DTSTART;TZID=US/Eastern:20120101T100000
+DURATION:PT1H
+RRULE:FREQ=DAILY;UNTIL=20140101T100000
+SUMMARY:event 1
+UID:event1@ninevah.local
+ORGANIZER:MAILTO:user02@example.com
+ATTENDEE:mailto:user02@example.com
+ATTENDEE:MAILTO:group01@example.com
+END:VEVENT
+END:VCALENDAR"""
+
+ data_get_1 = """BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+BEGIN:VEVENT
+UID:event1@ninevah.local
+DTSTART;TZID=US/Eastern:20120101T100000
+DURATION:PT1H
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000001
+ATTENDEE;CN=User 01;EMAIL=user01@example.com;MEMBER="urn:x-uid:20000000-0000-0000-0000-000000000001";PARTSTAT=NEEDS-ACTION;RSVP=TRUE;SCHEDULE-STATUS=1.2:urn:x-uid:10000000-0000-0000-0000-000000000001
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 02;EMAIL=user02@example.com:urn:x-uid:10000000-0000-0000-0000-000000000002
+RRULE:FREQ=DAILY;UNTIL=20240101T100000
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ data_get_2 = """BEGIN:VCALENDAR
+VERSION:2.0
+CALSCALE:GREGORIAN
+PRODID:-//Example Inc.//Example Calendar//EN
+BEGIN:VEVENT
+UID:event1@ninevah.local
+DTSTART;TZID=US/Eastern:20120101T100000
+DURATION:PT1H
+ATTENDEE;CN=User 02;EMAIL=user02@example.com;RSVP=TRUE:urn:x-uid:10000000-0000-0000-0000-000000000002
+ATTENDEE;CN=Group 01;CUTYPE=GROUP;EMAIL=group01@example.com;RSVP=TRUE;SCHEDULE-STATUS=3.7:urn:x-uid:20000000-0000-0000-0000-000000000001
+CREATED:20060101T150000Z
+ORGANIZER;CN=User 02;EMAIL=user02@example.com:urn:x-uid:10000000-0000-0000-0000-000000000002
+RRULE:FREQ=DAILY;UNTIL=20140101T100000
+SEQUENCE:1
+SUMMARY:event 1
+END:VEVENT
+END:VCALENDAR
+"""
+
+ @inlineCallbacks
+ def expandedMembers(self, records=None):
+ yield None
+ returnValue(set())
+
+ groupCacher = GroupCacher(self.transactionUnderTest().directoryService())
+
+ calendar = yield self.calendarUnderTest(name="calendar", home="10000000-0000-0000-0000-000000000002")
+ vcalendar = Component.fromString(data_put_1)
+ yield calendar.createCalendarObjectWithName("data1.ics", vcalendar)
+ yield self.commit()
+
+ wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), "20000000-0000-0000-0000-000000000001")
+ yield self.commit()
+ self.assertEqual(len(wps), 1)
+ yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+
+ cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="10000000-0000-0000-0000-000000000002")
+ vcalendar = yield cobj.component()
+ self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_1))
+
+ yield self._verifyObjectResourceCount("10000000-0000-0000-0000-000000000001", 1)
+
+ vcalendar = Component.fromString(data_put_2)
+ yield cobj.setComponent(vcalendar)
+ yield self.commit()
+
+ self.patch(CalendarDirectoryRecordMixin, "expandedMembers", expandedMembers)
+
+ cobj = yield self.calendarObjectUnderTest(name="data1.ics", calendar_name="calendar", home="10000000-0000-0000-0000-000000000002")
+ vcalendar = yield cobj.component()
+ self.assertEqual(normalize_iCalStr(vcalendar), normalize_iCalStr(data_get_2))
+
+ wps = yield groupCacher.refreshGroup(self.transactionUnderTest(), "20000000-0000-0000-0000-000000000001")
+ if len(wps): # This is needed because the test currently fails and does actually create job items we have to wait for
+ yield self.commit()
+ yield JobItem.waitEmpty(self._sqlCalendarStore.newTransaction, reactor, 60)
+ self.assertEqual(len(wps), 0)
+
+
+
+ @inlineCallbacks
</ins><span class="cx"> def test_groupRemovalFromDirectory(self):
</span><span class="cx"> """
</span><span class="cx"> Test that removing a group from the directory also removes the expanded attendees.
</span></span></pre>
</div>
</div>
</body>
</html>