[CMF-checkins] SVN: CMF/branches/1.4/C Backport from CMF 1.5

Sidnei da Silva sidnei at enfoldsystems.com
Mon Sep 19 09:39:53 EDT 2005


Log message for revision 38517:
  
  Backport from CMF 1.5
      - CMFCore.MemberDataTool: Fixed the pruneMemberData functionality in the
        ZMI: Now it is enough to press the button once.
  

Changed:
  U   CMF/branches/1.4/CHANGES.txt
  U   CMF/branches/1.4/CMFCore/MemberDataTool.py
  U   CMF/branches/1.4/CMFCore/tests/test_MemberDataTool.py

-=-
Modified: CMF/branches/1.4/CHANGES.txt
===================================================================
--- CMF/branches/1.4/CHANGES.txt	2005-09-19 12:29:58 UTC (rev 38516)
+++ CMF/branches/1.4/CHANGES.txt	2005-09-19 13:39:53 UTC (rev 38517)
@@ -2,6 +2,9 @@
 
   Bug Fixes
 
+    - CMFCore.MemberDataTool: Fixed the pruneMemberData functionality in the
+      ZMI: Now it is enough to press the button once.
+
     - DCWorkflow Guard check now uses utils._checkPermission instead of Zope's
       checkPermission (allows using proxy roles)
 

Modified: CMF/branches/1.4/CMFCore/MemberDataTool.py
===================================================================
--- CMF/branches/1.4/CMFCore/MemberDataTool.py	2005-09-19 12:29:58 UTC (rev 38516)
+++ CMF/branches/1.4/CMFCore/MemberDataTool.py	2005-09-19 13:39:53 UTC (rev 38517)
@@ -139,14 +139,12 @@
         and delete anything not in acl_users
         '''
         membertool= getToolByName(self, 'portal_membership')
-        members   = self._members
+        members = self._members
         user_list = membertool.listMemberIds()
 
-        for tuple in members.items():
-            member_name = tuple[0]
-            member_obj  = tuple[1]
-            if member_name not in user_list:
-                del members[member_name]
+        for member_id in list(members.keys()):
+            if member_id not in user_list:
+                del members[member_id]
 
     security.declarePrivate('wrapUser')
     def wrapUser(self, u):
@@ -188,6 +186,17 @@
         '''
         self._members[id] = aq_base(m)
 
+    security.declarePrivate('deleteMemberData')
+    def deleteMemberData(self, member_id):
+        """ Delete member data of specified member.
+        """
+        members = self._members
+        if members.has_key(member_id):
+            del members[member_id]
+            return 1
+        else:
+            return 0
+
 InitializeClass(MemberDataTool)
 
 

Modified: CMF/branches/1.4/CMFCore/tests/test_MemberDataTool.py
===================================================================
--- CMF/branches/1.4/CMFCore/tests/test_MemberDataTool.py	2005-09-19 12:29:58 UTC (rev 38516)
+++ CMF/branches/1.4/CMFCore/tests/test_MemberDataTool.py	2005-09-19 13:39:53 UTC (rev 38517)
@@ -7,10 +7,48 @@
     # for Zope versions before 2.6.0
     from Interface import verify_class_implementation as verifyClass
 
+import Acquisition
 from Products.CMFCore.MemberDataTool import MemberDataTool
 from Products.CMFCore.MemberDataTool import MemberData
 
+class DummyUserFolder(Acquisition.Implicit):
 
+    def __init__(self):
+        self._users = {}
+
+    def _addUser(self, user):
+        self._users[user.getUserName()] = user
+
+    def userFolderEditUser(self, name, password, roles, domains):
+        user = self._users[name]
+        if password is not None:
+            user.__ = password
+        # Emulate AccessControl.User's stupid behavior (should test None)
+        user.roles = tuple(roles)
+        user.domains = tuple(domains)
+
+    def getUsers(self):
+        return self._users.values()
+
+
+class DummyUser(Acquisition.Implicit):
+
+    def __init__(self, name, password, roles, domains):
+        self.name = name
+        self.__ = password
+        self.roles = tuple(roles)
+        self.domains = tuple(domains)
+
+    def getUserName(self):
+        return self.name
+
+    def getRoles(self):
+        return self.roles + ('Authenticated',)
+
+    def getDomains(self):
+        return self.domains
+
+
 class MemberDataToolTests(TestCase):
 
     def test_interface(self):
@@ -22,6 +60,46 @@
         verifyClass(IMemberDataTool, MemberDataTool)
         verifyClass(IActionProvider, MemberDataTool)
 
+    def test_deleteMemberData(self):
+        tool = MemberDataTool()
+        tool.registerMemberData('Dummy', 'user_foo')
+        self.failUnless( tool._members.has_key('user_foo') )
+        self.failUnless( tool.deleteMemberData('user_foo') )
+        self.failIf( tool._members.has_key('user_foo') )
+        self.failIf( tool.deleteMemberData('user_foo') )
+
+    def test_pruneMemberData(self):
+        # This needs a tad more setup
+        from OFS.Folder import Folder
+        from Products.CMFCore.MembershipTool import MembershipTool
+        folder = Folder('test')
+        folder._setObject('portal_memberdata', MemberDataTool())
+        folder._setObject('portal_membership', MembershipTool())
+        folder._setObject('acl_users', DummyUserFolder())
+        tool = folder.portal_memberdata
+
+        # Create some members
+        for i in range(20):
+            tool.registerMemberData( 'Dummy_%i' % i
+                                   , 'user_foo_%i' % i
+                                   )
+
+        # None of these fake members are in the user folder, which means
+        # there are 20 members and 20 "orphans"
+        contents = tool.getMemberDataContents()
+        info_dict = contents[0]
+        self.assertEqual(info_dict['member_count'], 20)
+        self.assertEqual(info_dict['orphan_count'], 20)
+
+        # Calling the prune method should delete all orphans, so we end
+        # up with no members in the tool.
+        tool.pruneMemberDataContents()
+        contents = tool.getMemberDataContents()
+        info_dict = contents[0]
+        self.assertEqual(info_dict['member_count'], 0)
+        self.assertEqual(info_dict['orphan_count'], 0)
+
+
 class MemberDataTests(TestCase):
 
     def test_interface(self):



More information about the CMF-checkins mailing list