[Checkins] SVN: Products.GenericSetup/trunk/Products/GenericSetup/ Avoid even an explicit purge of the rolemap if no XML file is present

Tres Seaver tseaver at palladion.com
Mon Oct 6 21:34:49 EDT 2008


Log message for revision 91825:
  Avoid even an explicit purge of the rolemap if no XML file is present
  
  - See https://bugs.launchpad.net/zope-cmf/+bug/279294
  
  

Changed:
  U   Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
  U   Products.GenericSetup/trunk/Products/GenericSetup/rolemap.py
  U   Products.GenericSetup/trunk/Products/GenericSetup/tests/test_rolemap.py

-=-
Modified: Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2008-10-07 01:34:32 UTC (rev 91824)
+++ Products.GenericSetup/trunk/Products/GenericSetup/CHANGES.txt	2008-10-07 01:34:49 UTC (rev 91825)
@@ -4,6 +4,9 @@
 GenericSetup 1.5.0 (unreleased)
 -------------------------------
 
+- Avoid even an explicit purge of the rolemap if no XML file is present
+  in a given context.  (https://bugs.launchpad.net/zope-cmf/+bug/279294)
+
 - Component registry import: Add the ability to unregister a component
   by specifying the "remove" attribute inside a utility node.
   (https://bugs.launchpad.net/zope-cmf/+bug/161728)

Modified: Products.GenericSetup/trunk/Products/GenericSetup/rolemap.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/rolemap.py	2008-10-07 01:34:32 UTC (rev 91824)
+++ Products.GenericSetup/trunk/Products/GenericSetup/rolemap.py	2008-10-07 01:34:49 UTC (rev 91825)
@@ -63,21 +63,21 @@
     encoding = context.getEncoding()
     logger = context.getLogger('rolemap')
 
-    if context.shouldPurge():
+    text = context.readDataFile( _FILENAME )
 
-        items = site.__dict__.items()
+    if text is not None:
 
-        for k, v in items: # XXX: WAAA
+        if context.shouldPurge():
 
-            if k == '__ac_roles__':
-                delattr( site, k )
+            items = site.__dict__.items()
 
-            if k.startswith( '_' ) and k.endswith( '_Permission' ):
-                delattr( site, k )
+            for k, v in items: # XXX: WAAA
 
-    text = context.readDataFile( _FILENAME )
+                if k == '__ac_roles__':
+                    delattr( site, k )
 
-    if text is not None:
+                if k.startswith( '_' ) and k.endswith( '_Permission' ):
+                    delattr( site, k )
 
         rc = RolemapImportConfigurator(site, encoding)
         rolemap_info = rc.parseXML( text )

Modified: Products.GenericSetup/trunk/Products/GenericSetup/tests/test_rolemap.py
===================================================================
--- Products.GenericSetup/trunk/Products/GenericSetup/tests/test_rolemap.py	2008-10-07 01:34:32 UTC (rev 91824)
+++ Products.GenericSetup/trunk/Products/GenericSetup/tests/test_rolemap.py	2008-10-07 01:34:49 UTC (rev 91825)
@@ -469,6 +469,44 @@
 
     layer = ExportImportZCMLLayer
 
+    def test_existing_roles_missing_xml_doesnt_purge(self):
+        # LP # 279294
+        ACI = 'Access contents information'
+        VIEW = 'View'
+
+        self.app.site = Folder(id='site')
+        site = self.app.site # wrap
+        original_roles = list(getattr(site, '__ac_roles__', []))[:]
+        modified_roles = original_roles[:]
+        modified_roles.append('ZZZ')
+
+        site.__ac_roles__ = modified_roles
+        site.manage_permission(VIEW, ())
+        site.manage_permission(ACI, ('Manager', 'ZZZ'))
+
+        existing_allowed = [x['name'] for x in site.rolesOfPermission(ACI)
+                                if x['selected']]
+
+        self.assertEqual(existing_allowed, ['Manager', 'ZZZ'])
+
+        context = DummyImportContext(site, True)
+        #context._files[ 'rolemap.xml' ] = _EMPTY_EXPORT # no file!
+
+        from Products.GenericSetup.rolemap import importRolemap
+        importRolemap(context)
+
+        new_roles = list(getattr(site, '__ac_roles__', []))[:]
+
+        modified_roles.sort()
+        new_roles.sort()
+
+        self.assertEqual(modified_roles, new_roles)
+
+        new_allowed = [x['name'] for x in site.rolesOfPermission(ACI)
+                                if x['selected']]
+
+        self.assertEqual(new_allowed, existing_allowed)
+
     def test_empty_default_purge( self ):
 
         self.app.site = Folder(id='site')



More information about the Checkins mailing list