[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/pas/groupfolder. Fixed a bug in cycle detection to prevent diamonds from incorrectly

Jim Fulton jim at zope.com
Mon Nov 8 13:59:08 EST 2004


Log message for revision 28405:
  Fixed a bug in cycle detection to prevent diamonds from incorrectly
  being reported as cycles.
  

Changed:
  U   Zope3/trunk/src/zope/app/pas/groupfolder.py
  U   Zope3/trunk/src/zope/app/pas/groupfolder.txt

-=-
Modified: Zope3/trunk/src/zope/app/pas/groupfolder.py
===================================================================
--- Zope3/trunk/src/zope/app/pas/groupfolder.py	2004-11-08 18:58:39 UTC (rev 28404)
+++ Zope3/trunk/src/zope/app/pas/groupfolder.py	2004-11-08 18:59:07 UTC (rev 28405)
@@ -166,23 +166,16 @@
     """A user has a group id for a group that can't be found
     """
 
-def nocycles(principal_ids, seen=None, getPrincipal=None):
-    if seen is None:
-        seen = {}
-        getPrincipal = zapi.principals().getPrincipal
-
-    for principal_id in principal_ids:
+def nocycles(principal_id, seen, getPrincipal):
+    if principal_id in seen:
         if principal_id in seen:
-            raise GroupCycle(principal_id)
-        seen[principal_id] = 1
+            raise GroupCycle(principal_id, seen)
+    seen.append(principal_id)
+    principal = getPrincipal(principal_id)
+    for group_id in principal.groups:
+        nocycles(group_id, seen, getPrincipal)
+    seen.pop()
 
-    for principal_id in principal_ids:
-        principal = getPrincipal(principal_id)
-        if principal is None:
-            raise InvalidGroupId(principal_id)
-
-        nocycles(principal.groups, seen, getPrincipal)
-
 class GroupInformation(Persistent):
 
     zope.interface.implements(IGroupInformation, IGroupContained)
@@ -214,7 +207,7 @@
                 except AttributeError:
                     pass
 
-            nocycles((group_id, ))
+            nocycles(group_id, [], zapi.principals().getPrincipal)
 
         self._principals = tuple(prinlist)
         

Modified: Zope3/trunk/src/zope/app/pas/groupfolder.txt
===================================================================
--- Zope3/trunk/src/zope/app/pas/groupfolder.txt	2004-11-08 18:58:39 UTC (rev 28404)
+++ Zope3/trunk/src/zope/app/pas/groupfolder.txt	2004-11-08 18:59:07 UTC (rev 28405)
@@ -122,18 +122,38 @@
   >>> groups.getGroupsForPrincipal('group.G1')
   (u'group.G2',)
 
-But, of course, they cannot contain cycles:
+Groups cannot contain cycles:
 
   >>> g1.principals = ('p1', 'p2', 'group.G2')
   Traceback (most recent call last):
   ...
-  GroupCycle: group.G1
+  GroupCycle: (u'group.G1', [u'group.G1', u'group.G2'])
+  
+They need not be hierarchical:
 
+  >>> ga = zope.app.pas.groupfolder.GroupInformation("Group A")
+  >>> groups['GA'] = ga
+
+  >>> gb = zope.app.pas.groupfolder.GroupInformation("Group B")
+  >>> groups['GB'] = gb
+  >>> gb.principals = ['group.GA']
+
+  >>> gc = zope.app.pas.groupfolder.GroupInformation("Group C")
+  >>> groups['GC'] = gc
+  >>> gc.principals = ['group.GA']
+
+  >>> gd = zope.app.pas.groupfolder.GroupInformation("Group D")
+  >>> groups['GD'] = gd
+  >>> gd.principals = ['group.GA', 'group.GB']
+
+  >>> ga.principals = ['p1']
+
 Group folders provide a very simple search interface.  They perform
 simple string searches on group titles and descriptions.
 
-  >>> list(groups.search({'search': 'grou'}))
-  [u'group.G1', u'group.G2']
+  >>> list(groups.search({'search': 'grou'})) # doctest: +NORMALIZE_WHITESPACE
+  [u'group.G1', u'group.G2',
+   u'group.GA', u'group.GB', u'group.GC', u'group.GD']
 
   >>> list(groups.search({'search': 'two'}))
   [u'group.G2']



More information about the Zope3-Checkins mailing list