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

View File

@ -16,6 +16,11 @@ from plone.app.discussion.interfaces import IConversation, IComment
from plone.indexer import indexer from plone.indexer import indexer
try:
from plone.uuid.interfaces import IUUID
except ImportError:
IUUID = None
MAX_DESCRIPTION = 25 MAX_DESCRIPTION = 25
# Conversation Indexers # Conversation Indexers
@ -130,3 +135,9 @@ def comments_last_comment_date(object):
@indexer(IComment) @indexer(IComment)
def comments_commentators(object): def comments_commentators(object):
return None return None
# Make sure comments don't inherit their container's UID
@indexer(IComment)
def UID(object):
if IUUID:
return IUUID(object, None)

View File

@ -101,6 +101,7 @@
<adapter name="in_response_to" factory=".catalog.in_response_to" /> <adapter name="in_response_to" factory=".catalog.in_response_to" />
<!-- Comment indexes --> <!-- Comment indexes -->
<adapter name="UID" factory=".catalog.UID" />
<adapter name="Title" factory=".catalog.title" /> <adapter name="Title" factory=".catalog.title" />
<adapter name="Creator" factory=".catalog.creator" /> <adapter name="Creator" factory=".catalog.creator" />
<adapter name="Description" factory=".catalog.description" /> <adapter name="Description" factory=".catalog.description" />

View File

@ -71,6 +71,14 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment1) conversation.addComment(comment1)
comment_brain = self.catalog.searchResults( comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0] portal_type = 'Discussion Item')[0]
# 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) self.failUnless(comment_brain.UID)
def test_uid_is_unique(self): def test_uid_is_unique(self):
@ -81,8 +89,10 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment2) conversation.addComment(comment2)
brains = self.catalog.searchResults( brains = self.catalog.searchResults(
portal_type = 'Discussion Item') portal_type = 'Discussion Item')
self.assertNotEquals(brains[0].UID, None)
self.assertNotEquals(brains[1].UID, None) # 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) self.assertNotEquals(brains[0].UID, brains[1].UID)
def test_comment_uid_differs_from_content_uid(self): def test_comment_uid_differs_from_content_uid(self):
@ -91,7 +101,6 @@ class CommentTest(PloneTestCase):
conversation.addComment(comment1) conversation.addComment(comment1)
comment_brain = self.catalog.searchResults( comment_brain = self.catalog.searchResults(
portal_type = 'Discussion Item')[0] portal_type = 'Discussion Item')[0]
self.assertNotEquals(comment_brain.UID, None)
self.assertNotEquals(self.document_brain.UID, comment_brain.UID) self.assertNotEquals(self.document_brain.UID, comment_brain.UID)
def test_title(self): def test_title(self):

View File

@ -1,7 +1,33 @@
import sys
from setuptools import setup, find_packages from setuptools import setup, find_packages
version = '1.0bRC1' version = '1.0bRC1'
install_requires = [
'setuptools',
'collective.autopermission',
'collective.monkeypatcher',
'plone.app.layout',
'plone.app.registry',
'plone.app.z3cform',
'plone.indexer',
'plone.registry',
'plone.z3cform',
'ZODB3',
'zope.interface',
'zope.component',
'zope.annotation',
'zope.event',
'zope.container',
'zope.lifecycleevent',
'zope.site',
'z3c.form>=2.3.3',
]
# On Python 2.6 (implying Plone 4), require plone.app.uuid
if sys.version_info >= (2,6):
install_requires.append('plone.app.uuid')
setup(name='plone.app.discussion', setup(name='plone.app.discussion',
version=version, version=version,
description="Enhanced discussion support for Plone", description="Enhanced discussion support for Plone",
@ -20,27 +46,7 @@ setup(name='plone.app.discussion',
namespace_packages=['plone', 'plone.app'], namespace_packages=['plone', 'plone.app'],
include_package_data=True, include_package_data=True,
zip_safe=False, zip_safe=False,
install_requires=[ install_requires=install_requires,
'setuptools',
'collective.autopermission',
'collective.monkeypatcher',
'plone.app.layout',
'plone.app.registry',
'plone.app.uuid',
'plone.app.z3cform',
'plone.indexer',
'plone.registry',
'plone.z3cform',
'ZODB3',
'zope.interface',
'zope.component',
'zope.annotation',
'zope.event',
'zope.container',
'zope.lifecycleevent',
'zope.site',
'z3c.form>=2.3.3',
],
extras_require = { extras_require = {
'test': [ 'test': [
'plone.app.testing', 'plone.app.testing',