[CalendarServer-changes] [12912] CalendarServer/branches/users/sagen/move2who-3
source_changes at macosforge.org
source_changes at macosforge.org
Fri Mar 14 12:03:58 PDT 2014
Revision: 12912
http://trac.calendarserver.org//changeset/12912
Author: sagen at apple.com
Date: 2014-03-14 12:03:57 -0700 (Fri, 14 Mar 2014)
Log Message:
-----------
Remove the last of the legacy record type pluralized name hacks, and use a mapping instead.
Modified Paths:
--------------
CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/calendaruserproxy.py
CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/principal.py
CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/extensions.py
CalendarServer/branches/users/sagen/move2who-3/txdav/dps/server.py
CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py
CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py
CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py
Modified: CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- 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)
@@ -134,7 +134,7 @@
directoryGUID=record.service.guid,
realm=record.service.realmName,
guid=guid,
- recordType=record.recordType.name + "s", # MOVE2WHO need mapping
+ recordType=record.service.recordTypeToOldName(record.recordType),
shortNames=record.shortNames,
fullName=record.displayName,
principalUID=parent.principalUID(),
Modified: CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/directory/principal.py
===================================================================
--- 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)
@@ -402,8 +402,10 @@
def listChildren(self):
- # MOVE2WHO hack
- return [r.name + "s" for r in self.directory.recordTypes()]
+ return [
+ self.directory.recordTypeToOldName(r)
+ for r in self.directory.recordTypes()
+ ]
##
@@ -652,7 +654,7 @@
directoryGUID=str(record.service.guid),
realm=str(record.service.realmName),
principalGUID=guid,
- recordType=record.recordType.name + "s", # MOVE2WHO need mapping
+ recordType=record.service.recordTypeToOldName(record.recordType),
shortNames=",".join(record.shortNames),
# MOVE2WHO: need this?
# securityIDs=",".join(record.authIDs),
Modified: CalendarServer/branches/users/sagen/move2who-3/twistedcaldav/extensions.py
===================================================================
--- 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)
@@ -729,8 +729,13 @@
elif name == "record-type":
if hasattr(self, "record"):
- # MOVE2WHO -- need mapping
- returnValue(customxml.RecordType(self.record.recordType.name + "s"))
+ returnValue(
+ customxml.RecordType(
+ self.record.service.recordTypeToOldName(
+ self.record.recordType
+ )
+ )
+ )
else:
raise HTTPError(StatusResponse(
responsecode.NOT_FOUND,
Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/dps/server.py
===================================================================
--- 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)
@@ -137,7 +137,7 @@
recordType = recordType # as bytes
log.debug("RecordsWithRecordType: {r}", r=recordType)
records = (yield self._directory.recordsWithRecordType(
- RecordType.lookupByName(recordType))
+ self._directory.recordType.lookupByName(recordType))
)
fieldsList = []
for record in records:
@@ -196,7 +196,7 @@
newFields.append((fieldName, searchTerm, matchFlags, matchType))
operand = Operand.lookupByName(operand)
if recordType:
- recordType = RecordType.lookupByName(recordType)
+ recordType = self._directory.recordType.lookupByName(recordType)
records = yield self._directory.recordsMatchingFields(
newFields, operand=operand, recordType=recordType
)
Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/who/augment.py
===================================================================
--- 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)
@@ -215,12 +215,10 @@
if record is None:
returnValue(None)
- # MOVE2WHO
- # FIXME: hacked by appending an "s" -- need a mapping
try:
augmentRecord = yield self._augmentDB.getAugmentRecord(
record.uid,
- record.recordType.name + "s"
+ self.recordTypeToOldName(record.recordType)
)
except KeyError:
# Augments does not know about this record type, so return
Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/who/directory.py
===================================================================
--- 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)
@@ -146,15 +146,29 @@
return self.recordsFromExpression(expression)
+ _oldRecordTypeNames = {
+ "address": "addresses",
+ "group": "groups",
+ "location": "locations",
+ "resource": "resources",
+ "user": "users",
+ "readDelegateGroup": "readDelegateGroups",
+ "writeDelegateGroup": "writeDelegateGroups",
+ "readDelegatorGroup": "readDelegatorGroups",
+ "writeDelegatorGroup": "writeDelegatorGroups",
+ }
+
# FIXME: Existing code assumes record type names are plural. Is there any
# reason to maintain backwards compatibility? I suppose there could be
# scripts referring to record type of "users", "locations"
def recordTypeToOldName(self, recordType):
- return recordType.name + u"s"
+ return self._oldRecordTypeNames[recordType.name]
-
def oldNameToRecordType(self, oldName):
- return self.recordType.lookupByName(oldName[:-1])
+ for name, value in self._oldRecordTypeNames.iteritems():
+ if oldName == value:
+ return self.recordType.lookupByName(name)
+ return None
@@ -217,7 +231,8 @@
cuas.add("/principals/__uids__/{uid}/".format(uid=self.uid))
for shortName in self.shortNames:
cuas.add("/principals/{rt}/{sn}/".format(
- rt=self.recordType.name + "s", sn=shortName)
+ rt=self.service.recordTypeToOldName(self.recordType),
+ sn=shortName)
)
return frozenset(cuas)
Modified: CalendarServer/branches/users/sagen/move2who-3/txdav/who/test/test_util.py
===================================================================
--- 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)
@@ -21,6 +21,7 @@
import os
from txdav.who.util import directoryFromConfig
+from twisted.internet.defer import inlineCallbacks
from twisted.trial.unittest import TestCase
from twistedcaldav.config import ConfigDict
from twisted.python.filepath import FilePath
@@ -64,6 +65,7 @@
augments.setContent(sourceAugments.getContent())
+ @inlineCallbacks
def test_directoryFromConfig(self):
config = ConfigDict(
@@ -82,7 +84,7 @@
"type": "XML",
"params": {
"xmlFile": "resources.xml",
- "recordTypes": ["locations", "resources"],
+ "recordTypes": ["locations", "resources", "addresses"],
},
},
"AugmentService": {
@@ -115,7 +117,13 @@
)
self.assertEquals(
set(service._directory.services[1].recordTypes()),
- set([CalRecordType.location, CalRecordType.resource])
+ set(
+ [
+ CalRecordType.location,
+ CalRecordType.resource,
+ CalRecordType.address
+ ]
+ )
)
self.assertTrue(
isinstance(service._directory.services[2], DelegateDirectoryService)
@@ -131,3 +139,7 @@
]
)
)
+
+ # And make sure it's functional:
+ record = yield service.recordWithUID("group07")
+ self.assertEquals(record.fullNames, [u'Group 07'])
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140314/e25fd8a0/attachment-0001.html>
More information about the calendarserver-changes
mailing list