[CMF-checkins] SVN: CMF/branches/2.0/CMFCore/ - User folders not supporting the userFolderDelUsers API, such as PAS,

Jens Vagelpohl jens at dataflake.org
Sat Jun 2 07:30:35 EDT 2007


Log message for revision 76151:
  - User folders not supporting the userFolderDelUsers API, such as PAS,
    would raise an unhelpful error when members were deleted using the
    portal_membership tool.
    (http://www.zope.org/Collectors/CMF/481)
  
  

Changed:
  U   CMF/branches/2.0/CMFCore/MembershipTool.py
  U   CMF/branches/2.0/CMFCore/tests/test_MembershipTool.py

-=-
Modified: CMF/branches/2.0/CMFCore/MembershipTool.py
===================================================================
--- CMF/branches/2.0/CMFCore/MembershipTool.py	2007-06-02 11:29:49 UTC (rev 76150)
+++ CMF/branches/2.0/CMFCore/MembershipTool.py	2007-06-02 11:30:35 UTC (rev 76151)
@@ -488,7 +488,7 @@
                     member_ids.remove(member_id)
             try:
                 acl_users.userFolderDelUsers(member_ids)
-            except (NotImplementedError, 'NotImplemented'):
+            except (AttributeError, NotImplementedError, 'NotImplemented'):
                 raise NotImplementedError('The underlying User Folder '
                                          'doesn\'t support deleting members.')
         else:

Modified: CMF/branches/2.0/CMFCore/tests/test_MembershipTool.py
===================================================================
--- CMF/branches/2.0/CMFCore/tests/test_MembershipTool.py	2007-06-02 11:29:49 UTC (rev 76150)
+++ CMF/branches/2.0/CMFCore/tests/test_MembershipTool.py	2007-06-02 11:30:35 UTC (rev 76151)
@@ -134,6 +134,40 @@
         self.failIf( mdtool._members.has_key('user_foo') )
         self.failIf( hasattr(members.aq_self, 'user_foo') )
 
+    def test_deleteMembersUnsupported(self):
+        # Quite a few user folders do not support the deletion API
+        # http://www.zope.org/Collectors/CMF/481
+        # Make sure we get the right exception
+        site = self._makeSite()
+        mtool = site.portal_membership
+        members = site._setObject( 'Members', PortalFolder('Members') )
+        acl_users = site._setObject( 'acl_users', DummyUserFolder() )
+        utool = site._setObject( 'portal_url', DummyTool() )
+        wtool = site._setObject( 'portal_workflow', DummyTool() )
+        mdtool = site._setObject( 'portal_memberdata', MemberDataTool() )
+        newSecurityManager(None, acl_users.all_powerful_Oz)
+
+        self.assertEqual( acl_users.getUserById('user_foo'),
+                          acl_users.user_foo )
+        mtool.createMemberArea('user_foo')
+        self.failUnless( hasattr(members.aq_self, 'user_foo') )
+        mdtool.registerMemberData('Dummy', 'user_foo')
+        self.failUnless( mdtool._members.has_key('user_foo') )
+
+        # Fake an incompatible user folder by deleting the class method
+        deletion_method = DummyUserFolder.userFolderDelUsers
+        del DummyUserFolder.userFolderDelUsers
+        self.assertRaises( NotImplementedError
+                         , mtool.deleteMembers
+                         , ('user_foo',)
+                         )
+        self.failUnless( acl_users.getUserById('user_foo', None) )
+        self.failUnless( mdtool._members.has_key('user_foo') )
+        self.failUnless( hasattr(members.aq_self, 'user_foo') )
+
+        # Cleanup
+        DummyUserFolder.userFolderDelUsers = deletion_method
+
     def test_getMemberById_nonesuch(self):
         INVALID_USER_ID = 'nonesuch'
 



More information about the CMF-checkins mailing list