Reindex comments when they are modified

This commit is contained in:
Gil Forcada 2016-04-07 18:30:30 +02:00
parent 608287692c
commit 26a21a12d5
5 changed files with 22 additions and 2 deletions

View File

@ -10,7 +10,8 @@ Breaking changes:
New features: New features:
- *add item here* - Reindex comments when they are modified.
[gforcada]
Bug fixes: Bug fixes:

View File

@ -12,6 +12,8 @@ from Products.statusmessages.interfaces import IStatusMessage
from z3c.form import button from z3c.form import button
from zope.component import getMultiAdapter from zope.component import getMultiAdapter
from zope.component import getUtility from zope.component import getUtility
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
class View(BrowserView): class View(BrowserView):
@ -91,6 +93,8 @@ class EditCommentForm(CommentForm):
# Update text # Update text
self.context.text = data['text'] self.context.text = data['text']
# Notify that the object has been modified
notify(ObjectModifiedEvent(self.context))
# Redirect to comment # Redirect to comment
IStatusMessage(self.request).add(_(u'comment_edit_notification', IStatusMessage(self.request).add(_(u'comment_edit_notification',

View File

@ -3,7 +3,7 @@ from Products.CMFCore.utils import getToolByName
def index_object(obj, event): def index_object(obj, event):
"""Index the object when it is added to the conversation. """Index the object when it is added/modified to the conversation.
""" """
catalog = getToolByName(obj, 'portal_catalog') catalog = getToolByName(obj, 'portal_catalog')
return catalog.reindexObject(obj) return catalog.reindexObject(obj)

View File

@ -39,6 +39,12 @@
handler=".subscribers.index_object" handler=".subscribers.index_object"
/> />
<subscriber
for="plone.app.discussion.interfaces.IComment
zope.lifecycleevent.interfaces.IObjectModifiedEvent"
handler=".subscribers.index_object"
/>
<subscriber <subscriber
for="plone.app.discussion.interfaces.IComment for="plone.app.discussion.interfaces.IComment
zope.lifecycleevent.interfaces.IObjectRemovedEvent" zope.lifecycleevent.interfaces.IObjectRemovedEvent"

View File

@ -9,6 +9,8 @@ from plone.app.testing import TEST_USER_ID
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from zope.annotation.interfaces import IAnnotations from zope.annotation.interfaces import IAnnotations
from zope.component import createObject from zope.component import createObject
from zope.event import notify
from zope.lifecycleevent import ObjectModifiedEvent
import transaction import transaction
import unittest2 as unittest import unittest2 as unittest
@ -329,6 +331,13 @@ class CommentCatalogTest(unittest.TestCase):
)) ))
self.assertEqual(len(brains), 0) self.assertEqual(len(brains), 0)
def test_reindex_comment(self):
# Make sure a comment is reindexed on the catalog when is modified
self.comment.text = 'Another text'
notify(ObjectModifiedEvent(self.comment))
brains = self.catalog.searchResults(SearchableText='Another text')
self.assertEqual(len(brains), 1)
def test_remove_comments_when_content_object_is_removed(self): def test_remove_comments_when_content_object_is_removed(self):
"""Make sure all comments are removed from the catalog, if the content """Make sure all comments are removed from the catalog, if the content
object is removed. object is removed.