Commit 1bce8563 authored by Arnaud Fontaine's avatar Arnaud Fontaine

Folder: Allow to create temp_objects anywhere, without checking if it's in...

Folder: Allow to create temp_objects anywhere, without checking if it's in allowed types for that Portal Type.

Until now, creating a temp_object with newContent() required for the temp_object
to be in allowed types. However, this was inconsistent with (now deprecated)
newTemp*() functions (calling directly constructInstance()) not having such
limitations.

Besides lifting such limitation being needed to properly replace newTemp*() calls,
portal_trash.newContent() pattern is already commonly used used here meaning there
is a real use case.

This also fixes testBanking* failures: newTempCashDeliveryLine() created objects
on 'Cash Inventory' and latter call Delivery.isAccountable() which does not exist on
portal_trash.

See also 04b49859.

/reviewed-on !1025
parent 299bc417
......@@ -63,7 +63,7 @@ class CashInventory(Inventory, BankingOperation):
setting another kind of temp delivery line.
"""
def newTempCashDeliveryLine(self, inventory_id):
return self.getPortalObject().portal_trash.newContent(
return self.newContent(
portal_type='Cash Delivery Line',
temp_object=True,
id=inventory_id)
......
......@@ -201,7 +201,7 @@ class FolderMixIn(ExtensionClass.Base):
portal_type = allowed_content_type_list[0].id
else:
raise ValueError('Creation disallowed')
else:
elif not temp_object:
type_info = pt.getTypeInfo(container)
if type_info is not None and not type_info.allowType(portal_type) and \
'portal_trash' not in container.getPhysicalPath():
......
......@@ -211,6 +211,8 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
def test_03_NewTempObject(self):
portal = self.portal
# WARNING: `newTemp<PortalType>(self, ID)` is deprecated in favor of
# `self.newContent(portal_type=<PortalType>, temp_object=True, id=ID)`
from Products.ERP5Type.Document import newTempPerson
o = newTempPerson(portal, 1.2)
o.setTitle('toto')
......@@ -253,14 +255,46 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
self.assertEqual(b.isTempObject(), 1)
self.assertEqual(b.getId(), str(2))
# Test newContent with the temp_object parameter and without ID
o = portal.person_module.newContent(portal_type="Person", temp_object=1)
o.setTitle('bar')
self.assertEqual(o.getTitle(), 'bar')
self.assertEqual(o.isTempObject(), 1)
a = o.newContent(id=1, portal_type="Telephone", temp_object=1)
self.assertEqual(str(a.getId()), str(1))
self.assertEqual(a.isTempObject(), 1)
b = o.newContent(id=2, portal_type="Telephone")
self.assertEqual(b.isTempObject(), 1)
self.assertEqual(b.getId(), str(2))
# Test newContent with the temp_object parameter and where a non-temp_object would not be allowed
o = portal.person_module.newContent(portal_type="Organisation", temp_object=1)
o.setTitle('bar')
self.assertEqual(o.getTitle(), 'bar')
self.assertEqual(o.isTempObject(), 1)
a = o.newContent(id=1, portal_type="Telephone", temp_object=1)
self.assertEqual(str(a.getId()), str(1))
self.assertEqual(a.isTempObject(), 1)
b = o.newContent(id=2, portal_type="Telephone")
self.assertEqual(b.isTempObject(), 1)
self.assertEqual(b.getId(), str(2))
# check we can create temp object without specific roles/permissions
self.logout()
self.loginWithNoRole()
## newTemp<PORTAL_TYPE>
o = newTempOrganisation(portal.organisation_module,'b')
self.assertEqual(o.isTempObject(), 1)
a = o.newContent(portal_type = 'Telephone')
self.assertEqual(a.isTempObject(), 1)
self.assertEqual(a, guarded_getattr(o, a.getId()))
## newContent
o = portal.organisation_module.newContent(portal_type='Organisation',
temp_object=1)
self.assertEqual(o.isTempObject(), 1)
a = o.newContent(portal_type = 'Telephone')
self.assertEqual(a.isTempObject(), 1)
self.assertEqual(a, guarded_getattr(o, a.getId()))
self.logout()
self.login()
......
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