Commit 63183b06 authored by Thomas Gambier's avatar Thomas Gambier 🚴🏼

fix key in VirtualFolderMixin

old key was simply "id" so when a container is a VirtualFolder (like Web
Site), container._getOb("id") can return any object with id "id"
including an object outside the container.
    
Change the key to contain PhysicalPath of the container to get only
objects inside the container.
    
This actually fixes installation of some business templates with Web
Site inside.

/reviewed-on !867
parent 2aca4f96
......@@ -245,3 +245,15 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
result, document3 = self.getInformation()
self.assertEqual(1, len(json.loads(document3)))
def test_VirtualFolder_key(self):
module = self.portal.newContent(portal_type='Folder', id='test_virtual_folder_%s' % random.random())
# WebSite is a VirtualFolder
vf1 = module.newContent(portal_type='Web Site')
vf2 = module.newContent(portal_type='Web Site')
obj_id = "test_obj_%s" % random.random()
obj = vf1.newContent(portal_type='Web Section', id=obj_id)
self.assertEqual(obj, vf1._getOb(obj_id))
self.assertIsNone(vf2._getOb(obj_id, default=None))
......@@ -6,10 +6,22 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testShaDir</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testShaDir</string> </value>
......@@ -31,13 +43,28 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -50,7 +77,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -59,7 +86,7 @@
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
......
......@@ -65,7 +65,7 @@ class VirtualFolderMixin:
XXX
"""
tv = getTransactionalVariable()
key = (id, )
key = 'VirtualFolderMixin', self.getPhysicalPath(), id
tv[key] = ob.__of__(self).getRelativeUrl()
method = getattr(self, 'Base_setObject', None)
......@@ -80,7 +80,8 @@ class VirtualFolderMixin:
XXX
"""
tv = getTransactionalVariable()
document_url = tv.get((id,), None)
key = 'VirtualFolderMixin', self.getPhysicalPath(), id
document_url = tv.get(key, None)
if document_url is not None:
return self.getPortalObject().unrestrictedTraverse(document_url)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment