Fix #2494228: Remove comments as well when a content object is deleted.

svn path=/plone.app.discussion/trunk/; revision=34965
This commit is contained in:
Timo Stollenwerk 2010-03-16 15:06:43 +00:00
parent eec6bca238
commit 52ebbe2e71
4 changed files with 39 additions and 9 deletions

View File

@ -4,6 +4,9 @@ Changelog
1.0b4 (unreleased) 1.0b4 (unreleased)
------------------ ------------------
* Fix #2494228: Remove comments as well when a content object is deleted.
[timo]
* Fix unicode error when non-ASCII characters are typed into the name field of a * Fix unicode error when non-ASCII characters are typed into the name field of a
comment by anonymous users. comment by anonymous users.
[regebro] [regebro]

View File

@ -2,11 +2,13 @@
""" """
from datetime import datetime from datetime import datetime
from zope.interface import implements from zope.annotation.interfaces import IAnnotations, IAnnotatable
from zope.component.factory import Factory from zope.component.factory import Factory
from zope.component import queryUtility from zope.component import queryUtility
from zope.interface import implements
from Acquisition import aq_parent, Implicit from Acquisition import aq_parent, Implicit
from AccessControl.Role import RoleManager from AccessControl.Role import RoleManager
@ -21,7 +23,9 @@ from OFS.Traversable import Traversable
from plone.registry.interfaces import IRegistry from plone.registry.interfaces import IRegistry
from plone.app.discussion.interfaces import IComment, IDiscussionSettings from plone.app.discussion.interfaces import IComment
from plone.app.discussion.interfaces import IConversation
from plone.app.discussion.interfaces import IDiscussionSettings
try: try:
# Plone 4: # Plone 4:
@ -139,6 +143,15 @@ def notify_content_object(obj, event):
'last_comment_date', 'last_comment_date',
'commentators',)) 'commentators',))
def notify_content_object_deleted(obj, event):
"""Remove all comments of a content object when the content object has been
deleted.
"""
if IAnnotatable.providedBy(obj):
conversation = IConversation(obj)
for comment in conversation.getComments():
del conversation[comment.id]
def notify_user(obj, event): def notify_user(obj, event):
"""Tell the user when a comment is added """Tell the user when a comment is added
""" """

View File

@ -3,7 +3,7 @@
xmlns:zcml="http://namespaces.zope.org/zcml" xmlns:zcml="http://namespaces.zope.org/zcml"
i18n_domain="plone.app.discussion"> i18n_domain="plone.app.discussion">
<!-- Event subscribers --> <!-- Plone 3 Event Subscribers -->
<configure zcml:condition="not-installed zope.app.container"> <configure zcml:condition="not-installed zope.app.container">
@ -51,8 +51,17 @@
handler=".comment.notify_moderator" handler=".comment.notify_moderator"
/> />
<subscriber
for="Products.CMFCore.interfaces.IContentish
zope.lifecycleevent.interfaces.IObjectAddedEvent"
handler=".comment.notify_content_object_deleted"
/>
</configure> </configure>
<!-- Plone 4 Event Subscribers -->
<configure zcml:condition="installed zope.app.container"> <configure zcml:condition="installed zope.app.container">
<subscriber <subscriber
@ -99,6 +108,12 @@
handler=".comment.notify_moderator" handler=".comment.notify_moderator"
/> />
<subscriber
for="Products.CMFCore.interfaces.IContentish
zope.app.container.interfaces.IObjectRemovedEvent"
handler=".comment.notify_content_object_deleted"
/>
</configure> </configure>
</configure> </configure>

View File

@ -156,10 +156,9 @@ class ConversationTest(PloneTestCase):
self.portal.manage_delObjects(['doc1']) self.portal.manage_delObjects(['doc1'])
# Make sure the comment has been deleted as well # Make sure the comment has been deleted as well
# XXX: Failing! Pivotal Tracker issue #2494228. self.assertEquals(len(list(conversation.getComments())), 0)
#self.assertEquals(len(list(conversation.getComments())), 0) self.assertEquals(sum(1 for w in conversation.getThreads()), 0)
#self.assertEquals(sum(1 for w in conversation.getThreads()), 0) self.assertEquals(conversation.total_comments, 0)
#self.assertEquals(conversation.total_comments, 0)
def test_allow_discussion(self): def test_allow_discussion(self):
# This is not a real test! It's only there to understand the # This is not a real test! It's only there to understand the