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:
		
							parent
							
								
									eec6bca238
								
							
						
					
					
						commit
						52ebbe2e71
					
				@ -4,6 +4,9 @@ Changelog
 | 
			
		||||
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
 | 
			
		||||
  comment by anonymous users.
 | 
			
		||||
  [regebro]
 | 
			
		||||
 | 
			
		||||
@ -2,11 +2,13 @@
 | 
			
		||||
"""
 | 
			
		||||
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 import queryUtility
 | 
			
		||||
 | 
			
		||||
from zope.interface import implements
 | 
			
		||||
 | 
			
		||||
from Acquisition import aq_parent, Implicit
 | 
			
		||||
 | 
			
		||||
from AccessControl.Role import RoleManager
 | 
			
		||||
@ -21,7 +23,9 @@ from OFS.Traversable import Traversable
 | 
			
		||||
 | 
			
		||||
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:
 | 
			
		||||
    # Plone 4:
 | 
			
		||||
@ -139,6 +143,15 @@ def notify_content_object(obj, event):
 | 
			
		||||
                                    'last_comment_date', 
 | 
			
		||||
                                    '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):
 | 
			
		||||
    """Tell the user when a comment is added
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
@ -3,7 +3,7 @@
 | 
			
		||||
    xmlns:zcml="http://namespaces.zope.org/zcml"
 | 
			
		||||
    i18n_domain="plone.app.discussion">
 | 
			
		||||
 | 
			
		||||
    <!-- Event subscribers -->
 | 
			
		||||
    <!-- Plone 3 Event Subscribers -->
 | 
			
		||||
 | 
			
		||||
    <configure zcml:condition="not-installed zope.app.container">
 | 
			
		||||
 | 
			
		||||
@ -51,8 +51,17 @@
 | 
			
		||||
          handler=".comment.notify_moderator"
 | 
			
		||||
          />
 | 
			
		||||
 | 
			
		||||
      </configure>
 | 
			
		||||
      <subscriber
 | 
			
		||||
          for="Products.CMFCore.interfaces.IContentish
 | 
			
		||||
               zope.lifecycleevent.interfaces.IObjectAddedEvent"
 | 
			
		||||
          handler=".comment.notify_content_object_deleted"
 | 
			
		||||
          />
 | 
			
		||||
          
 | 
			
		||||
    </configure>
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
    <!-- Plone 4 Event Subscribers -->
 | 
			
		||||
    
 | 
			
		||||
    <configure zcml:condition="installed zope.app.container">
 | 
			
		||||
 | 
			
		||||
      <subscriber
 | 
			
		||||
@ -99,6 +108,12 @@
 | 
			
		||||
          handler=".comment.notify_moderator"
 | 
			
		||||
          />
 | 
			
		||||
 | 
			
		||||
      </configure>
 | 
			
		||||
      <subscriber
 | 
			
		||||
          for="Products.CMFCore.interfaces.IContentish
 | 
			
		||||
               zope.app.container.interfaces.IObjectRemovedEvent"
 | 
			
		||||
          handler=".comment.notify_content_object_deleted"
 | 
			
		||||
          />
 | 
			
		||||
          
 | 
			
		||||
    </configure>
 | 
			
		||||
 | 
			
		||||
</configure>
 | 
			
		||||
 | 
			
		||||
@ -156,10 +156,9 @@ class ConversationTest(PloneTestCase):
 | 
			
		||||
        self.portal.manage_delObjects(['doc1'])
 | 
			
		||||
        
 | 
			
		||||
        # Make sure the comment has been deleted as well
 | 
			
		||||
        # XXX: Failing! Pivotal Tracker issue #2494228.
 | 
			
		||||
        #self.assertEquals(len(list(conversation.getComments())), 0)
 | 
			
		||||
        #self.assertEquals(sum(1 for w in conversation.getThreads()), 0)
 | 
			
		||||
        #self.assertEquals(conversation.total_comments, 0) 
 | 
			
		||||
        self.assertEquals(len(list(conversation.getComments())), 0)
 | 
			
		||||
        self.assertEquals(sum(1 for w in conversation.getThreads()), 0)
 | 
			
		||||
        self.assertEquals(conversation.total_comments, 0) 
 | 
			
		||||
 | 
			
		||||
    def test_allow_discussion(self):
 | 
			
		||||
        # This is not a real test! It's only there to understand the
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user