[CalendarServer-changes] [974] CalendarServer/trunk

source_changes at macosforge.org source_changes at macosforge.org
Mon Jan 8 13:55:15 PST 2007


Revision: 974
          http://trac.macosforge.org/projects/calendarserver/changeset/974
Author:   cdaboo at apple.com
Date:     2007-01-08 13:55:15 -0800 (Mon, 08 Jan 2007)

Log Message:
-----------
Abstract the record type names into constants and reference those instead of hard-coded strings. Also change to
using plural form of record types. Also make sure that locations have tha auto-schedule option on in addition
to resources.

Modified Paths:
--------------
    CalendarServer/trunk/conf/accounts.dtd
    CalendarServer/trunk/conf/accounts.xml
    CalendarServer/trunk/conf/caldavd-test.plist
    CalendarServer/trunk/conf/caldavd.plist
    CalendarServer/trunk/twistedcaldav/admin/options.py
    CalendarServer/trunk/twistedcaldav/config.py
    CalendarServer/trunk/twistedcaldav/directory/apache.py
    CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
    CalendarServer/trunk/twistedcaldav/directory/directory.py
    CalendarServer/trunk/twistedcaldav/directory/principal.py
    CalendarServer/trunk/twistedcaldav/directory/sqldb.py
    CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml
    CalendarServer/trunk/twistedcaldav/directory/test/test_apache.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectory.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
    CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py
    CalendarServer/trunk/twistedcaldav/directory/test/util.py
    CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
    CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
    CalendarServer/trunk/twistedcaldav/static.py
    CalendarServer/trunk/twistedcaldav/test/test_root.py

Modified: CalendarServer/trunk/conf/accounts.dtd
===================================================================
--- CalendarServer/trunk/conf/accounts.dtd	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/conf/accounts.dtd	2007-01-08 21:55:15 UTC (rev 974)
@@ -32,7 +32,7 @@
     <!ATTLIST location repeat CDATA "1">
 
   <!ELEMENT member (#PCDATA)>
-    <!ATTLIST member type (user|group|resource) "user">
+    <!ATTLIST member type (users|groups|locations|resources) "users">
 
   <!ELEMENT uid (#PCDATA)>
   <!ELEMENT password    (#PCDATA)>

Modified: CalendarServer/trunk/conf/accounts.xml
===================================================================
--- CalendarServer/trunk/conf/accounts.xml	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/conf/accounts.xml	2007-01-08 21:55:15 UTC (rev 974)
@@ -41,7 +41,7 @@
     <password>users</password>
     <name>Users Group</name>
     <members>
-      <member type="user">test</member>
+      <member type="users">test</member>
     </members>
   </group>
   <resource>

Modified: CalendarServer/trunk/conf/caldavd-test.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd-test.plist	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/conf/caldavd-test.plist	2007-01-08 21:55:15 UTC (rev 974)
@@ -189,7 +189,7 @@
 
   <key>AdminPrincipals</key>
   <array>
-    <string>/principals/user/admin/</string>
+    <string>/principals/users/admin/</string>
   </array>
   
   <key>ServerType</key>

Modified: CalendarServer/trunk/conf/caldavd.plist
===================================================================
--- CalendarServer/trunk/conf/caldavd.plist	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/conf/caldavd.plist	2007-01-08 21:55:15 UTC (rev 974)
@@ -134,7 +134,7 @@
 
   <key>AdminPrincipals</key>
   <array>
-    <string>/principals/user/admin/</string>
+    <string>/principals/users/admin/</string>
   </array>
   <key>ServerType</key>
   <string>singleprocess</string>

Modified: CalendarServer/trunk/twistedcaldav/admin/options.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/admin/options.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/admin/options.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -164,23 +164,31 @@
         report = reflect.namedAny(self.action)(self, self.name).run()
         self.parent.formatter.printReport(report)
 
+from twistedcaldav.directory.directory import DirectoryService
 
 class UserOptions(PrincipalOptions):
-    name = "user"
+    name = DirectoryService.recordType_users
     help = PrincipalOptions.help % (name,)
 
 registerCommand(UserOptions)
 
 
 class GroupOptions(PrincipalOptions):
-    name = "group"
+    name = DirectoryService.recordType_groups
     help = PrincipalOptions.help % (name,)
 
 registerCommand(GroupOptions)
 
 
+class LocationOptions(PrincipalOptions):
+    name = DirectoryService.recordType_locations
+    help = PrincipalOptions.help % (name,)
+
+registerCommand(LocationOptions)
+
+
 class ResourceOptions(PrincipalOptions):
-    name = "resource"
+    name = DirectoryService.recordType_resources
     help = PrincipalOptions.help % (name,)
 
 registerCommand(ResourceOptions)

Modified: CalendarServer/trunk/twistedcaldav/config.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/config.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/config.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -61,7 +61,7 @@
             'ServicePrincipal': '',
             },
         },
-    'AdminPrincipals': ['/principals/user/admin/'],
+    'AdminPrincipals': ['/principals/users/admin/'],
 
     'twistdLocation': '/usr/share/caldavd/bin/twistd',
     'pydirLocation': '/usr/share/caldavd/bin/pydir++.py',

Modified: CalendarServer/trunk/twistedcaldav/directory/apache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/apache.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/apache.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -53,14 +53,14 @@
         self.groupFile = groupFile
 
     def recordTypes(self):
-        recordTypes = ("user",)
+        recordTypes = (DirectoryService.recordType_users,)
         if self.groupFile is not None:
-            recordTypes += ("group",)
+            recordTypes += (DirectoryService.recordType_groups,)
         return recordTypes
 
     def listRecords(self, recordType):
         for entryShortName, entryData in self.entriesForRecordType(recordType):
-            if recordType == "user":
+            if recordType == DirectoryService.recordType_users:
                 yield self.userRecordClass(
                     service       = self,
                     recordType    = recordType,
@@ -68,7 +68,7 @@
                     cryptPassword = entryData,
                 )
 
-            elif recordType == "group":
+            elif recordType == DirectoryService.recordType_groups:
                 yield GroupRecord(
                     service    = self,
                     recordType = recordType,
@@ -83,7 +83,7 @@
     def recordWithShortName(self, recordType, shortName):
         for entryShortName, entryData in self.entriesForRecordType(recordType):
             if entryShortName == shortName:
-                if recordType == "user":
+                if recordType == DirectoryService.recordType_users:
                     return self.userRecordClass(
                         service       = self,
                         recordType    = recordType,
@@ -91,7 +91,7 @@
                         cryptPassword = entryData,
                     )
 
-                if recordType == "group":
+                if recordType == DirectoryService.recordType_groups:
                     return GroupRecord(
                         service    = self,
                         recordType = recordType,
@@ -105,9 +105,9 @@
         return None
 
     def entriesForRecordType(self, recordType):
-        if recordType == "user":
+        if recordType == DirectoryService.recordType_users:
             recordFile = self.userFile
-        elif recordType == "group":
+        elif recordType == DirectoryService.recordType_groups:
             recordFile = self.groupFile
         else:
             raise UnknownRecordTypeError("Unknown record type: %s" % (recordType,))
@@ -141,7 +141,7 @@
         self._cryptPassword = cryptPassword
 
     def groups(self):
-        for group in self.service.listRecords("group"):
+        for group in self.service.listRecords(DirectoryService.recordType_groups):
             for member in group.members():
                 if member == self:
                     yield group
@@ -195,4 +195,4 @@
 
     def members(self):
         for shortName in self._members:
-            yield self.service.recordWithShortName("user", shortName)
+            yield self.service.recordWithShortName(DirectoryService.recordType_users, shortName)

Modified: CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/appleopendirectory.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -78,7 +78,11 @@
         return h
 
     def recordTypes(self):
-        return ("user", "group", "location", "resource")
+        return (
+            DirectoryService.recordType_users,
+            DirectoryService.recordType_groups,
+            DirectoryService.recordType_locations,
+            DirectoryService.recordType_resources)
 
     def _cacheRecords(self, recordType):
         if recordType not in self._records:
@@ -88,15 +92,15 @@
                 dsattributes.kDS1AttrGeneratedUID,
                 dsattributes.kDS1AttrDistinguishedName,
             ]
-            if recordType == "user":
+            if recordType == DirectoryService.recordType_users:
                 listRecordType = dsattributes.kDSStdRecordTypeUsers
-            elif recordType == "group":
+            elif recordType == DirectoryService.recordType_groups:
                 listRecordType = dsattributes.kDSStdRecordTypeGroups
                 attrs += [dsattributes.kDSNAttrGroupMembers,]
-            elif recordType == "resource":
+            elif recordType == DirectoryService.recordType_locations:
+                listRecordType = dsattributes.kDSStdRecordTypeLocations
+            elif recordType == DirectoryService.recordType_resources:
                 listRecordType = dsattributes.kDSStdRecordTypeResources
-            elif recordType == "location":
-                listRecordType = dsattributes.kDSStdRecordTypeLocations
             else:
                 raise UnknownRecordTypeError("Unknown Open Directory record type: %s" % (recordType,))
 
@@ -115,7 +119,7 @@
                     continue
                 realName = value.get(dsattributes.kDS1AttrDistinguishedName)
 
-                if recordType == "group":
+                if recordType == DirectoryService.recordType_groups:
                     memberGUIDs = value.get(dsattributes.kDSNAttrGroupMembers)
                     if memberGUIDs is None:
                         memberGUIDs = ()
@@ -170,7 +174,7 @@
         self._memberGUIDs = tuple(memberGUIDs)
 
     def members(self):
-        if self.recordType != "group":
+        if self.recordType != DirectoryService.recordType_groups:
             return
 
         for guid in self._memberGUIDs:
@@ -181,7 +185,7 @@
                 yield userRecord
 
     def groups(self):
-        for groupRecord in self.service._cacheRecords("group").itervalues():
+        for groupRecord in self.service._cacheRecords(DirectoryService.recordType_groups).itervalues():
             if self.guid in groupRecord._memberGUIDs:
                 yield groupRecord
 

Modified: CalendarServer/trunk/twistedcaldav/directory/directory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/directory.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/directory.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -50,6 +50,11 @@
 
     realmName = None
 
+    recordType_users = "users"
+    recordType_groups = "groups"
+    recordType_locations = "locations"
+    recordType_resources = "resources"
+    
     def _generatedGUID(self):
         if not hasattr(self, "_guid"):
             realmName = self.realmName
@@ -84,7 +89,7 @@
         # implementation because you shouldn't have a principal object for a
         # disabled directory principal.
 
-        user = self.recordWithShortName("user", credentials.credentials.username)
+        user = self.recordWithShortName(DirectoryService.recordType_users, credentials.credentials.username)
         if user is None:
             raise UnauthorizedLogin("No such user: %s" % (user,))
 

Modified: CalendarServer/trunk/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/principal.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/principal.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -40,6 +40,7 @@
 from twistedcaldav.config import config
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyDatabase
 from twistedcaldav.directory.calendaruserproxy import CalendarUserProxyPrincipalResource
+from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.extensions import ReadOnlyResourceMixIn, DAVFile
 from twistedcaldav.resource import CalendarPrincipalCollectionResource, CalendarPrincipalResource
 from twistedcaldav.static import AutoProvisioningFileMixIn
@@ -87,7 +88,7 @@
             self.putChild(recordType, DirectoryPrincipalTypeResource(self.fp.child(recordType).path, self, recordType))
 
     def principalForUser(self, user):
-        return self.getChild("user").getChild(user)
+        return self.getChild(DirectoryService.recordType_users).getChild(user)
 
     def principalForRecord(self, record):
         typeResource = self.getChild(record.recordType)

Modified: CalendarServer/trunk/twistedcaldav/directory/sqldb.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/sqldb.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/sqldb.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -277,7 +277,12 @@
         self.realmName = self.manager.getRealm()
 
     def recordTypes(self):
-        recordTypes = ("user", "group", "location", "resource")
+        recordTypes = (
+            DirectoryService.recordType_users,
+            DirectoryService.recordType_groups,
+            DirectoryService.recordType_locations,
+            DirectoryService.recordType_resources,
+        )
         return recordTypes
 
     def listRecords(self, recordType):
@@ -333,7 +338,7 @@
 
     def groups(self):
         for shortName in self._groups:
-            yield self.service.recordWithShortName("group", shortName)
+            yield self.service.recordWithShortName(DirectoryService.recordType_groups, shortName)
 
     def verifyCredentials(self, credentials):
         if isinstance(credentials, UsernamePassword):

Modified: CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/test/accounts.xml	2007-01-08 21:55:15 UTC (rev 974)
@@ -64,7 +64,7 @@
     <password>managers</password>
     <name>Managers</name>
     <members>
-      <member type="user">lecroy</member>
+      <member type="users">lecroy</member>
     </members>
   </group>
   <group>
@@ -72,7 +72,7 @@
     <password>admin</password>
     <name>Administrators</name>
     <members>
-      <member type="group">managers</member>
+      <member type="groups">managers</member>
     </members>
   </group>
   <group>
@@ -108,8 +108,8 @@
     <password>both_coasts</password>
     <name>Both Coasts</name>
     <members>
-      <member type="group">right_coast</member>
-      <member type="group">left_coast</member>
+      <member type="groups">right_coast</member>
+      <member type="groups">left_coast</member>
     </members>
   </group>
   <location>

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_apache.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_apache.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_apache.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -22,6 +22,7 @@
 
 import twistedcaldav.directory.test.util
 from twistedcaldav.directory.apache import BasicDirectoryService, DigestDirectoryService
+from twistedcaldav.directory.directory import DirectoryService
 
 digestRealm = "Test"
 
@@ -32,7 +33,10 @@
 # FIXME: Add tests for GUID hooey, once we figure out what that means here
 
 class Apache (object):
-    recordTypes = set(("user", "group"))
+    recordTypes = set((
+        DirectoryService.recordType_users,
+        DirectoryService.recordType_groups
+    ))
 
     users = {
         "wsanchez": { "password": "foo",  "guid": None, "addresses": () },
@@ -42,10 +46,14 @@
     }
 
     groups = {
-        "managers"   : { "guid": None, "addresses": (), "members": (("user", "lecroy"),)                                         },
-        "grunts"     : { "guid": None, "addresses": (), "members": (("user", "wsanchez"), ("user", "cdaboo"), ("user", "dreid")) },
-        "right_coast": { "guid": None, "addresses": (), "members": (("user", "cdaboo"),)                                         },
-        "left_coast" : { "guid": None, "addresses": (), "members": (("user", "wsanchez"), ("user", "dreid"), ("user", "lecroy")) },
+        "managers"   : { "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "lecroy"),)                                         },
+        "grunts"     : { "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "wsanchez"),
+                                                                    (DirectoryService.recordType_users, "cdaboo"),
+                                                                    (DirectoryService.recordType_users, "dreid")) },
+        "right_coast": { "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "cdaboo"),)                                         },
+        "left_coast" : { "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "wsanchez"),
+                                                                    (DirectoryService.recordType_users, "dreid"),
+                                                                    (DirectoryService.recordType_users, "lecroy")) },
     }
 
     locations = {
@@ -75,13 +83,13 @@
 
     def test_changedGroupFile(self):
         self.groupFile().open("w").write("grunts: wsanchez\n")
-        self.assertEquals(self.recordNames("group"), set(("grunts",)))
+        self.assertEquals(self.recordNames(DirectoryService.recordType_groups), set(("grunts",)))
 
     def test_recordTypes_user(self):
         """
         IDirectoryService.recordTypes(userFile)
         """
-        self.assertEquals(set(self.serviceClass(digestRealm, self.userFile()).recordTypes()), set(("user",)))
+        self.assertEquals(set(self.serviceClass(digestRealm, self.userFile()).recordTypes()), set((DirectoryService.recordType_users,)))
 
     userEntry = None
 
@@ -89,7 +97,7 @@
         if self.userEntry is None:
             raise NotImplementedError("Test subclass needs to specify userEntry.")
         self.userFile().open("w").write(self.userEntry[1])
-        self.assertEquals(self.recordNames("user"), set((self.userEntry[0],)))
+        self.assertEquals(self.recordNames(DirectoryService.recordType_users), set((self.userEntry[0],)))
 
 class Basic (Apache, twistedcaldav.directory.test.util.BasicTestCase):
     """

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectory.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_opendirectory.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -21,6 +21,7 @@
 except ImportError:
     pass
 else:
+    from twistedcaldav.directory.directory import DirectoryService
     import twistedcaldav.directory.test.util
 
     # Wonky hack to prevent unclean reactor shutdowns
@@ -38,7 +39,12 @@
         """
         Test Open Directory directory implementation.
         """
-        recordTypes = set(("user", "group", "location", "resource"))
+        recordTypes = set((
+            DirectoryService.recordType_users,
+            DirectoryService.recordType_groups,
+            DirectoryService.recordType_locations,
+            DirectoryService.recordType_resources
+        ))
 
         users = groups = locations = resources = {}
 

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_principal.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -33,6 +33,7 @@
 
 from twistedcaldav.static import CalendarHomeProvisioningFile
 from twistedcaldav.directory.apache import BasicDirectoryService, DigestDirectoryService
+from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.directory.test.test_apache import basicUserFile, digestUserFile, groupFile, digestRealm
 from twistedcaldav.directory.xmlfile import XMLDirectoryService
 from twistedcaldav.directory.test.test_xmlfile import xmlFile
@@ -131,7 +132,7 @@
         for directory in directoryServices:
             provisioningResource = self.principalRootResources[directory.__class__.__name__]
 
-            for user in directory.listRecords("user"):
+            for user in directory.listRecords(DirectoryService.recordType_users):
                 userResource = provisioningResource.principalForUser(user.shortName)
                 self.failIf(userResource is None)
                 self.assertEquals(user, userResource.record)

Modified: CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/test/test_xmlfile.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -20,6 +20,7 @@
 
 from twisted.python.filepath import FilePath
 
+from twistedcaldav.directory.directory import DirectoryService
 import twistedcaldav.directory.test.util
 from twistedcaldav.directory.xmlfile import XMLDirectoryService
 
@@ -28,7 +29,12 @@
 # FIXME: Add tests for GUID hooey, once we figure out what that means here
 
 class XMLFileBase(object):
-    recordTypes = set(("user", "group", "location", "resource"))
+    recordTypes = set((
+        DirectoryService.recordType_users,
+        DirectoryService.recordType_groups,
+        DirectoryService.recordType_locations,
+        DirectoryService.recordType_resources
+    ))
 
     users = {
         "admin"   : { "password": "nimda",    "guid": None, "addresses": () },
@@ -42,12 +48,17 @@
     }
 
     groups = {
-        "admin"      : { "password": "admin",       "guid": None, "addresses": (), "members": (("group", "managers"),)                                      },
-        "managers"   : { "password": "managers",    "guid": None, "addresses": (), "members": (("user", "lecroy"),)                                         },
-        "grunts"     : { "password": "grunts",      "guid": None, "addresses": (), "members": (("user", "wsanchez"), ("user", "cdaboo"), ("user", "dreid")) },
-        "right_coast": { "password": "right_coast", "guid": None, "addresses": (), "members": (("user", "cdaboo"),)                                         },
-        "left_coast" : { "password": "left_coast",  "guid": None, "addresses": (), "members": (("user", "wsanchez"), ("user", "dreid"), ("user", "lecroy")) },
-        "both_coasts": { "password": "both_coasts", "guid": None, "addresses": (), "members": (("group", "right_coast"), ("group", "left_coast"))           },
+        "admin"      : { "password": "admin",       "guid": None, "addresses": (), "members": ((DirectoryService.recordType_groups, "managers"),)                                      },
+        "managers"   : { "password": "managers",    "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "lecroy"),)                                         },
+        "grunts"     : { "password": "grunts",      "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "wsanchez"),
+                                                                                               (DirectoryService.recordType_users, "cdaboo"),
+                                                                                               (DirectoryService.recordType_users, "dreid")) },
+        "right_coast": { "password": "right_coast", "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "cdaboo"),)                                         },
+        "left_coast" : { "password": "left_coast",  "guid": None, "addresses": (), "members": ((DirectoryService.recordType_users, "wsanchez"),
+                                                                                               (DirectoryService.recordType_users, "dreid"),
+                                                                                               (DirectoryService.recordType_users, "lecroy")) },
+        "both_coasts": { "password": "both_coasts", "guid": None, "addresses": (), "members": ((DirectoryService.recordType_groups, "right_coast"),
+                                                                                               (DirectoryService.recordType_groups, "left_coast"))           },
     }
 
     locations = {
@@ -92,10 +103,10 @@
 """
         )
         for recordType, expectedRecords in (
-            ( "user"     , ("admin",) ),
-            ( "group"    , ()         ),
-            ( "location" , ()         ),
-            ( "resource" , ()         ),
+            ( DirectoryService.recordType_users     , ("admin",) ),
+            ( DirectoryService.recordType_groups    , ()         ),
+            ( DirectoryService.recordType_locations , ()         ),
+            ( DirectoryService.recordType_resources , ()         ),
         ):
             self.assertEquals(
                 set(r.shortName for r in self.service().listRecords(recordType)),

Modified: CalendarServer/trunk/twistedcaldav/directory/test/util.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/test/util.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/test/util.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -21,6 +21,7 @@
 from twisted.cred.credentials import UsernamePassword
 from twisted.web2.auth.digest import DigestedCredentials, calcResponse, calcHA1
 
+from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.directory.directory import UnknownRecordTypeError
 
 # FIXME: Add tests for GUID hooey, once we figure out what that means here
@@ -68,21 +69,21 @@
 
     def test_listRecords_user(self):
         """
-        IDirectoryService.listRecords("user")
+        IDirectoryService.listRecords(DirectoryService.recordType_users)
         """
         if not self.users:
             raise SkipTest("No users")
 
-        self.assertEquals(self.recordNames("user"), set(self.users.keys()))
+        self.assertEquals(self.recordNames(DirectoryService.recordType_users), set(self.users.keys()))
 
     def test_listRecords_group(self):
         """
-        IDirectoryService.listRecords("group")
+        IDirectoryService.listRecords(DirectoryService.recordType_groups)
         """
         if not self.groups:
             raise SkipTest("No groups")
 
-        self.assertEquals(self.recordNames("group"), set(self.groups.keys()))
+        self.assertEquals(self.recordNames(DirectoryService.recordType_groups), set(self.groups.keys()))
 
     def test_listRecords_locations(self):
         """
@@ -91,7 +92,7 @@
         if not self.resources:
             raise SkipTest("No locations")
 
-        self.assertEquals(self.recordNames("location"), set(self.locations.keys()))
+        self.assertEquals(self.recordNames(DirectoryService.recordType_locations), set(self.locations.keys()))
 
     def test_listRecords_resources(self):
         """
@@ -100,17 +101,17 @@
         if not self.resources:
             raise SkipTest("No resources")
 
-        self.assertEquals(self.recordNames("resource"), set(self.resources.keys()))
+        self.assertEquals(self.recordNames(DirectoryService.recordType_resources), set(self.resources.keys()))
 
     def test_recordWithShortName(self):
         """
         IDirectoryService.recordWithShortName()
         """
         for recordType, data in (
-            ( "user"    , self.users     ),
-            ( "group"   , self.groups    ),
-            ( "location", self.locations ),
-            ( "resource", self.resources ),
+            ( DirectoryService.recordType_users    , self.users     ),
+            ( DirectoryService.recordType_groups   , self.groups    ),
+            ( DirectoryService.recordType_locations, self.locations ),
+            ( DirectoryService.recordType_resources, self.resources ),
         ):
             if not data:
                 raise SkipTest("No %s" % (recordType,))
@@ -163,7 +164,7 @@
         service = self.service()
         for group, info in self.groups.iteritems():
             prefix = info.get("prefix", "")
-            groupRecord = service.recordWithShortName(prefix + "group", group)
+            groupRecord = service.recordWithShortName(prefix + DirectoryService.recordType_groups, group)
             result = set((m.recordType, prefix + m.shortName) for m in groupRecord.members())
             expected = set(self.groups[group]["members"])
             self.assertEquals(
@@ -181,8 +182,8 @@
             raise SkipTest("No groups")
 
         for recordType, data in (
-            ( "user" , self.users  ),
-            ( "group", self.groups ),
+            ( DirectoryService.recordType_users , self.users  ),
+            ( DirectoryService.recordType_groups, self.groups ),
         ):
             service = self.service()
             for shortName, info in data.iteritems():
@@ -210,10 +211,10 @@
 
     def allEntries(self):
         for data, recordType in (
-            (self.users,     "user"    ),
-            (self.groups,    "group"   ),
-            (self.locations, "location"),
-            (self.resources, "resource"),
+            (self.users,     DirectoryService.recordType_users    ),
+            (self.groups,    DirectoryService.recordType_groups   ),
+            (self.locations, DirectoryService.recordType_locations),
+            (self.resources, DirectoryService.recordType_resources),
         ):
             for item in data.iteritems():
                 yield item
@@ -266,7 +267,7 @@
 
         service = self.service()
         for user in self.users:
-            userRecord = service.recordWithShortName("user", user)
+            userRecord = service.recordWithShortName(DirectoryService.recordType_users, user)
             self.failUnless(userRecord.verifyCredentials(UsernamePassword(user, self.users[user]["password"])))
 
 # authRequest = {
@@ -295,7 +296,7 @@
 
         service = self.service()
         for user in self.users:
-            userRecord = service.recordWithShortName("user", user)
+            userRecord = service.recordWithShortName(DirectoryService.recordType_users, user)
 
             # I'm glad this is so simple...
             response = calcResponse(

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlaccountsparser.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -29,6 +29,7 @@
 
 from twisted.python.filepath import FilePath
 
+from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.resource import CalDAVResource
 
 ELEMENT_ACCOUNTS     = "accounts"
@@ -50,10 +51,10 @@
 ATTRIBUTE_RECORDTYPE = "type"
 
 RECORD_TYPES = {
-    ELEMENT_USER     : "user",
-    ELEMENT_GROUP    : "group",
-    ELEMENT_RESOURCE : "resource",
-    ELEMENT_LOCATION : "location",
+    ELEMENT_USER     : DirectoryService.recordType_users,
+    ELEMENT_GROUP    : DirectoryService.recordType_groups,
+    ELEMENT_LOCATION : DirectoryService.recordType_locations,
+    ELEMENT_RESOURCE : DirectoryService.recordType_resources,
 }
 
 class XMLAccountsParser(object):
@@ -209,6 +210,6 @@
                 if child.hasAttribute(ATTRIBUTE_RECORDTYPE):
                     recordType = child.getAttribute(ATTRIBUTE_RECORDTYPE).encode("utf-8")
                 else:
-                    recordType = "user"
+                    recordType = DirectoryService.recordType_users
                 if child.firstChild is not None:
                     self.members.add((recordType, child.firstChild.data.encode("utf-8")))

Modified: CalendarServer/trunk/twistedcaldav/directory/xmlfile.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/directory/xmlfile.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -53,7 +53,12 @@
         self._accounts()
 
     def recordTypes(self):
-        recordTypes = ("user", "group", "location", "resource")
+        recordTypes = (
+            DirectoryService.recordType_users,
+            DirectoryService.recordType_groups,
+            DirectoryService.recordType_locations,
+            DirectoryService.recordType_resources
+        )
         return recordTypes
 
     def listRecords(self, recordType):
@@ -114,7 +119,7 @@
 
     def groups(self):
         for shortName in self._groups:
-            yield self.service.recordWithShortName("group", shortName)
+            yield self.service.recordWithShortName(DirectoryService.recordType_groups, shortName)
 
     def verifyCredentials(self, credentials):
         if isinstance(credentials, UsernamePassword):

Modified: CalendarServer/trunk/twistedcaldav/static.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/static.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/static.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -52,6 +52,7 @@
 from twistedcaldav import caldavxml
 from twistedcaldav import customxml
 from twistedcaldav.config import config
+from twistedcaldav.directory.directory import DirectoryService
 from twistedcaldav.extensions import DAVFile
 from twistedcaldav.ical import Component as iComponent
 from twistedcaldav.ical import Property as iProperty
@@ -540,7 +541,7 @@
         if self.provisionFile():
             # FIXME: This should probably be a directory record option that
             # maps to the property value directly without the need to store one.
-            if self.parent.record.recordType == "resource":
+            if self.parent.record.recordType in (DirectoryService.recordType_locations, DirectoryService.recordType_resources,):
                 # Resources should have autorespond turned on by default,
                 # since they typically don't have someone responding for them.
                 self.writeDeadProperty(customxml.TwistedScheduleAutoRespond())

Modified: CalendarServer/trunk/twistedcaldav/test/test_root.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/test/test_root.py	2007-01-08 21:09:00 UTC (rev 973)
+++ CalendarServer/trunk/twistedcaldav/test/test_root.py	2007-01-08 21:55:15 UTC (rev 974)
@@ -142,7 +142,7 @@
 
             self.assertEquals(request.authzUser, 
                               davxml.Principal(
-                    davxml.HRef('/principals/user/dreid/')))
+                    davxml.HRef('/principals/users/dreid/')))
             
         d = defer.maybeDeferred(resrc.locateChild, request, ['principals'])
         d.addCallback(_Cb)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20070108/e6c1ff87/attachment.html


More information about the calendarserver-changes mailing list