Commit 416bd068 authored by Jérome Perrin's avatar Jérome Perrin

CMFActivity: Drop messages when document is removed but another document can...

CMFActivity: Drop messages when document is removed but another document can be acquired with the same path.
Signed-off-by: Julien Muchembled's avatarJulien Muchembled <jm@nexedi.com>
parent e5dfa780
...@@ -226,10 +226,16 @@ class Message(BaseMessage): ...@@ -226,10 +226,16 @@ class Message(BaseMessage):
group_method_id = 'portal_activities/dummyGroupMethod/' + self.method_id group_method_id = 'portal_activities/dummyGroupMethod/' + self.method_id
return group_method_id + '\0' + get('group_id', '') return group_method_id + '\0' + get('group_id', '')
def _getObject(self, activity_tool):
obj = activity_tool.getPhysicalRoot()
for id in self.object_path[1:]:
obj = obj[id]
return obj
def getObject(self, activity_tool): def getObject(self, activity_tool):
"""return the object referenced in this message.""" """return the object referenced in this message."""
try: try:
obj = activity_tool.unrestrictedTraverse(self.object_path) obj = self._getObject(activity_tool)
except KeyError: except KeyError:
LOG('CMFActivity', WARNING, "Message dropped (no object found at path %r)" LOG('CMFActivity', WARNING, "Message dropped (no object found at path %r)"
% (self.object_path,), error=sys.exc_info()) % (self.object_path,), error=sys.exc_info())
...@@ -255,7 +261,7 @@ class Message(BaseMessage): ...@@ -255,7 +261,7 @@ class Message(BaseMessage):
def getObjectCount(self, activity_tool): def getObjectCount(self, activity_tool):
if 'expand_method_id' in self.activity_kw: if 'expand_method_id' in self.activity_kw:
try: try:
obj = activity_tool.unrestrictedTraverse(self.object_path) obj = self._getObject(activity_tool)
return len(getattr(obj, self.activity_kw['expand_method_id'])()) return len(getattr(obj, self.activity_kw['expand_method_id'])())
except StandardError: except StandardError:
pass pass
...@@ -373,7 +379,7 @@ Named Parameters: %r ...@@ -373,7 +379,7 @@ Named Parameters: %r
def reactivate(self, activity_tool, activity=DEFAULT_ACTIVITY): def reactivate(self, activity_tool, activity=DEFAULT_ACTIVITY):
# Reactivate the original object. # Reactivate the original object.
obj = activity_tool.unrestrictedTraverse(self.object_path) obj = self._getObject(activity_tool)
old_security_manager = getSecurityManager() old_security_manager = getSecurityManager()
try: try:
# Change user if required (TO BE DONE) # Change user if required (TO BE DONE)
......
...@@ -3432,6 +3432,31 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor): ...@@ -3432,6 +3432,31 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.activate().getTitle() organisation.activate().getTitle()
self.tic() self.tic()
def test_flushActivitiesOnDelete(self):
organisation_module = self.getOrganisationModule()
if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id)
self.tic()
organisation = organisation_module[self.company_id]
organisation_module.manage_delObjects(ids=[organisation.getId()])
organisation.activate().getTitle()
self.tic()
def test_flushActivitiesOnDeleteWithAcquierableObject(self):
organisation_module = self.getOrganisationModule()
if not organisation_module.hasContent(self.company_id):
organisation_module.newContent(id=self.company_id)
self.tic()
# Create an object with the same ID that can be acquired
self.portal._setObject(self.company_id, Organisation(self.company_id))
organisation = organisation_module[self.company_id]
organisation_module.manage_delObjects(ids=[organisation.getId()])
organisation.reindexObject()
self.tic()
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCMFActivity)) suite.addTest(unittest.makeSuite(TestCMFActivity))
......
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