[CalendarServer-changes] [11004] CalendarServer/trunk/calendarserver/tools
source_changes at macosforge.org
source_changes at macosforge.org
Fri Apr 5 12:16:26 PDT 2013
Revision: 11004
http://trac.calendarserver.org//changeset/11004
Author: cdaboo at apple.com
Date: 2013-04-05 12:16:26 -0700 (Fri, 05 Apr 2013)
Log Message:
-----------
A couple of extra options added to dark event detection.
Modified Paths:
--------------
CalendarServer/trunk/calendarserver/tools/calverify.py
CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
CalendarServer/trunk/calendarserver/tools/util.py
Modified: CalendarServer/trunk/calendarserver/tools/calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/calverify.py 2013-04-05 18:33:30 UTC (rev 11003)
+++ CalendarServer/trunk/calendarserver/tools/calverify.py 2013-04-05 19:16:26 UTC (rev 11004)
@@ -271,6 +271,19 @@
--summary : report only which GUIDs have double-bookings - no details.
--days : number of days ahead to scan [DEFAULT: 365]
+Options for --dark-purge:
+
+--uuid : only scan specified calendar homes. Can be a partial GUID
+ to scan all GUIDs with that as a prefix or "*" for all GUIDS
+ (that are marked as resources or locations in the directory).
+--summary : report only which GUIDs have double-bookings - no details.
+--no-organizer : only detect events without an organizer
+--invalid-organizer : only detect events with an organizer not in the directory
+--disabled-organizer : only detect events with an organizer disabled for calendaring
+
+If none of (--no-organizer, --invalid-organizer, --disabled-organizer) is present, it
+will default to (--invalid-organizer, --disabled-organizer).
+
CHANGES
v8: Detects ORGANIZER or ATTENDEE properties with mailto: calendar user
addresses for users that have valid directory records. Fix is to
@@ -307,8 +320,12 @@
['details', 'V', "Detailed logging."],
['summary', 'S', "Summary of double-bookings."],
['tzid', 't', "Timezone to adjust displayed times to."],
- ]
+ ['no-organizer', '', "Detect dark events without an organizer"],
+ ['invalid-organizer', '', "Detect dark events with an organizer not in the directory"],
+ ['disabled-organizer', '', "Detect dark events with a disabled organizer"],
+]
+
optParameters = [
['config', 'f', DEFAULT_CONFIG_FILE, "Specify caldavd.plist configuration path."],
['uuid', 'u', "", "Only check this user."],
@@ -2403,6 +2420,9 @@
@inlineCallbacks
def doAction(self):
+ if not self.options["no-organizer"] and not self.options["invalid-organizer"] and not self.options["disabled-organizer"]:
+ self.options["invalid-organizer"] = self.options["disabled-organizer"] = True
+
self.output.write("\n---- Scanning calendar data ----\n")
self.tzid = PyCalendarTimezone(tzid=self.options["tzid"] if self.options["tzid"] else "America/Los_Angeles")
@@ -2557,15 +2577,29 @@
cal = Component(None, pycalendar=caldata)
uid = cal.resourceUID()
+
+ fail = False
organizer = cal.getOrganizer()
- if organizer is not None:
+ if organizer is None:
+ if self.options["no-organizer"]:
+ fail = True
+ else:
principal = self.directoryService().principalForCalendarUserAddress(organizer)
- if principal is None or not principal.calendarsEnabled():
- details.append(Details(resid, uid, organizer,))
- if self.fix:
- yield self.removeEvent(resid)
- fixed += 1
+ if principal is None and organizer.startswith("urn:uuid:"):
+ principal = self.directoryService().principalCollection.principalForUID(organizer[9:])
+ if principal is None:
+ if self.options["invalid-organizer"]:
+ fail = True
+ elif not principal.calendarsEnabled():
+ if self.options["disabled-organizer"]:
+ fail = True
+ if fail:
+ details.append(Details(resid, uid, organizer,))
+ if self.fix:
+ yield self.removeEvent(resid)
+ fixed += 1
+
if self.options["verbose"] and not self.options["summary"]:
if count == 1:
self.output.write("Current".rjust(rjust) + "Total".rjust(rjust) + "Complete".rjust(rjust) + "\n")
Modified: CalendarServer/trunk/calendarserver/tools/test/test_calverify.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/test/test_calverify.py 2013-04-05 18:33:30 UTC (rev 11003)
+++ CalendarServer/trunk/calendarserver/tools/test/test_calverify.py 2013-04-05 19:16:26 UTC (rev 11004)
@@ -2665,6 +2665,9 @@
"uuid": self.uuidl1,
"tzid": "utc",
"start": PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+ "no-organizer": False,
+ "invalid-organizer": False,
+ "disabled-organizer": False,
}
output = StringIO()
calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
@@ -2709,6 +2712,9 @@
"uuid": self.uuidl1,
"tzid": "utc",
"start": PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+ "no-organizer": False,
+ "invalid-organizer": False,
+ "disabled-organizer": False,
}
output = StringIO()
calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
@@ -2737,3 +2743,121 @@
self.assertEqual(len(calverify.results["Dark Events"]), 0)
self.assertTrue("Fix dark events" not in calverify.results)
self.assertTrue("Fix remove" not in calverify.results)
+
+
+ @inlineCallbacks
+ def test_fixDarkEventsNoOrganizerOnly(self):
+ """
+ CalVerifyService.doScan with fix for dark events. Make sure it detects
+ as much as it can. Make sure sync-token is changed.
+ """
+
+ sync_token_oldl1 = (yield (yield self.calendarUnderTest(self.uuidl1)).syncToken())
+ self.commit()
+
+ options = {
+ "ical": False,
+ "badcua": False,
+ "mismatch": False,
+ "nobase64": False,
+ "double": True,
+ "dark-purge": False,
+ "fix": True,
+ "verbose": False,
+ "details": False,
+ "summary": False,
+ "days": 365,
+ "uid": "",
+ "uuid": self.uuidl1,
+ "tzid": "utc",
+ "start": PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+ "no-organizer": True,
+ "invalid-organizer": False,
+ "disabled-organizer": False,
+ }
+ output = StringIO()
+ calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
+ self.assertEqual(
+ sorted([i.uid for i in calverify.results["Dark Events"]]),
+ ["INVITE_NO_ORGANIZER_ICS", ]
+ )
+ self.assertEqual(calverify.results["Number of dark events"], 1)
+ self.assertEqual(calverify.results["Fix dark events"], 1)
+ self.assertTrue("Fix remove" in calverify.results)
+
+ sync_token_newl1 = (yield (yield self.calendarUnderTest(self.uuidl1)).syncToken())
+ self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
+
+ # Re-scan after changes to make sure there are no errors
+ self.commit()
+ options["fix"] = False
+ options["uuid"] = self.uuidl1
+ calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], 3)
+ self.assertEqual(len(calverify.results["Dark Events"]), 0)
+ self.assertTrue("Fix dark events" not in calverify.results)
+ self.assertTrue("Fix remove" not in calverify.results)
+
+
+ @inlineCallbacks
+ def test_fixDarkEventsAllTypes(self):
+ """
+ CalVerifyService.doScan with fix for dark events. Make sure it detects
+ as much as it can. Make sure sync-token is changed.
+ """
+
+ sync_token_oldl1 = (yield (yield self.calendarUnderTest(self.uuidl1)).syncToken())
+ self.commit()
+
+ options = {
+ "ical": False,
+ "badcua": False,
+ "mismatch": False,
+ "nobase64": False,
+ "double": True,
+ "dark-purge": False,
+ "fix": True,
+ "verbose": False,
+ "details": False,
+ "summary": False,
+ "days": 365,
+ "uid": "",
+ "uuid": self.uuidl1,
+ "tzid": "utc",
+ "start": PyCalendarDateTime(nowYear, 1, 1, 0, 0, 0),
+ "no-organizer": True,
+ "invalid-organizer": True,
+ "disabled-organizer": True,
+ }
+ output = StringIO()
+ calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], len(self.requirements[CalVerifyMismatchTestsBase.uuidl1]["calendar"]))
+ self.assertEqual(
+ sorted([i.uid for i in calverify.results["Dark Events"]]),
+ ["INVITE_INVALID_ORGANIZER_1_ICS", "INVITE_INVALID_ORGANIZER_2_ICS", "INVITE_NO_ORGANIZER_ICS", ]
+ )
+ self.assertEqual(calverify.results["Number of dark events"], 3)
+ self.assertEqual(calverify.results["Fix dark events"], 3)
+ self.assertTrue("Fix remove" in calverify.results)
+
+ sync_token_newl1 = (yield (yield self.calendarUnderTest(self.uuidl1)).syncToken())
+ self.assertNotEqual(sync_token_oldl1, sync_token_newl1)
+
+ # Re-scan after changes to make sure there are no errors
+ self.commit()
+ options["fix"] = False
+ options["uuid"] = self.uuidl1
+ calverify = DarkPurgeService(self._sqlCalendarStore, options, output, reactor, config)
+ yield calverify.doAction()
+
+ self.assertEqual(calverify.results["Number of events to process"], 1)
+ self.assertEqual(len(calverify.results["Dark Events"]), 0)
+ self.assertTrue("Fix dark events" not in calverify.results)
+ self.assertTrue("Fix remove" not in calverify.results)
Modified: CalendarServer/trunk/calendarserver/tools/util.py
===================================================================
--- CalendarServer/trunk/calendarserver/tools/util.py 2013-04-05 18:33:30 UTC (rev 11003)
+++ CalendarServer/trunk/calendarserver/tools/util.py 2013-04-05 19:16:26 UTC (rev 11004)
@@ -133,8 +133,8 @@
return principal.calendarHome()
return None
- def principalForCalendarUserAddress(self, cua):
- return self.principalCollection.principalForCalendarUserAddress(cua)
+ def principalForUID(self, uid):
+ return self.principalCollection.principalForUID(uid)
# Load augment/proxy db classes now
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130405/e0dc2e63/attachment-0001.html>
More information about the calendarserver-changes
mailing list