Commit ceb7d92b authored by Jérome Perrin's avatar Jérome Perrin

BusinessTemplate: don't uninstall module containing documents

uninstalling a ModuleTemplateItem containing document is usually not
what people want, so the default option should be to keep.
parent a07118b2
......@@ -7211,6 +7211,53 @@ class TestBusinessTemplate(BusinessTemplateMixin):
self.assertEqual(module_content_uid, self.portal.geek_module['1'].uid)
self.assertEqual('kept', self.portal.geek_module['1'].title)
def test_update_business_template_with_module_removed(self):
"""Updating business template with a module removed keeps the module if it contains documents
"""
self.portal.newContent(
portal_type='Person Module',
id='kept_module',
).newContent(
portal_type='Person',
id='keep',
)
self.portal.newContent(portal_type='Person Module', id='removed_module')
self.tic()
# install a bt containing two modules
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title=self.id(),
template_module_id_list=['kept_module', 'removed_module'])
bt.build()
self.tic()
bt.install()
self.tic()
# in next version, both modules are removed
bt = self.portal.portal_templates.newContent(
portal_type='Business Template',
title=self.id(),
)
bt.build()
self.tic()
export_dir = tempfile.mkdtemp()
try:
bt.export(path=export_dir, local=True)
self.tic()
new_bt = self.portal.portal_templates.download(
url='file://%s' % export_dir)
finally:
shutil.rmtree(export_dir)
self.assertEqual(
new_bt.preinstall(),
{
'removed_module': ('Removed', 'Module'),
'kept_module': ('Removed but should be kept', 'Module'),
})
def test_BusinessTemplateWithTest(self):
sequence_list = SequenceList()
sequence_string = '\
......
......@@ -3775,6 +3775,20 @@ class ModuleTemplateItem(BaseTemplateItem):
xml_data = self.generateXml(path=key)
bta.addObject(xml_data, name=key, path=path)
def preinstall(self, context, installed_item, **kw):
"""Keep modules when they are not empty.
"""
_modified_object_dict = super(ModuleTemplateItem, self).preinstall(context, installed_item, **kw)
portal = context.getPortalObject()
modified_object_dict = {}
for module_id, (action, item_class) in _modified_object_dict.items():
if action == 'Removed':
module = portal._getOb(module_id, None)
if module is not None and len(module.objectValues()):
action = 'Removed but should be kept'
modified_object_dict[module_id] = (action, item_class)
return modified_object_dict
def install(self, context, trashbin, **kw):
portal = context.getPortalObject()
update_dict = kw.get('object_to_update')
......
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