[CalendarServer-changes] [11899] CalendarServer/branches/users/sagen/groupcacher

source_changes at macosforge.org source_changes at macosforge.org
Wed Mar 12 11:17:34 PDT 2014


Revision: 11899
          http://trac.calendarserver.org//changeset/11899
Author:   sagen at apple.com
Date:     2013-11-06 15:41:28 -0800 (Wed, 06 Nov 2013)
Log Message:
-----------
Adds "allGroupDelegates()"

Modified Paths:
--------------
    CalendarServer/branches/users/sagen/groupcacher/twext/who/delegates.py
    CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py
    CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py

Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/delegates.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twext/who/delegates.py	2013-11-06 23:36:01 UTC (rev 11898)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/delegates.py	2013-11-06 23:41:28 UTC (rev 11899)
@@ -33,15 +33,7 @@
     """
     if delegate.recordType == RecordType.group:
         # find the groupID
-        results = (yield txn.groupByGUID(delegate.guid))
-        while not results:
-            # need to add the group to the groups table so we have a groupID
-
-            # TODO: is there a better pattern for this?
-            yield txn.addGroup(delegate.guid, delegate.fullNames[0], "")
-            results = (yield txn.groupByGUID(delegate.guid))
-
-        groupID = results[0][0]
+        groupID, name, membershipHash = (yield txn.groupByGUID(delegate.guid))
         yield txn.addDelegate(delegator.guid, groupID,
             1 if readWrite else 0, True)
     else:
@@ -87,3 +79,9 @@
             if record is not None:
                 records.append(record)
     returnValue(records)
+
+
+ at inlineCallbacks
+def allGroupDelegates(txn):
+    results = (yield txn.allGroupDelegates())
+    returnValue([r[0] for r in results])

Modified: CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py	2013-11-06 23:36:01 UTC (rev 11898)
+++ CalendarServer/branches/users/sagen/groupcacher/twext/who/test/test_delegates.py	2013-11-06 23:41:28 UTC (rev 11899)
@@ -19,7 +19,7 @@
 """
 
 from twext.who.delegates import (
-    addDelegate, removeDelegate, delegatesOf, delegateFor
+    addDelegate, removeDelegate, delegatesOf, delegateFor, allGroupDelegates
 )
 from twext.who.groups import GroupCacher
 from twext.who.test.test_xml import xmlService
@@ -104,6 +104,15 @@
         delegators = (yield delegateFor(txn, delegate1, True))
         self.assertEquals(["wsanchez"], [d.shortNames[0] for d in delegators])
 
+        # Verify we can ask for all delegated-to groups
+        group2 = yield self.xmlService.recordWithUID("__sub_group_1__")
+        yield addDelegate(txn, delegator, group2, True)
+        groups = (yield allGroupDelegates(txn))
+        self.assertEquals(
+            set([
+                "49b350c69611477b94d95516b13856ab",
+                "86144f73345a409782f1b782672087c7"
+                ]), set(groups))
 
 
 

Modified: CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py
===================================================================
--- CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py	2013-11-06 23:36:01 UTC (rev 11898)
+++ CalendarServer/branches/users/sagen/groupcacher/txdav/common/datastore/sql.py	2013-11-06 23:41:28 UTC (rev 11899)
@@ -936,7 +936,7 @@
             savepoint = SavepointAction("groupByGUID")
             yield savepoint.acquire(self)
             try:
-                groupID = (yield self.addGroup(groupGUID, "", ""))[0][0]
+                yield self.addGroup(groupGUID, "", "")
             except Exception:
                 yield savepoint.rollback(self)
                 results = (yield self._groupByGUID.on(self,
@@ -1137,6 +1137,7 @@
             return self._removeDelegateQuery.on(self, delegator=delegator,
                 delegate=delegate, readWrite=readWrite)
 
+    """
     def directDelegates(self, delegator, readWrite):
         return self._selectDelegatesQuery.on(self, delegator=delegator,
             readWrite=readWrite)
@@ -1144,6 +1145,7 @@
     def groupDelegates(self, delegator, readWrite):
         return self._selectDelegateGroupssQuery.on(self, delegator=delegator,
             readWrite=readWrite)
+    """
 
     @inlineCallbacks
     def delegates(self, delegator, readWrite):
@@ -1172,6 +1174,17 @@
             delegate=delegate, readWrite=readWrite)))
         returnValue(results)
 
+
+    def allGroupDelegates(self):
+        gr = schema.GROUPS
+        dg = schema.DELEGATE_GROUPS
+
+        return Select(
+            [gr.GROUP_GUID],
+            From=gr,
+            Where=(gr.GROUP_ID.In(Select([dg.GROUP_ID], From=dg, Where=None)))
+        ).on(self)
+
     # End of Delegates
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20140312/14a6d0e8/attachment.html>


More information about the calendarserver-changes mailing list