Commit ec9dd198 authored by Stefan H. Holek's avatar Stefan H. Holek

Collector #2307: ObjectCopiedEvent not dispatched to sublocations.

parent 46209156
......@@ -91,6 +91,8 @@ Zope Changes
Bugs Fixed
- Collector #2307: ObjectCopiedEvent not dispatched to sublocations.
- Collector #2298: webdav.Resource.COPY and webdav.Resource.MOVE did
not send the expected copy/move events.
......
......@@ -31,6 +31,7 @@ import zope.interface
import zope.location.interfaces
from zope.app.container.contained import dispatchToSublocations
from zope.app.container.interfaces import IObjectMovedEvent
from zope.lifecycleevent.interfaces import IObjectCopiedEvent
deprecatedManageAddDeleteClasses = []
......@@ -130,6 +131,14 @@ def dispatchObjectClonedEvent(ob, event):
if OFS.interfaces.IObjectManager.providedBy(ob):
dispatchToSublocations(ob, event)
@zope.component.adapter(OFS.interfaces.IItem, IObjectCopiedEvent)
def dispatchObjectCopiedEvent(ob, event):
"""Multi-subscriber for IItem + IObjectCopiedEvent.
"""
# Dispatch to sublocations
if OFS.interfaces.IObjectManager.providedBy(ob):
dispatchToSublocations(ob, event)
def callManageAfterAdd(ob, item, container):
"""Compatibility subscriber for manage_afterAdd.
......
......@@ -275,7 +275,7 @@ class TestCopySupportSublocation(EventTest):
# Test clone
self.subfolder.manage_clone(self.folder.myfolder, 'myfolder')
self.assertEqual(eventlog.called(),
[#('mydoc', 'ObjectCopiedEvent'),
[('mydoc', 'ObjectCopiedEvent'),
('myfolder', 'ObjectCopiedEvent'),
('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectWillBeAddedEvent'),
......@@ -291,7 +291,7 @@ class TestCopySupportSublocation(EventTest):
cb = self.folder.manage_copyObjects(['myfolder'])
self.subfolder.manage_pasteObjects(cb)
self.assertEqual(eventlog.called(),
[#('mydoc', 'ObjectCopiedEvent'),
[('mydoc', 'ObjectCopiedEvent'),
('myfolder', 'ObjectCopiedEvent'),
('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectWillBeAddedEvent'),
......@@ -333,7 +333,7 @@ class TestCopySupportSublocation(EventTest):
req.environ['HTTP_DESTINATION'] = '%s/subfolder/myfolder' % self.folder.absolute_url()
self.folder.myfolder.COPY(req, req.RESPONSE)
self.assertEqual(eventlog.called(),
[#('mydoc', 'ObjectCopiedEvent'),
[('mydoc', 'ObjectCopiedEvent'),
('myfolder', 'ObjectCopiedEvent'),
('mydoc', 'ObjectWillBeAddedEvent'),
('myfolder', 'ObjectWillBeAddedEvent'),
......
......@@ -16,4 +16,7 @@
<!-- dispatch IObjectClonedEvent with "top-down" semantics -->
<subscriber handler="OFS.subscribers.dispatchObjectClonedEvent" />
<!-- dispatch IObjectCopiedEvent with "top-down" semantics -->
<subscriber handler="OFS.subscribers.dispatchObjectCopiedEvent" />
</configure>
......@@ -57,6 +57,7 @@ printed events will be in their "natural" order::
>>> from zope.component.interfaces import IObjectEvent, IRegistrationEvent
>>> from zope.app.container.interfaces import IObjectMovedEvent
>>> from zope.lifecycleevent.interfaces import IObjectCopiedEvent
>>> from OFS.interfaces import IObjectWillBeMovedEvent
>>> from OFS.interfaces import IObjectClonedEvent
>>> from OFS.interfaces import IItem
......@@ -64,6 +65,7 @@ printed events will be in their "natural" order::
... print event.__class__.__name__, object.getId()
>>> def printObjectEventExceptSome(object, event):
... if (IObjectMovedEvent.providedBy(event) or
... IObjectCopiedEvent.providedBy(event) or
... IObjectWillBeMovedEvent.providedBy(event) or
... IObjectClonedEvent.providedBy(event) or
... IRegistrationEvent.providedBy(event)):
......@@ -72,6 +74,7 @@ printed events will be in their "natural" order::
>>> from zope.component import provideHandler
>>> provideHandler(printObjectEvent, (IItem, IObjectMovedEvent))
>>> provideHandler(printObjectEvent, (IItem, IObjectCopiedEvent))
>>> provideHandler(printObjectEvent, (IItem, IObjectWillBeMovedEvent))
>>> provideHandler(printObjectEvent, (IItem, IObjectClonedEvent))
>>> provideHandler(printObjectEventExceptSome, (None, IObjectEvent))
......@@ -83,6 +86,7 @@ Finally we need to load the subscribers configuration::
>>> zope.component.provideAdapter(OFS.subscribers.ObjectManagerSublocations)
>>> zope.component.provideHandler(OFS.subscribers.dispatchObjectWillBeMovedEvent)
>>> zope.component.provideHandler(OFS.subscribers.dispatchObjectMovedEvent)
>>> zope.component.provideHandler(OFS.subscribers.dispatchObjectCopiedEvent)
>>> zope.component.provideHandler(OFS.subscribers.dispatchObjectClonedEvent)
We need at least one fake deprecated method to tell the compatibility
......@@ -133,6 +137,7 @@ Same thing for clone::
>>> res = folder.manage_clone(folder.marine, 'tank')
ObjectCopiedEvent tank
ObjectCopiedEvent dog
ObjectWillBeAddedEvent tank
ObjectWillBeAddedEvent dog
ObjectAddedEvent tank
......@@ -282,6 +287,7 @@ Cloning a tree of objects::
>>> res = folder.manage_clone(folder.pluto, 'mickey')
ObjectCopiedEvent mickey
ObjectCopiedEvent donald
ObjectWillBeAddedEvent mickey
ObjectWillBeAddedEvent donald
ObjectAddedEvent mickey
......@@ -414,6 +420,7 @@ Cloning a tree of objects::
>>> res = folder.manage_clone(folder.firefly, 'serenity')
ObjectCopiedEvent serenity
ObjectCopiedEvent mel
ObjectWillBeAddedEvent serenity
ObjectWillBeAddedEvent mel
ObjectAddedEvent serenity
......
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