Commit f33b2e8a 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 08960254
Pipeline #17946 failed with stage
in 0 seconds
......@@ -153,15 +153,14 @@ for base_category, category_list in category_list_spreadsheet_dict.iteritems():
message="Kept category",
)
kept_category_counter += 1
elif hasRelation(category):
# TODO: add a dialog parameter allowing to delete this path
elif hasRelation(category) and existing_category_list != 'force_delete':
report(
level='warning',
field_type='Warning',
field_category=category.getRelativeUrl(),
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
deleted_category_counter += 1
report(
......
......@@ -228,9 +228,13 @@
<string>expire</string>
</tuple>
<tuple>
<string>Delete Categories</string>
<string>Delete Categories (Unless They are Used)</string>
<string>delete</string>
</tuple>
<tuple>
<string>Delete Categories (Even if They are Used)</string>
<string>force_delete</string>
</tuple>
</list>
</value>
</item>
......
......@@ -664,6 +664,37 @@ class TestOOoImport(TestOOoImportMixin):
self.assertEqual('FR', france.getCodification())
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):
# tests simple use of CategoryTool_importCategoryFile script
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