[CalendarServer-changes] [1746] CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav /directory

source_changes at macosforge.org source_changes at macosforge.org
Wed Aug 1 10:33:38 PDT 2007


Revision: 1746
          http://trac.macosforge.org/projects/calendarserver/changeset/1746
Author:   wsanchez at apple.com
Date:     2007-08-01 10:33:38 -0700 (Wed, 01 Aug 2007)

Log Message:
-----------
Pulled up r1634 r1643 r1734 from trunk.

Modified Paths:
--------------
    CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/calendaruserproxy.py
    CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/principal.py

Modified: CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/calendaruserproxy.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/calendaruserproxy.py	2007-08-01 17:23:13 UTC (rev 1745)
+++ CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/calendaruserproxy.py	2007-08-01 17:33:38 UTC (rev 1746)
@@ -99,8 +99,15 @@
         self._url = joinURL(parent.principalURL(), proxyType)
         if self.isCollection():
             self._url += "/"
-        self.guid = self.parent.principalUID() + "-" + proxyType
 
+        # Not terribly useful at present because we don't have a way
+        # to map a GUID back to the correct principal.
+        #self.guid = uuidFromName(self.parent.principalUID(), proxyType)
+
+        # Principal UID is parent's GUID plus the proxy type; this we
+        # can easily map back to a principal.
+        self.uid = "%s#%s" % (self.parent.principalUID(), proxyType)
+
         # Provision in __init__() because principals are used prior to request
         # lookups.
         self.provision()
@@ -147,7 +154,7 @@
     def setGroupMemberSet(self, new_members, request):
         # FIXME: as defined right now it is not possible to specify a calendar-user-proxy group as
         # a member of any other group since the directory service does not know how to lookup
-        # these special resource GUIDs.
+        # these special resource UIDs.
         #
         # Really, c-u-p principals should be treated the same way as any other principal, so
         # they should be allowed as members of groups.
@@ -169,10 +176,10 @@
                 ))
             principals.append(principal)
         
-        # Map the principals to GUIDs.
-        guids = [p.principalUID() for p in principals]
+        # Map the principals to UIDs.
+        uids = [p.principalUID() for p in principals]
 
-        self._index().setGroupMembers(self.guid, guids)
+        self._index().setGroupMembers(self.uid, uids)
         return succeed(True)
 
     ##
@@ -204,7 +211,7 @@
                 """<pre><blockquote>"""
                 """Directory Information\n"""
                 """---------------------\n"""
-                """Parent Directory GUID: %s\n"""  % (self.parent.record.service.guid,),
+                """Directory GUID: %s\n"""         % (self.parent.record.service.guid,),
                 """Realm: %s\n"""                  % (self.parent.record.service.realmName,),
                 """\n"""
                 """Parent Principal Information\n"""
@@ -218,6 +225,7 @@
                 """\n"""
                 """Proxy Principal Information\n"""
                 """---------------------\n"""
+               #"""GUID: %s\n"""                   % (self.guid,),
                 """Principal UID: %s\n"""          % (self.principalUID(),),
                 """Principal URL: %s\n"""          % (link(self.principalURL()),),
                 """\nAlternate URIs:\n"""          , format_list(self.alternateURIs()),
@@ -250,16 +258,16 @@
         return self._url
 
     def principalUID(self):
-        return self.guid
+        return self.uid
 
     def principalCollections(self):
         return self.parent.principalCollections()
 
     def groupMembers(self):
         if self.hasEditableMembership():
-            # Get member GUIDs from database and map to principal resources
-            members = self._index().getMembers(self.guid)
-            return [self.pcollection.principalForGUID(guid) for guid in members]
+            # Get member UIDs from database and map to principal resources
+            members = self._index().getMembers(self.uid)
+            return [self.pcollection.principalForUID(uid) for uid in members]
         else:
             # Fixed proxies are only for read-write - the read-only list is empty
             if self.proxyType == "calendar-proxy-write":
@@ -268,9 +276,9 @@
                 return ()
 
     def groupMemberships(self):
-        # Get membership GUIDs and map to principal resources
-        memberships = self._index().getMemberships(self.guid)
-        return [self.pcollection.principalForGUID(guid) for guid in memberships]
+        # Get membership UIDs and map to principal resources
+        memberships = self._index().getMemberships(self.uid)
+        return [self.pcollection.principalForUID(uid) for uid in memberships]
 
     def hasEditableMembership(self):
         return self.parent.hasEditableProxyMembership()
@@ -295,68 +303,68 @@
         path = os.path.join(path, CalendarUserProxyDatabase.dbFilename)
         super(CalendarUserProxyDatabase, self).__init__(path)
 
-    def setGroupMembers(self, principalGUID, members):
+    def setGroupMembers(self, principalUID, members):
         """
         Add a group membership record.
     
-        @param principalGUID: the principalGUID of the group principal to add.
-        @param members: the list of principalGUIDs that are members of this group.
+        @param principalUID: the UID of the group principal to add.
+        @param members: a list UIDs of principals that are members of this group.
         """
         
         # Remove what is there, then add it back.
-        self._delete_from_db(principalGUID)
-        self._add_to_db(principalGUID, members)
+        self._delete_from_db(principalUID)
+        self._add_to_db(principalUID, members)
         self._db_commit()
 
-    def removeGroup(self, principalGUID):
+    def removeGroup(self, principalUID):
         """
         Remove a group membership record.
     
-        @param principalGUID: the principalGUID of the group principal to remove.
+        @param principalUID: the UID of the group principal to remove.
         """
-        self._delete_from_db(principalGUID)
+        self._delete_from_db(principalUID)
         self._db_commit()
     
-    def getMembers(self, principalGUID):
+    def getMembers(self, principalUID):
         """
-        Return the list of group member GUIDs for the specified principal.
+        Return the list of group member UIDs for the specified principal.
         """
         members = set()
-        for row in self._db_execute("select MEMBER from GROUPS where GROUPNAME = :1", principalGUID):
+        for row in self._db_execute("select MEMBER from GROUPS where GROUPNAME = :1", principalUID):
             members.add(row[0])
         return members
     
-    def getMemberships(self, principalGUID):
+    def getMemberships(self, principalUID):
         """
-        Return the list of group principal GUIDs the specified principal is a member of.
+        Return the list of group principal UIDs the specified principal is a member of.
         """
         members = set()
-        for row in self._db_execute("select GROUPNAME from GROUPS where MEMBER = :1", principalGUID):
+        for row in self._db_execute("select GROUPNAME from GROUPS where MEMBER = :1", principalUID):
             members.add(row[0])
         return members
 
-    def _add_to_db(self, principalGUID, members):
+    def _add_to_db(self, principalUID, members):
         """
         Insert the specified entry into the database.
 
-        @param principalGUID: the principalGUID of the group principal to add.
-        @param members: the list of principalGUIDs that are members of this group.
+        @param principalUID: the UID of the group principal to add.
+        @param members: a list of UIDs or principals that are members of this group.
         """
         for member in members:
             self._db_execute(
                 """
                 insert into GROUPS (GROUPNAME, MEMBER)
                 values (:1, :2)
-                """, principalGUID, member
+                """, principalUID, member
             )
        
-    def _delete_from_db(self, principalGUID):
+    def _delete_from_db(self, principalUID):
         """
         Deletes the specified entry from the database.
 
-        @param principalGUID: the principalGUID of the group principal to remove.
+        @param principalUID: the UID of the group principal to remove.
         """
-        self._db_execute("delete from GROUPS where GROUPNAME = :1", principalGUID)
+        self._db_execute("delete from GROUPS where GROUPNAME = :1", principalUID)
     
     def _db_version(self):
         """

Modified: CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/principal.py
===================================================================
--- CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/principal.py	2007-08-01 17:23:13 UTC (rev 1745)
+++ CalendarServer/branches/release/CalendarServer-1.0-dev/twistedcaldav/directory/principal.py	2007-08-01 17:33:38 UTC (rev 1746)
@@ -58,12 +58,41 @@
         # Permissions here are fixed, and are not subject to inherritance rules, etc.
         return succeed(self.defaultAccessControlList())
 
-class DirectoryPrincipalProvisioningResource (
+class DirectoryProvisioningResource(
     AutoProvisioningFileMixIn,
     PermissionsMixIn,
     CalendarPrincipalCollectionResource,
     DAVFile,
 ):
+    def principalForShortName(self, type, name):
+        raise NotImplementedError("Subclass must implement principalForShortName()")
+
+    def principalForUser(self, user):
+        return self.principalForShortName(DirectoryService.recordType_users, user)
+
+    def principalForGUID(self, guid):
+        record = self.directory.recordWithGUID(guid)
+        if record:
+            return self.principalForRecord(record)
+        else:
+            return None
+
+    def principalForUID(self, uid):
+        if "#" in uid:
+            # This UID belongs to a sub-principal
+            parent_uid, subType = uid.split("#")
+            return self.principalForGUID(parent_uid).getChild(subType)
+        else:
+            # This UID belongs to a primary principal (UID == GUID)
+            return self.principalForGUID(uid)
+
+    def principalForRecord(self, record):
+        return self.principalForShortName(record.recordType, record.shortName)
+
+    def principalForCalendarUserAddress(self, address):
+        raise NotImplementedError("Subclass must implement principalForCalendarUserAddress()")
+
+class DirectoryPrincipalProvisioningResource (DirectoryProvisioningResource):
     """
     Collection resource which provisions directory principals as its children.
     """
@@ -93,19 +122,6 @@
             return None
         return typeResource.getChild(name)
 
-    def principalForUser(self, user):
-        return self.principalForShortName(DirectoryService.recordType_users, user)
-
-    def principalForGUID(self, guid):
-        record = self.directory.recordWithGUID(guid)
-        if record:
-            return self.principalForRecord(record)
-        else:
-            return None
-
-    def principalForRecord(self, record):
-        return self.principalForShortName(record.recordType, record.shortName)
-
     def _principalForURI(self, uri):
         scheme, netloc, path, params, query, fragment = urlparse(uri)
 
@@ -192,12 +208,7 @@
     def principalCollections(self):
         return (self,)
 
-class DirectoryPrincipalTypeResource (
-    AutoProvisioningFileMixIn,
-    PermissionsMixIn,
-    CalendarPrincipalCollectionResource,
-    DAVFile,
-):
+class DirectoryPrincipalTypeResource (DirectoryProvisioningResource):
     """
     Collection resource which provisions directory principals of a specific type as its children.
     """
@@ -217,15 +228,6 @@
     def principalForShortName(self, type, name):
         return self.parent.principalForShortName(type, name)
 
-    def principalForUser(self, user):
-        return self.parent.principalForUser(user)
-
-    def principalForRecord(self, record):
-        return self.parent.principalForRecord(record)
-
-    def principalForGUID(self, guid):
-        return self.parent.principalForGUID(guid)
-
     def principalForCalendarUserAddress(self, address):
         return self.parent.principalForCalendarUserAddress(address)
 
@@ -400,32 +402,6 @@
             setattr(pcollection, "calendar_user_proxy_db", CalendarUserProxyDatabase(pcollection.fp.path))
         return pcollection.calendar_user_proxy_db
 
-    def _map_calendar_user_proxy_guids(self, guids):
-        """
-        Return a list of principals mapped from a list of calendar user proxy principal GUIDs.
-        
-        @param guids: a C{list} of C{str}'s containing the GUIDs to map.
-        @return: a C{list} of L{CalendarPrincipalResource}s for each mapped GUID.
-        """
-        proxies = []
-        for guid in guids:
-            # Get the "base" GUID for the parent of the proxy principal
-            if guid.endswith("-calendar-proxy-read"):
-                guid = guid[:-20]
-                proxyType = "calendar-proxy-read"
-            elif guid.endswith("-calendar-proxy-write"):
-                guid = guid[:-21]
-                proxyType = "calendar-proxy-write"
-                
-            # Lookup the base GUID and get its principal resource
-            principal = self.parent.principalForGUID(guid)
-            if principal:
-                proxyprincipal = principal.getChild(proxyType)
-                if proxyprincipal:
-                    proxies.append(proxyprincipal)
-                    
-        return proxies
-            
     def groupMembers(self):
         return self._getRelatives("members")
 
@@ -436,8 +412,13 @@
             # Get any directory specified proxies
             groups.update(self._getRelatives("proxyFor", proxy=True))
 
-            # Get proxy group GUIDs and map to principal resources
-            proxies = self._map_calendar_user_proxy_guids(self._calendar_user_proxy_index().getMemberships(self.principalUID()))
+            # Get proxy group UIDs and map to principal resources
+            proxies = []
+            for uid in self._calendar_user_proxy_index().getMemberships(self.principalUID()):
+                subprincipal = self.parent.principalForUID(uid)
+                if subprincipal:
+                    proxies.append(subprincipal)
+
             groups.update(proxies)
 
         return groups
@@ -461,8 +442,8 @@
             addresses.add("http://%s:%s%s" % (config.ServerHostName, config.HTTPPort, self.principalURL(),))
         if config.SSLPort:
             addresses.add("https://%s:%s%s" % (config.ServerHostName, config.SSLPort, self.principalURL(),))
-        addresses.add("urn:uuid:%s" % (self.principalUID(),))
-        
+        addresses.add("urn:uuid:%s" % (self.record.guid,))
+
         return addresses
 
     def autoSchedule(self):

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


More information about the calendarserver-changes mailing list