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):
group_method_id = 'portal_activities/dummyGroupMethod/' + self.method_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):
"""return the object referenced in this message."""
try:
obj = activity_tool.unrestrictedTraverse(self.object_path)
obj = self._getObject(activity_tool)
except KeyError:
LOG('CMFActivity', WARNING, "Message dropped (no object found at path %r)"
% (self.object_path,), error=sys.exc_info())
......@@ -255,7 +261,7 @@ class Message(BaseMessage):
def getObjectCount(self, activity_tool):
if 'expand_method_id' in self.activity_kw:
try:
obj = activity_tool.unrestrictedTraverse(self.object_path)
obj = self._getObject(activity_tool)
return len(getattr(obj, self.activity_kw['expand_method_id'])())
except StandardError:
pass
......@@ -373,7 +379,7 @@ Named Parameters: %r
def reactivate(self, activity_tool, activity=DEFAULT_ACTIVITY):
# Reactivate the original object.
obj = activity_tool.unrestrictedTraverse(self.object_path)
obj = self._getObject(activity_tool)
old_security_manager = getSecurityManager()
try:
# Change user if required (TO BE DONE)
......
......@@ -3432,6 +3432,31 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
organisation.activate().getTitle()
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():
suite = unittest.TestSuite()
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