[CalendarServer-changes] [4023] CalendarServer/trunk/twistedcaldav/directory/ cachingappleopendirectory.py

source_changes at macosforge.org source_changes at macosforge.org
Wed Apr 15 20:51:26 PDT 2009


Revision: 4023
          http://trac.macosforge.org/projects/calendarserver/changeset/4023
Author:   sagen at apple.com
Date:     2009-04-15 20:51:25 -0700 (Wed, 15 Apr 2009)
Log Message:
-----------
restrictToGroup now honored by cachingappleopendirectory

Modified Paths:
--------------
    CalendarServer/trunk/twistedcaldav/directory/cachingappleopendirectory.py

Modified: CalendarServer/trunk/twistedcaldav/directory/cachingappleopendirectory.py
===================================================================
--- CalendarServer/trunk/twistedcaldav/directory/cachingappleopendirectory.py	2009-04-16 00:47:19 UTC (rev 4022)
+++ CalendarServer/trunk/twistedcaldav/directory/cachingappleopendirectory.py	2009-04-16 03:51:25 UTC (rev 4023)
@@ -24,6 +24,7 @@
 ]
 
 import sys
+import time
 from uuid import UUID
 
 from twext.python.plistlib import readPlistFromString
@@ -91,6 +92,7 @@
         else:
             self.restrictToGUID = True
         self.restrictedGUIDs = None
+        self.restrictedTimestamp = 0
         self._records = {}
         self._delayedCalls = set()
 
@@ -576,7 +578,40 @@
             if recordType == self.recordType_groups:
                 enabledForCalendaring = False
             else:
-                if self.restrictEnabledRecords and self.restrictedGUIDs is not None:
+                if self.restrictEnabledRecords:
+                    if time.time() - self.restrictedTimestamp > self.cacheTimeout:
+                        attributeToMatch = dsattributes.kDS1AttrGeneratedUID if self.restrictToGUID else dsattributes.kDSNAttrRecordName
+                        valueToMatch = self.restrictToGroup
+                        self.log_debug("Doing restricted group membership check")
+                        self.log_debug("opendirectory.queryRecordsWithAttribute_list(%r,%r,%r,%r,%r,%r,%r)" % (
+                            self.directory,
+                            attributeToMatch,
+                            valueToMatch,
+                            dsattributes.eDSExact,
+                            False,
+                            dsattributes.kDSStdRecordTypeGroups,
+                            [dsattributes.kDSNAttrGroupMembers, dsattributes.kDSNAttrNestedGroups,],
+                        ))
+                        results = opendirectory.queryRecordsWithAttribute_list(
+                            self.directory,
+                            attributeToMatch,
+                            valueToMatch,
+                            dsattributes.eDSExact,
+                            False,
+                            dsattributes.kDSStdRecordTypeGroups,
+                            [dsattributes.kDSNAttrGroupMembers, dsattributes.kDSNAttrNestedGroups,],
+                        )
+
+                        if len(results) == 1:
+                            members = results[0][1].get(dsattributes.kDSNAttrGroupMembers, [])
+                            nestedGroups = results[0][1].get(dsattributes.kDSNAttrNestedGroups, [])
+                        else:
+                            members = []
+                            nestedGroups = []
+                        self.restrictedGUIDs = set(self._expandGroupMembership(members, nestedGroups, returnGroups=True))
+                        self.log_debug("Got %d restricted group members" % (len(self.restrictedGUIDs),))
+                        self.restrictedTimestamp = time.time()
+
                     enabledForCalendaring = recordGUID in self.restrictedGUIDs
                 else:
                     enabledForCalendaring = True
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20090415/73aa03ec/attachment.html>


More information about the calendarserver-changes mailing list