Commit 8577cb2c authored by Georgios Dagkakis's avatar Georgios Dagkakis

BusinessTemplate: Remove user_id when a document that is ERP5User is exported and

re-generate on installation
parent e9cc6f29
......@@ -642,7 +642,13 @@ class BaseTemplateItem(Implicit, Persistent):
for attr in obj.__dict__.keys():
if attr in attr_set or attr.startswith('_cache_cookie_'):
delattr(obj, attr)
portal_type = getattr(obj, 'portal_type', None)
if portal_type is not None:
portal_type_value = self.getPortalObject().portal_types.get(portal_type, None)
if portal_type_value is not None \
and 'ERP5User' in portal_type_value.getTypePropertySheetList() \
and 'user_id' in obj.__dict__.keys():
delattr(obj, 'user_id')
if classname == 'PDFForm':
if not obj.getProperty('business_template_include_content', 1):
obj.deletePdfContent()
......@@ -1464,6 +1470,19 @@ class ObjectTemplateItem(BaseTemplateItem):
l=local_role_dict.setdefault(userid, [])
l.append('Owner')
# END:part of ERP5Type.CopySupport.manage_afterClone
# Reset user_id if needed
portal_type = getattr(obj, 'portal_type', None)
if portal_type is not None:
portal_type_value = portal.portal_types.get(portal_type, None)
if portal_type_value is not None \
and 'ERP5User' in portal_type_value.getTypePropertySheetList():
aq_base(obj).user_id = '%s%i' % (
portal_type[0],
portal.portal_ids.generateNewId(
id_group='user_id',
id_generator='non_continuous_integer_increasing',
),
)
del obj.isIndexable
if getattr(aq_base(obj), 'reindexObject', None) is not None:
obj.reindexObject()
......
......@@ -7324,6 +7324,47 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.assertEqual(True, method("aa/bb"))
self.assertEqual(True, method("aa/bb/cc"))
def testRemovalOfUserIdOfPersonInExport(self):
'''
Checks that when a Business Template with a Person path is exported
the user_id is stripped and when it is installed a new one is created
'''
export_dir = tempfile.mkdtemp()
try:
sequence = Sequence()
self.stepCreateNewBusinessTemplate(sequence=sequence)
business_template = sequence.get("export_bt")
person_id = 'test_person'
person = self.portal.person_module.newContent(
id=person_id,
portal_type='Person'
)
self.assertTrue(person.hasUserId())
original_user_id = person.getUserId()
business_template.edit(template_path_list=['person_module/' + person.getId()])
business_template.build()
business_template.export(path=export_dir, local=True)
template_tool = self.portal.portal_templates
template_tool.manage_delObjects(business_template.getId())
self.portal.person_module.manage_delObjects(person_id)
person_xml_file = open(export_dir + '/PathTemplateItem/person_module/%s.xml' % person_id, mode='r')
person_xml = person_xml_file.read()
person_xml_file.close()
# Check that user_id is not exported
self.assertNotIn('>user_id<', person_xml)
self.assertNotIn('>%s<' % original_user_id, person_xml)
import_template = template_tool.download(url='file:' + export_dir)
self.assertEqual(import_template.getPortalType(), 'Business Template')
# Check that in installation a new user_id is created
import_template.install()
person_value = self.portal.person_module[person_id]
self.assertTrue(person_value.hasUserId())
new_user_id = person_value.getUserId()
self.assertNotEqual(new_user_id, original_user_id)
self.assertEqual(new_user_id[0], 'P')
finally:
shutil.rmtree(export_dir)
def stepCreateDocumentComponentWhichTriggersAnOperationWhenSubDocumentIsAdded(
self, sequence=None, **kw):
from textwrap import dedent
......
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