[Zope-Checkins] CVS: Releases/Zope/lib/python/AccessControl - Role.py:1.51 User.py:1.158

Matthew T. Kromer matt@zope.com
Tue, 2 Oct 2001 12:16:55 -0400


Update of /cvs-repository/Releases/Zope/lib/python/AccessControl
In directory cvs.zope.org:/tmp/cvs-serv4296

Modified Files:
	Role.py User.py 
Log Message:
Change for 2.5 for user local role lists.  acl_user folders now support a
maxlistusers property (managed from user folder properties tab) which
limits the number of roles that rolemanager's get_valid_users will return
before raising an OverflowError.  The DTML for listLocalRoles will insert a 
text box for user id entry if OverflowError is raised.


=== Releases/Zope/lib/python/AccessControl/Role.py 1.50 => 1.51 ===
 ListType=type([])
 
+DEFAULTMAXLISTUSERS=250
+
 def _isBeingUsedAsAMethod(self):
     return aq_get(self, '_isBeingUsedAsAMethod_', 0)
 
@@ -374,14 +376,24 @@
     def get_valid_userids(self):
         item=self
         dict={}
+        _notfound = []
         while 1:
-            if hasattr(aq_base(item), 'acl_users') and \
-               hasattr(item.acl_users, 'user_names'):
-                for name in item.acl_users.user_names():
-                    dict[name]=1
-            if not hasattr(item, 'aq_parent'):
+            aclu = getattr(aq_base(item), 'acl_users', _notfound)
+            if aclu is not _notfound:
+                mlu = getattr(aclu, 'maxlistusers', _notfound)
+                if type(mlu) != type(1): mlu = DEFAULTMAXLISTUSERS
+                if mlu < 0: raise OverflowError
+                un = getattr(aclu, 'user_names', _notfound)
+                if un is not _notfound:
+                    unl = un()
+                    # maxlistusers of 0 is list all
+                    if len(unl) > mlu and mlu != 0:
+                        raise OverflowError
+                    for name in un():
+                        dict[name]=1
+            item = getattr(item, 'aq_parent', _notfound)
+            if item is _notfound:
                 break
-            item=item.aq_parent
         keys=dict.keys()
         keys.sort()
         return tuple(keys)


=== Releases/Zope/lib/python/AccessControl/User.py 1.157 => 1.158 ===
 from base64 import decodestring
 from App.ImageFile import ImageFile
-from Role import RoleManager
+from Role import RoleManager, DEFAULTMAXLISTUSERS
 from PermissionRole import _what_not_even_god_should_do, rolesForPermissionOn
 import AuthEncoding
 from AccessControl import getSecurityManager, Unauthorized
@@ -479,6 +479,7 @@
 
     isPrincipiaFolderish=1
     isAUserFolder=1
+    maxlistusers = DEFAULTMAXLISTUSERS
 
     encrypt_passwords = 0
 
@@ -795,11 +796,17 @@
             management_view='Properties')
 
     def manage_setUserFolderProperties(self, encrypt_passwords=0,
-                                       update_passwords=0, REQUEST=None):
+                                       update_passwords=0,
+                                       maxlistusers=DEFAULTMAXLISTUSERS,
+                                       REQUEST=None):
         """
         Sets the properties of the user folder.
         """
         self.encrypt_passwords = not not encrypt_passwords
+        try:
+            self.maxlistusers = int(maxlistusers)
+        except ValueError:
+            self.maxlistusers = DEFAULTMAXLISTUSERS
         if encrypt_passwords and update_passwords:
             changed = 0
             for u in self.getUsers():