<!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>[13009] CalendarServer/branches/users/sagen/move2who-4/txdav</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/13009">13009</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-03-26 20:38:48 -0700 (Wed, 26 Mar 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Make canonicalCalendarUserAddress less random, more canonical.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingitippy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingschedulerpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretestutilpy">CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhodirectorypy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_directorypy">CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingitippy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py (13008 => 13009)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py        2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/itip.py        2014-03-27 03:38:48 UTC (rev 13009)
</span><span class="lines">@@ -951,6 +951,8 @@
</span><span class="cx"> @staticmethod
</span><span class="cx"> def generateAttendeeReply(original, attendee, changedRids=None, force_decline=False):
</span><span class="cx">
</span><ins>+ print("XYZZY generateAttendeeReply", original, attendee)
+
</ins><span class="cx"> # Start with a copy of the original as we may have to modify bits of it
</span><span class="cx"> itip = original.duplicate()
</span><span class="cx"> itip.replaceProperty(Property("PRODID", iCalendarProductID))
</span><span class="lines">@@ -970,6 +972,7 @@
</span><span class="cx"> if component.name() in ignoredComponents:
</span><span class="cx"> continue
</span><span class="cx"> if not component.getAttendeeProperty((attendee,)):
</span><ins>+ print("XYZZY removing componeont", component, attendee)
</ins><span class="cx"> itip.removeComponent(component)
</span><span class="cx">
</span><span class="cx"> # No alarms
</span><span class="lines">@@ -1015,6 +1018,7 @@
</span><span class="cx"> if component.name() == "VPOLL":
</span><span class="cx"> iTipGenerator.generateVPOLLReply(component, attendee)
</span><span class="cx">
</span><ins>+ print("XYZZY AFTER", itip)
</ins><span class="cx"> return itip
</span><span class="cx">
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoreschedulingschedulerpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py (13008 => 13009)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py        2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/scheduling/scheduler.py        2014-03-27 03:38:48 UTC (rev 13009)
</span><span class="lines">@@ -322,7 +322,7 @@
</span><span class="cx">
</span><span class="cx"> # FIXME, how can this be None?
</span><span class="cx"> if attendees is None:
</span><del>- print("Attendees is None", self.calendar)
</del><ins>+ print("XYZZY Attendees is None", self.calendar)
</ins><span class="cx">
</span><span class="cx"> # Must have only one
</span><span class="cx"> if len(attendees) != 1:
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavcaldavdatastoretestutilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py (13008 => 13009)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py        2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/caldav/datastore/test/util.py        2014-03-27 03:38:48 UTC (rev 13009)
</span><span class="lines">@@ -72,21 +72,29 @@
</span><span class="cx">
</span><span class="cx">
</span><span class="cx"> def canonicalCalendarUserAddress(self):
</span><del>- cua = ""
- for candidate in self.calendarUserAddresses:
- # Pick the first one, but urn:uuid: and mailto: can override
- if not cua:
- cua = candidate
- # But always immediately choose the urn:uuid: form
- if candidate.startswith("urn:uuid:"):
- cua = candidate
- break
- # Prefer mailto: if no urn:uuid:
- elif candidate.startswith("mailto:"):
- cua = candidate
- return cua
</del><ins>+ """
+ Return a CUA for this record, preferring in this order:
+ urn:uuid: form
+ mailto: form
+ /principals/__uids__/ form
+ first in calendarUserAddresses list (sorted)
+ """
</ins><span class="cx">
</span><ins>+ sortedCuas = sorted(self.calendarUserAddresses)
</ins><span class="cx">
</span><ins>+ for prefix in (
+ "urn:uuid:",
+ "mailto:",
+ "/principals/__uids__/"
+ ):
+ for candidate in sortedCuas:
+ if candidate.startswith(prefix):
+ return candidate
+
+ # fall back to using the first one
+ return sortedCuas[0]
+
+
</ins><span class="cx"> def calendarsEnabled(self):
</span><span class="cx"> return True
</span><span class="cx">
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhodirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py (13008 => 13009)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py        2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/directory.py        2014-03-27 03:38:48 UTC (rev 13009)
</span><span class="lines">@@ -231,8 +231,11 @@
</span><span class="cx">
</span><span class="cx"> @property
</span><span class="cx"> def calendarUserAddresses(self):
</span><del>- if not self.hasCalendars:
- return frozenset()
</del><ins>+ try:
+ if not self.hasCalendars:
+ return frozenset()
+ except AttributeError:
+ pass
</ins><span class="cx">
</span><span class="cx"> try:
</span><span class="cx"> cuas = set(
</span><span class="lines">@@ -325,24 +328,25 @@
</span><span class="cx"> Return a CUA for this record, preferring in this order:
</span><span class="cx"> urn:uuid: form
</span><span class="cx"> mailto: form
</span><del>- first in calendarUserAddresses list
</del><ins>+ /principals/__uids__/ form
+ first in calendarUserAddresses list (sorted)
</ins><span class="cx"> """
</span><span class="cx">
</span><del>- cua = ""
- for candidate in self.calendarUserAddresses:
- # Pick the first one, but urn:uuid: and mailto: can override
- if not cua:
- cua = candidate
- # But always immediately choose the urn:uuid: form
- if candidate.startswith("urn:uuid:"):
- cua = candidate
- break
- # Prefer mailto: if no urn:uuid:
- elif candidate.startswith("mailto:"):
- cua = candidate
- return cua
</del><ins>+ sortedCuas = sorted(self.calendarUserAddresses)
</ins><span class="cx">
</span><ins>+ for prefix in (
+ "urn:uuid:",
+ "mailto:",
+ "/principals/__uids__/"
+ ):
+ for candidate in sortedCuas:
+ if candidate.startswith(prefix):
+ return candidate
</ins><span class="cx">
</span><ins>+ # fall back to using the first one
+ return sortedCuas[0]
+
+
</ins><span class="cx"> def enabledAsOrganizer(self):
</span><span class="cx"> # FIXME:
</span><span class="cx"> from twistedcaldav.config import config
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who4txdavwhotesttest_directorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py (13008 => 13009)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py        2014-03-27 03:36:29 UTC (rev 13008)
+++ CalendarServer/branches/users/sagen/move2who-4/txdav/who/test/test_directory.py        2014-03-27 03:38:48 UTC (rev 13009)
</span><span class="lines">@@ -20,8 +20,17 @@
</span><span class="cx">
</span><span class="cx"> from twisted.internet.defer import inlineCallbacks
</span><span class="cx"> from twistedcaldav.test.util import StoreTestCase
</span><ins>+from twext.who.directory import DirectoryRecord
+from twext.who.idirectory import FieldName, RecordType
+from txdav.who.directory import CalendarDirectoryRecordMixin
+from uuid import UUID
</ins><span class="cx">
</span><span class="cx">
</span><ins>+
+class TestDirectoryRecord(DirectoryRecord, CalendarDirectoryRecordMixin):
+ pass
+
+
</ins><span class="cx"> class DirectoryTestCase(StoreTestCase):
</span><span class="cx">
</span><span class="cx"> @inlineCallbacks
</span><span class="lines">@@ -40,3 +49,50 @@
</span><span class="cx"> set([u"Chris Lecroy", u"Cyrus Daboo", u"David Reid", u"Wilfredo Sanchez"]),
</span><span class="cx"> set([r.displayName for r in expanded])
</span><span class="cx"> )
</span><ins>+
+
+ def test_canonicalCalendarUserAddress(self):
+
+ record = TestDirectoryRecord(
+ self.directory,
+ {
+ FieldName.uid: u"uid",
+ FieldName.shortNames: [u"name"],
+ FieldName.recordType: RecordType.user,
+ }
+ )
+ self.assertEquals(
+ record.canonicalCalendarUserAddress(),
+ u"/principals/__uids__/uid/"
+ )
+
+
+ record = TestDirectoryRecord(
+ self.directory,
+ {
+ FieldName.uid: u"uid",
+ FieldName.shortNames: [u"name"],
+ FieldName.emailAddresses: [u"test@example.com"],
+ FieldName.recordType: RecordType.user,
+ }
+ )
+ self.assertEquals(
+ record.canonicalCalendarUserAddress(),
+ u"mailto:test@example.com"
+ )
+
+
+ record = TestDirectoryRecord(
+ self.directory,
+ {
+ FieldName.uid: u"uid",
+ FieldName.guid: UUID("E2F6C57F-BB15-4EF9-B0AC-47A7578386F1"),
+ FieldName.shortNames: [u"name"],
+ FieldName.emailAddresses: [u"test@example.com"],
+ FieldName.recordType: RecordType.user,
+ }
+ )
+ self.assertEquals(
+ record.canonicalCalendarUserAddress(),
+ u"urn:uuid:E2F6C57F-BB15-4EF9-B0AC-47A7578386F1"
+ )
</ins></span></pre>
</div>
</div>
</body>
</html>