[Checkins] SVN: CMF/trunk/C - CMFCore.MembershipTool: Fixed inconsistent behavior where member lookup

Jens Vagelpohl jens at dataflake.org
Sat Feb 3 10:03:34 EST 2007


Log message for revision 72352:
  - CMFCore.MembershipTool: Fixed inconsistent behavior where member lookup
    would take all user folders up to the Zope root into account whereas
    member area creation would not.
  

Changed:
  U   CMF/trunk/CHANGES.txt
  U   CMF/trunk/CMFCore/MembershipTool.py
  U   CMF/trunk/CMFCore/tests/test_MembershipTool.py

-=-
Modified: CMF/trunk/CHANGES.txt
===================================================================
--- CMF/trunk/CHANGES.txt	2007-02-03 12:40:02 UTC (rev 72351)
+++ CMF/trunk/CHANGES.txt	2007-02-03 15:03:33 UTC (rev 72352)
@@ -11,6 +11,10 @@
 
   Bug Fixes
 
+    - CMFCore.MembershipTool: Fixed inconsistent behavior where member lookup
+      would take all user folders up to the Zope root into account whereas
+      member area creation would not.
+
     - CMFDefault.File and CMFDefault.Image: Restored ZMI Cache tab which was
       lost in CMF 1.6.
 

Modified: CMF/trunk/CMFCore/MembershipTool.py
===================================================================
--- CMF/trunk/CMFCore/MembershipTool.py	2007-02-03 12:40:02 UTC (rev 72351)
+++ CMF/trunk/CMFCore/MembershipTool.py	2007-02-03 15:03:33 UTC (rev 72352)
@@ -255,9 +255,9 @@
             member_id = user_id
         else:
             if _checkPermission(ManageUsers, self):
-                member = self.acl_users.getUserById(member_id, None)
-                if member:
-                    member = member.__of__(self.acl_users)
+                uf = self._huntUserFolder(member_id, self)
+                if uf:
+                    member = uf.getUserById(member_id).__of__(uf)
                 else:
                     raise ValueError('Member %s does not exist' % member_id)
             else:
@@ -351,19 +351,28 @@
             user = self.wrapUser(user)
         return user
 
-    def _huntUser(self, username, context):
-        """Find user in the hierarchy starting from bottom level 'start'.
+    def _huntUserFolder(self, username, context):
+        """Find userfolder containing user in the hierarchy
+           starting from context
         """
         uf = context.acl_users
         while uf is not None:
             user = uf.getUserById(username)
             if user is not None:
-                return user
+                return uf
             container = aq_parent(aq_inner(uf))
             parent = aq_parent(aq_inner(container))
             uf = getattr(parent, 'acl_users', None)
         return None
 
+    def _huntUser(self, username, context):
+        """Find user in the hierarchy of userfolders
+           starting from context
+        """
+        uf = self._huntUserFolder(username, context)
+        if uf is not None:
+            return uf.getUserById(username)
+
     def __getPUS(self):
         # Gets something we can call getUsers() and getUserNames() on.
         acl_users = self.acl_users

Modified: CMF/trunk/CMFCore/tests/test_MembershipTool.py
===================================================================
--- CMF/trunk/CMFCore/tests/test_MembershipTool.py	2007-02-03 12:40:02 UTC (rev 72351)
+++ CMF/trunk/CMFCore/tests/test_MembershipTool.py	2007-02-03 15:03:33 UTC (rev 72352)
@@ -109,6 +109,30 @@
                           'CMF Collector issue #162 (LocalRoles broken): %s'
                           % str( f.get_local_roles() ) )
 
+    def test_createMemberArea_chained(self):
+        LOCAL_USER_ID = 'user_foo'
+        NONLOCAL_USER_ID = 'user_bar'
+
+        self.root._setObject( 'folder', Folder('folder') )
+        site = self._makeSite( self.root.folder )
+        mtool = site.portal_membership
+        members = site._setObject( 'Members', PortalFolder('Members') )
+        wtool = site._setObject( 'portal_workflow', DummyTool() )
+
+        local_uf = DummyUserFolder()
+        delattr( local_uf, NONLOCAL_USER_ID )
+        acl_users = site._setObject('acl_users', local_uf)
+
+        nonlocal_uf = DummyUserFolder()
+        delattr( nonlocal_uf, LOCAL_USER_ID )
+        self.root.folder._setObject('acl_users', nonlocal_uf)
+
+        newSecurityManager(None, acl_users.all_powerful_Oz)
+        mtool.createMemberArea( NONLOCAL_USER_ID )
+        self.failUnless( hasattr(members.aq_self, NONLOCAL_USER_ID ) )
+        mtool.createMemberArea( LOCAL_USER_ID )
+        self.failUnless( hasattr(members.aq_self, LOCAL_USER_ID ) )
+
     def test_deleteMembers(self):
         site = self._makeSite()
         mtool = site.portal_membership



More information about the Checkins mailing list