make sure comments don't get indexed with their parents' UID in Plone 3. only declare dependency on plone.app.uuid in Python 2.6, since we only use it in Plone 4 currently.

svn path=/plone.app.discussion/trunk/; revision=46353
This commit is contained in:
David Glick
2010-12-15 20:39:55 +00:00
parent b9d929bca3
commit 0cb75778ba
4 changed files with 55 additions and 28 deletions
+11
View File
@@ -16,6 +16,11 @@ from plone.app.discussion.interfaces import IConversation, IComment
from plone.indexer import indexer
try:
from plone.uuid.interfaces import IUUID
except ImportError:
IUUID = None
MAX_DESCRIPTION = 25
# Conversation Indexers
@@ -130,3 +135,9 @@ def comments_last_comment_date(object):
@indexer(IComment)
def comments_commentators(object):
return None
# Make sure comments don't inherit their container's UID
@indexer(IComment)
def UID(object):
if IUUID:
return IUUID(object, None)
+1
View File
@@ -101,6 +101,7 @@
<adapter name="in_response_to" factory=".catalog.in_response_to" />
<!-- Comment indexes -->
<adapter name="UID" factory=".catalog.UID" />
<adapter name="Title" factory=".catalog.title" />
<adapter name="Creator" factory=".catalog.creator" />
<adapter name="Description" factory=".catalog.description" />
+16 -7
View File
@@ -71,27 +71,36 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment1)
comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0]
self.failUnless(comment_brain.UID)
# comment should only have a UID if plone.uuid is present
try:
from plone.uuid.interfaces import IUUID
IUUID # pyflakes
except ImportError:
self.failIf(comment_brain.UID)
else:
self.failUnless(comment_brain.UID)
def test_uid_is_unique(self):
conversation = IConversation(self.portal.doc1)
conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment')
conversation.addComment(comment1)
comment2 = createObject('plone.Comment')
conversation.addComment(comment2)
brains = self.catalog.searchResults(
portal_type = 'Discussion Item')
self.assertNotEquals(brains[0].UID, None)
self.assertNotEquals(brains[1].UID, None)
self.assertNotEquals(brains[0].UID, brains[1].UID)
# make sure uids are either both None (i.e. without plone.uuid),
# or not equal
if brains[0].UID != None or brains[1].UID != None:
self.assertNotEquals(brains[0].UID, brains[1].UID)
def test_comment_uid_differs_from_content_uid(self):
conversation = IConversation(self.portal.doc1)
conversation = IConversation(self.portal.doc1)
comment1 = createObject('plone.Comment')
conversation.addComment(comment1)
comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0]
self.assertNotEquals(comment_brain.UID, None)
self.assertNotEquals(self.document_brain.UID, comment_brain.UID)
def test_title(self):