Commit 5fa7c105 authored by Jérome Perrin's avatar Jérome Perrin

Change underlying implementation of id changes to support
updateRelatedContent on cut & paste.



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@7613 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 6f005ea1
...@@ -156,6 +156,13 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -156,6 +156,13 @@ class TestCMFCategory(ERP5TypeTestCase):
portal_categories[bc].setAcquisitionSyncValue(1) portal_categories[bc].setAcquisitionSyncValue(1)
portal_categories[bc].setFallbackBaseCategoryList(['subordination']) portal_categories[bc].setFallbackBaseCategoryList(['subordination'])
def beforeTearDown(self):
"""Clean up."""
# categories
for bc in ('region', 'subordination', 'gender'):
bc_obj = self.getPortal().portal_categories[bc]
bc_obj.manage_delObjects()
def login(self, quiet=0, run=run_all_test): def login(self, quiet=0, run=run_all_test):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
uf._doAddUser('seb', '', ['Manager'], []) uf._doAddUser('seb', '', ['Manager'], [])
...@@ -374,18 +381,16 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -374,18 +381,16 @@ class TestCMFCategory(ERP5TypeTestCase):
LOG('Testing... ',0,'Category Renaming') LOG('Testing... ',0,'Category Renaming')
portal = self.getPortal() portal = self.getPortal()
france = portal.portal_categories.resolveCategory('region/europe/west/france') france = portal.portal_categories.resolveCategory(
'region/europe/west/france')
self.assertNotEqual(france, None) self.assertNotEqual(france, None)
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion('europe/west/france') p1.setRegion('europe/west/france')
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
west = portal.portal_categories.resolveCategory('region/europe/west') west = portal.portal_categories.resolveCategory('region/europe/west')
# To be able to change the object id, we must first commit the transaction,
# because in Zope we are not able to create an object and modify its id
# in the same transaction
west.setId("ouest") west.setId("ouest")
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
...@@ -393,7 +398,68 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -393,7 +398,68 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEqual(west, self.assertEqual(west,
portal.portal_categories.resolveCategory('region/europe/ouest')) portal.portal_categories.resolveCategory('region/europe/ouest'))
self.assertEqual(p1.getRegion(), 'europe/ouest/france') self.assertEqual(p1.getRegion(), 'europe/ouest/france')
self.failUnless(p1 in west.getRegionRelatedValueList()) self.failUnless(p1 in west.getRegionRelatedValueList())
def test_13b_RenameCategoryUsingCutAndPaste(self, quiet=0, run=run_all_test) :
if not run: return
if not quiet:
ZopeTestCase._print('\n Test Category Renaming with cut n paste')
LOG('Testing... ',0,'Category Renaming')
portal = self.getPortal()
france = portal.portal_categories.resolveCategory(
'region/europe/west/france')
self.assertNotEqual(france, None)
p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion('europe/west/france')
get_transaction().commit()
self.tic()
europe = portal.portal_categories.resolveCategory('region/europe')
west = europe.west
cb_data = europe.manage_cutObjects(['west'])
portal.portal_categories.region.manage_pasteObjects(cb_data)
get_transaction().commit()
self.tic()
self.assertEqual(west,
portal.portal_categories.resolveCategory('region/west'))
self.assertEqual(p1.getRegion(), 'west/france')
self.failUnless(p1 in west.getRegionRelatedValueList())
def test_13c_RenameCategoryUsingCutAndPasteButNotCopy(
self, quiet=0, run=run_all_test) :
if not run: return
if not quiet:
ZopeTestCase._print('\n Test Category Renaming with cut n paste, '
'copy n paste doesnt change')
LOG('Testing... ',0,'Category Renaming')
portal = self.getPortal()
france = portal.portal_categories.resolveCategory(
'region/europe/west/france')
self.assertNotEqual(france, None)
p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion('europe/west/france')
get_transaction().commit()
self.tic()
europe = portal.portal_categories.resolveCategory('region/europe')
west = europe.west
cb_data = europe.manage_copyObjects(['west'])
portal.portal_categories.region.manage_pasteObjects(cb_data)
get_transaction().commit()
self.tic()
self.assertEqual(west,
portal.portal_categories.resolveCategory('region/europe/west'))
self.assertEqual(p1.getRegion(), 'europe/west/france')
# we are not member of the copy
self.failUnless('west/france' not in p1.getRegionList())
self.failUnless(p1 in west.getRegionRelatedValueList())
def test_14_MultiplePortalTypes(self, quiet=0, run=run_all_test) : def test_14_MultiplePortalTypes(self, quiet=0, run=run_all_test) :
""" Checks that categories support different value per portal_type, """ Checks that categories support different value per portal_type,
......
...@@ -997,20 +997,20 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ): ...@@ -997,20 +997,20 @@ class Base( CopyContainer, PortalContent, ActiveObject, ERP5PropertyManager ):
""" """
# Do not rename until everything flushed # Do not rename until everything flushed
self.recursiveFlushActivity(invoke=1) self.recursiveFlushActivity(invoke=1)
previous_relative_url = self.getRelativeUrl()
tryMethodCallWithTemporaryPermission(self, 'Copy or Move', tryMethodCallWithTemporaryPermission(self, 'Copy or Move',
self.aq_parent.manage_renameObject, (self.id, id), {}, CopyError) self.aq_parent.manage_renameObject, (self.id, id), {}, CopyError)
new_relative_url = self.getRelativeUrl()
if reindex: if reindex:
self.flushActivity(invoke=1) # Required if we wish that news ids appear instantly # Required if we wish that news ids appear instantly
self.activate().updateRelatedContent(previous_relative_url, new_relative_url) self.flushActivity(invoke=1)
security.declareProtected( Permissions.ModifyPortalContent, 'updateRelatedContent' ) security.declareProtected( Permissions.ModifyPortalContent,
'updateRelatedContent' )
def updateRelatedContent(self, previous_category_url, new_category_url): def updateRelatedContent(self, previous_category_url, new_category_url):
""" """
updateRelatedContent is implemented by portal_categories updateRelatedContent is implemented by portal_categories
""" """
self._getCategoryTool().updateRelatedContent(self, previous_category_url, new_category_url) self._getCategoryTool().updateRelatedContent(self,
previous_category_url, new_category_url)
security.declareProtected(Permissions.ModifyPortalContent, 'edit') security.declareProtected(Permissions.ModifyPortalContent, 'edit')
def edit(self, REQUEST=None, force_update=0, reindex_object=1, **kw): def edit(self, REQUEST=None, force_update=0, reindex_object=1, **kw):
......
...@@ -82,7 +82,10 @@ class CopyContainer: ...@@ -82,7 +82,10 @@ class CopyContainer:
def _updateInternalRelatedContent(self, local_self, path, new_id): def _updateInternalRelatedContent(self, local_self, path, new_id):
""" """
Search for categories starting with path in local_self and its subobjects, and replaces the last common item in category paths by new_id. Search for categories starting with path in local_self and its
subobjects, and replaces the last common item in category paths
by new_id.
Example : Example :
category : "a/b/c/d/e" category : "a/b/c/d/e"
path : "a/b/c" path : "a/b/c"
...@@ -104,7 +107,8 @@ class CopyContainer: ...@@ -104,7 +107,8 @@ class CopyContainer:
security.declareProtected( Permissions.ModifyPortalContent, 'manage_renameObject' ) security.declareProtected( Permissions.ModifyPortalContent, 'manage_renameObject' )
def manage_renameObject(self, id=None, new_id=None, REQUEST=None): def manage_renameObject(self, id=None, new_id=None, REQUEST=None):
"""manage renaming an object while keeping coherency for contained and linked to objects inside the renamed object """manage renaming an object while keeping coherency for contained
and linked to objects inside the renamed object
""" """
ob=self.restrictedTraverse(id) ob=self.restrictedTraverse(id)
...@@ -315,6 +319,26 @@ class CopyContainer: ...@@ -315,6 +319,26 @@ class CopyContainer:
if catalog is not None: if catalog is not None:
catalog.moveObject(self, idxs=idxs) catalog.moveObject(self, idxs=idxs)
def _notifyOfCopyTo(self, container, op=0):
"""Overiden to track object cut and pastes, and update related
content accordingly.
The op variable is 0 for a copy, 1 for a move.
"""
if op == 1: # move
self._v_category_url_before_move = self.getRelativeUrl()
def _postCopy(self, container, op=0):
# Called after the copy is finished to accomodate special cases.
# in our case, we want to notify the category system that our path
# changed, so that it updates related objects.
if op == 1:
old_url = getattr(self, '_v_category_url_before_move', None)
if old_url is not None:
container.activate().updateRelatedContent(
old_url,
self.getRelativeUrl())
#### Helper methods #### Helper methods
def tryMethodCallWithTemporaryPermission(context, permission, method, def tryMethodCallWithTemporaryPermission(context, permission, method,
......
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