<!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>[12912] CalendarServer/branches/users/sagen/move2who-3</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/12912">12912</a></dd>
<dt>Author</dt> <dd>sagen@apple.com</dd>
<dt>Date</dt> <dd>2014-03-14 12:03:57 -0700 (Fri, 14 Mar 2014)</dd>
</dl>

<h3>Log Message</h3>
<pre>Remove the last of the legacy record type pluralized name hacks, and use a mapping instead.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServerbranchesuserssagenmove2who3twistedcaldavdirectorycalendaruserproxypy">CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/calendaruserproxy.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who3twistedcaldavdirectoryprincipalpy">CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/principal.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who3twistedcaldavextensionspy">CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/extensions.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who3txdavdpsserverpy">CalendarServer/branches/users/sagen/move2who-3/txdav/dps/server.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who3txdavwhoaugmentpy">CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who3txdavwhodirectorypy">CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py</a></li>
<li><a href="#CalendarServerbranchesuserssagenmove2who3txdavwhotesttest_utilpy">CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServerbranchesuserssagenmove2who3twistedcaldavdirectorycalendaruserproxypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/calendaruserproxy.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/calendaruserproxy.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/calendaruserproxy.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -134,7 +134,7 @@
</span><span class="cx">             directoryGUID=record.service.guid,
</span><span class="cx">             realm=record.service.realmName,
</span><span class="cx">             guid=guid,
</span><del>-            recordType=record.recordType.name + &quot;s&quot;,  # MOVE2WHO need mapping
</del><ins>+            recordType=record.service.recordTypeToOldName(record.recordType),
</ins><span class="cx">             shortNames=record.shortNames,
</span><span class="cx">             fullName=record.displayName,
</span><span class="cx">             principalUID=parent.principalUID(),
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who3twistedcaldavdirectoryprincipalpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/principal.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/principal.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/principal.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -402,8 +402,10 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def listChildren(self):
</span><del>-        # MOVE2WHO hack
-        return [r.name + &quot;s&quot; for r in self.directory.recordTypes()]
</del><ins>+        return [
+            self.directory.recordTypeToOldName(r)
+            for r in self.directory.recordTypes()
+        ]
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     ##
</span><span class="lines">@@ -652,7 +654,7 @@
</span><span class="cx">             directoryGUID=str(record.service.guid),
</span><span class="cx">             realm=str(record.service.realmName),
</span><span class="cx">             principalGUID=guid,
</span><del>-            recordType=record.recordType.name + &quot;s&quot;,  # MOVE2WHO need mapping
</del><ins>+            recordType=record.service.recordTypeToOldName(record.recordType),
</ins><span class="cx">             shortNames=&quot;,&quot;.join(record.shortNames),
</span><span class="cx">             # MOVE2WHO: need this?
</span><span class="cx">             # securityIDs=&quot;,&quot;.join(record.authIDs),
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who3twistedcaldavextensionspy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/extensions.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/extensions.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/extensions.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -729,8 +729,13 @@
</span><span class="cx"> 
</span><span class="cx">             elif name == &quot;record-type&quot;:
</span><span class="cx">                 if hasattr(self, &quot;record&quot;):
</span><del>-                    # MOVE2WHO -- need mapping
-                    returnValue(customxml.RecordType(self.record.recordType.name + &quot;s&quot;))
</del><ins>+                    returnValue(
+                        customxml.RecordType(
+                            self.record.service.recordTypeToOldName(
+                                self.record.recordType
+                            )
+                        )
+                    )
</ins><span class="cx">                 else:
</span><span class="cx">                     raise HTTPError(StatusResponse(
</span><span class="cx">                         responsecode.NOT_FOUND,
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who3txdavdpsserverpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/dps/server.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/txdav/dps/server.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/txdav/dps/server.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -137,7 +137,7 @@
</span><span class="cx">         recordType = recordType  # as bytes
</span><span class="cx">         log.debug(&quot;RecordsWithRecordType: {r}&quot;, r=recordType)
</span><span class="cx">         records = (yield self._directory.recordsWithRecordType(
</span><del>-            RecordType.lookupByName(recordType))
</del><ins>+            self._directory.recordType.lookupByName(recordType))
</ins><span class="cx">         )
</span><span class="cx">         fieldsList = []
</span><span class="cx">         for record in records:
</span><span class="lines">@@ -196,7 +196,7 @@
</span><span class="cx">             newFields.append((fieldName, searchTerm, matchFlags, matchType))
</span><span class="cx">         operand = Operand.lookupByName(operand)
</span><span class="cx">         if recordType:
</span><del>-            recordType = RecordType.lookupByName(recordType)
</del><ins>+            recordType = self._directory.recordType.lookupByName(recordType)
</ins><span class="cx">         records = yield self._directory.recordsMatchingFields(
</span><span class="cx">             newFields, operand=operand, recordType=recordType
</span><span class="cx">         )
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who3txdavwhoaugmentpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -215,12 +215,10 @@
</span><span class="cx">         if record is None:
</span><span class="cx">             returnValue(None)
</span><span class="cx"> 
</span><del>-        # MOVE2WHO
-        # FIXME: hacked by appending an &quot;s&quot; -- need a mapping
</del><span class="cx">         try:
</span><span class="cx">             augmentRecord = yield self._augmentDB.getAugmentRecord(
</span><span class="cx">                 record.uid,
</span><del>-                record.recordType.name + &quot;s&quot;
</del><ins>+                self.recordTypeToOldName(record.recordType)
</ins><span class="cx">             )
</span><span class="cx">         except KeyError:
</span><span class="cx">             # Augments does not know about this record type, so return
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who3txdavwhodirectorypy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -146,15 +146,29 @@
</span><span class="cx">         return self.recordsFromExpression(expression)
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    _oldRecordTypeNames = {
+        &quot;address&quot;: &quot;addresses&quot;,
+        &quot;group&quot;: &quot;groups&quot;,
+        &quot;location&quot;: &quot;locations&quot;,
+        &quot;resource&quot;: &quot;resources&quot;,
+        &quot;user&quot;: &quot;users&quot;,
+        &quot;readDelegateGroup&quot;: &quot;readDelegateGroups&quot;,
+        &quot;writeDelegateGroup&quot;: &quot;writeDelegateGroups&quot;,
+        &quot;readDelegatorGroup&quot;: &quot;readDelegatorGroups&quot;,
+        &quot;writeDelegatorGroup&quot;: &quot;writeDelegatorGroups&quot;,
+    }
+
</ins><span class="cx">     # FIXME: Existing code assumes record type names are plural. Is there any
</span><span class="cx">     # reason to maintain backwards compatibility?  I suppose there could be
</span><span class="cx">     # scripts referring to record type of &quot;users&quot;, &quot;locations&quot;
</span><span class="cx">     def recordTypeToOldName(self, recordType):
</span><del>-        return recordType.name + u&quot;s&quot;
</del><ins>+        return self._oldRecordTypeNames[recordType.name]
</ins><span class="cx"> 
</span><del>-
</del><span class="cx">     def oldNameToRecordType(self, oldName):
</span><del>-        return self.recordType.lookupByName(oldName[:-1])
</del><ins>+        for name, value in self._oldRecordTypeNames.iteritems():
+            if oldName == value:
+                return self.recordType.lookupByName(name)
+        return None
</ins><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="lines">@@ -217,7 +231,8 @@
</span><span class="cx">         cuas.add(&quot;/principals/__uids__/{uid}/&quot;.format(uid=self.uid))
</span><span class="cx">         for shortName in self.shortNames:
</span><span class="cx">             cuas.add(&quot;/principals/{rt}/{sn}/&quot;.format(
</span><del>-                rt=self.recordType.name + &quot;s&quot;, sn=shortName)
</del><ins>+                rt=self.service.recordTypeToOldName(self.recordType),
+                sn=shortName)
</ins><span class="cx">             )
</span><span class="cx">         return frozenset(cuas)
</span><span class="cx"> 
</span></span></pre></div>
<a id="CalendarServerbranchesuserssagenmove2who3txdavwhotesttest_utilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py (12911 => 12912)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py        2014-03-14 17:58:21 UTC (rev 12911)
+++ CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py        2014-03-14 19:03:57 UTC (rev 12912)
</span><span class="lines">@@ -21,6 +21,7 @@
</span><span class="cx"> import os
</span><span class="cx"> 
</span><span class="cx"> from txdav.who.util import directoryFromConfig
</span><ins>+from twisted.internet.defer import inlineCallbacks
</ins><span class="cx"> from twisted.trial.unittest import TestCase
</span><span class="cx"> from twistedcaldav.config import ConfigDict
</span><span class="cx"> from twisted.python.filepath import FilePath
</span><span class="lines">@@ -64,6 +65,7 @@
</span><span class="cx">         augments.setContent(sourceAugments.getContent())
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @inlineCallbacks
</ins><span class="cx">     def test_directoryFromConfig(self):
</span><span class="cx"> 
</span><span class="cx">         config = ConfigDict(
</span><span class="lines">@@ -82,7 +84,7 @@
</span><span class="cx">                     &quot;type&quot;: &quot;XML&quot;,
</span><span class="cx">                     &quot;params&quot;: {
</span><span class="cx">                         &quot;xmlFile&quot;: &quot;resources.xml&quot;,
</span><del>-                        &quot;recordTypes&quot;: [&quot;locations&quot;, &quot;resources&quot;],
</del><ins>+                        &quot;recordTypes&quot;: [&quot;locations&quot;, &quot;resources&quot;, &quot;addresses&quot;],
</ins><span class="cx">                     },
</span><span class="cx">                 },
</span><span class="cx">                 &quot;AugmentService&quot;: {
</span><span class="lines">@@ -115,7 +117,13 @@
</span><span class="cx">         )
</span><span class="cx">         self.assertEquals(
</span><span class="cx">             set(service._directory.services[1].recordTypes()),
</span><del>-            set([CalRecordType.location, CalRecordType.resource])
</del><ins>+            set(
+                [
+                    CalRecordType.location,
+                    CalRecordType.resource,
+                    CalRecordType.address
+                ]
+            )
</ins><span class="cx">         )
</span><span class="cx">         self.assertTrue(
</span><span class="cx">             isinstance(service._directory.services[2], DelegateDirectoryService)
</span><span class="lines">@@ -131,3 +139,7 @@
</span><span class="cx">                 ]
</span><span class="cx">             )
</span><span class="cx">         )
</span><ins>+
+        # And make sure it's functional:
+        record = yield service.recordWithUID(&quot;group07&quot;)
+        self.assertEquals(record.fullNames, [u'Group 07'])
</ins></span></pre>
</div>
</div>

</body>
</html>