Commit 78cf1c94 authored by Jérome Perrin's avatar Jérome Perrin

core: Extend Category import with an option to force deletion of categories in use

Category spreadsheet import did not delete categories if some documents
where related to these categories. While this may make sense when using
this import in site with already some data, in many cases, we want to
be able to delete the categories, so that the result is that the category
tree match the imported spreadsheet.

This extend the dialog to support a new "force delete" mode that delete
categories even if they are use, leaving the documents using categories
with broken relations.
parent 679467c9
Pipeline #18007 passed with stage
in 0 seconds
...@@ -153,15 +153,14 @@ for base_category, category_list in category_list_spreadsheet_dict.iteritems(): ...@@ -153,15 +153,14 @@ for base_category, category_list in category_list_spreadsheet_dict.iteritems():
message="Kept category", message="Kept category",
) )
kept_category_counter += 1 kept_category_counter += 1
elif hasRelation(category): elif hasRelation(category) and existing_category_list != 'force_delete':
# TODO: add a dialog parameter allowing to delete this path
report( report(
level='warning', level='warning',
field_type='Warning', field_type='Warning',
field_category=category.getRelativeUrl(), field_category=category.getRelativeUrl(),
message="Category is used and can not be deleted or expired ", message="Category is used and can not be deleted or expired ",
) )
elif existing_category_list == 'delete': elif existing_category_list in ('delete', 'force_delete'):
recurse = False recurse = False
deleted_category_counter += 1 deleted_category_counter += 1
report( report(
......
...@@ -228,9 +228,13 @@ ...@@ -228,9 +228,13 @@
<string>expire</string> <string>expire</string>
</tuple> </tuple>
<tuple> <tuple>
<string>Delete Categories</string> <string>Delete Categories (Unless They are Used)</string>
<string>delete</string> <string>delete</string>
</tuple> </tuple>
<tuple>
<string>Delete Categories (Even if They are Used)</string>
<string>force_delete</string>
</tuple>
</list> </list>
</value> </value>
</item> </item>
......
...@@ -664,6 +664,37 @@ class TestOOoImport(TestOOoImportMixin): ...@@ -664,6 +664,37 @@ class TestOOoImport(TestOOoImportMixin):
self.assertEqual('FR', france.getCodification()) self.assertEqual('FR', france.getCodification())
self.assertEqual(1, france.getIntIndex()) self.assertEqual(1, france.getIntIndex())
def test_CategoryTool_importCategoryFileDeletionSupportForCategoriesInUse(self):
region = self.portal.portal_categories.region
region.newContent(id='dummy_region')
self.portal.person_module.newContent(
portal_type='Person',
region_value=region.dummy_region
)
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
existing_category_list='delete')
self.tic()
self.assertEqual(3, len(region))
# dummy region is in used so it was not deleted
self.assertTrue('dummy_region' in region.objectIds())
def test_CategoryTool_importCategoryFileForcedDeletionSupportForCategoriesInUse(self):
region = self.portal.portal_categories.region
region.newContent(id='dummy_region')
self.portal.person_module.newContent(
portal_type='Person',
region_value=region.dummy_region
)
self.tic()
self.portal.portal_categories.CategoryTool_importCategoryFile(
import_file=makeFileUpload('import_region_category.sxc'),
existing_category_list='force_delete')
self.tic()
self.assertEqual(2, len(region))
self.assertFalse('dummy_region' in region.objectIds())
def test_CategoryTool_importCategoryFileExpirationSupport(self): def test_CategoryTool_importCategoryFileExpirationSupport(self):
# tests simple use of CategoryTool_importCategoryFile script # tests simple use of CategoryTool_importCategoryFile script
region = self.portal.portal_categories.region region = self.portal.portal_categories.region
......
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