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 nexedi/erp5!867
parent 2aca4f96
...@@ -245,3 +245,15 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase): ...@@ -245,3 +245,15 @@ class TestShaDir(ShaDirMixin, ERP5TypeTestCase):
result, document3 = self.getInformation() result, document3 = self.getInformation()
self.assertEqual(1, len(json.loads(document3))) 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 @@ ...@@ -6,10 +6,22 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>testShaDir</string> </value> <value> <string>testShaDir</string> </value>
</item> </item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
<value> <string>test.erp5.testShaDir</string> </value> <value> <string>test.erp5.testShaDir</string> </value>
...@@ -31,13 +43,28 @@ ...@@ -31,13 +43,28 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <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> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -50,7 +77,7 @@ ...@@ -50,7 +77,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -59,7 +86,7 @@ ...@@ -59,7 +86,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle> </pickle>
......
...@@ -65,7 +65,7 @@ class VirtualFolderMixin: ...@@ -65,7 +65,7 @@ class VirtualFolderMixin:
XXX XXX
""" """
tv = getTransactionalVariable() tv = getTransactionalVariable()
key = (id, ) key = 'VirtualFolderMixin', self.getPhysicalPath(), id
tv[key] = ob.__of__(self).getRelativeUrl() tv[key] = ob.__of__(self).getRelativeUrl()
method = getattr(self, 'Base_setObject', None) method = getattr(self, 'Base_setObject', None)
...@@ -80,7 +80,8 @@ class VirtualFolderMixin: ...@@ -80,7 +80,8 @@ class VirtualFolderMixin:
XXX XXX
""" """
tv = getTransactionalVariable() 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: if document_url is not None:
return self.getPortalObject().unrestrictedTraverse(document_url) 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