From fbc78e29510bbec6aad4a45a1595c5a79b9d18b9 Mon Sep 17 00:00:00 2001 From: tisto Date: Thu, 10 Oct 2013 15:36:18 +0200 Subject: [PATCH] Remove portal_discussion tool. --- CHANGES.rst | 10 +- plone/app/discussion/interfaces.py | 32 -- plone/app/discussion/patches.py | 9 +- .../profiles/default/componentregistry.xml | 9 - .../discussion/profiles/default/toolset.xml | 5 - plone/app/discussion/subscribers.py | 14 + plone/app/discussion/subscribers.zcml | 4 +- plone/app/discussion/tests/test_catalog.py | 3 + .../discussion/tests/test_comments_viewlet.py | 25 +- .../app/discussion/tests/test_conversation.py | 6 +- plone/app/discussion/tests/test_migration.py | 328 ------------------ .../discussion/tests/test_moderation_view.py | 23 -- .../discussion/tests/test_notifications.py | 2 - plone/app/discussion/tests/test_tool.py | 56 --- plone/app/discussion/tests/test_workflow.py | 2 - 15 files changed, 44 insertions(+), 484 deletions(-) delete mode 100644 plone/app/discussion/profiles/default/componentregistry.xml delete mode 100644 plone/app/discussion/profiles/default/toolset.xml create mode 100644 plone/app/discussion/subscribers.py delete mode 100644 plone/app/discussion/tests/test_migration.py delete mode 100644 plone/app/discussion/tests/test_tool.py diff --git a/CHANGES.rst b/CHANGES.rst index cafcaa5..3c17efd 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,14 +4,20 @@ Changelog 2.3.0 (unreleased) ------------------ -- Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of the PLONE_FIXTURE. +- Remove portal_discussion tool. + [timo] + +- Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of + PLONE_FIXTURE. [timo] 2.2.10 (2013-09-24) ------------------- -- Revert "Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of the PLONE_FIXTURE." that has been accidentially introduced into the 2.2.9 release. +- Revert "Refactor tests to use the PLONE_APP_CONTENTTYPES_FIXTURE instead of + the PLONE_FIXTURE." that has been accidentially introduced into the 2.2.9 + release. [timo] diff --git a/plone/app/discussion/interfaces.py b/plone/app/discussion/interfaces.py index 46d430d..733f4d0 100644 --- a/plone/app/discussion/interfaces.py +++ b/plone/app/discussion/interfaces.py @@ -184,38 +184,6 @@ class ICaptcha(Interface): required=False) -class ICommentingTool(Interface): - """A tool that indexes all comments for usage by the management interface. - - This means the management interface can still work even though we don't - index the comments in portal_catalog. - - The default implementation of this interface simply defers to - portal_catalog, but a custom version of the tool can be used to provide - an alternate indexing mechanism. - """ - - def indexObject(comment): - """Indexes a comment - """ - - def reindexObject(comment): - """Reindex a comment - """ - - def unindexObject(comment): - """Removes a comment from the indexes - """ - - def uniqueValuesFor(name): - """Get unique values for FieldIndex name - """ - - def searchResults(REQUEST=None, **kw): - """Perform a search over all indexed comments. - """ - - class IDiscussionSettings(Interface): """Global discussion settings. This describes records stored in the configuration registry and obtainable via plone.registry. diff --git a/plone/app/discussion/patches.py b/plone/app/discussion/patches.py index 47ec27b..f803f10 100644 --- a/plone/app/discussion/patches.py +++ b/plone/app/discussion/patches.py @@ -1,3 +1,5 @@ +from Products.CMFCore.utils import getToolByName + from zope.component import queryUtility from Acquisition import aq_inner, aq_parent @@ -8,7 +10,6 @@ from Products.CMFPlone.utils import base_hasattr from Products.CMFPlone.utils import safe_callable from plone.app.discussion.conversation import ANNOTATION_KEY -from plone.app.discussion.interfaces import ICommentingTool def patchedClearFindAndRebuild(self): @@ -26,14 +27,14 @@ def patchedClearFindAndRebuild(self): obj.indexObject() annotions = IAnnotations(obj) - ctool = queryUtility(ICommentingTool) + catalog = getToolByName(obj, "portal_catalog") if ANNOTATION_KEY in annotions: conversation = annotions[ANNOTATION_KEY] conversation = conversation.__of__(obj) for comment in conversation.getComments(): try: - if ctool: - ctool.indexObject(comment) + if catalog: + catalog.indexObject(comment) except StopIteration: # pragma: no cover pass diff --git a/plone/app/discussion/profiles/default/componentregistry.xml b/plone/app/discussion/profiles/default/componentregistry.xml deleted file mode 100644 index 635cae9..0000000 --- a/plone/app/discussion/profiles/default/componentregistry.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - diff --git a/plone/app/discussion/profiles/default/toolset.xml b/plone/app/discussion/profiles/default/toolset.xml deleted file mode 100644 index 0823a74..0000000 --- a/plone/app/discussion/profiles/default/toolset.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/plone/app/discussion/subscribers.py b/plone/app/discussion/subscribers.py new file mode 100644 index 0000000..20ac7ad --- /dev/null +++ b/plone/app/discussion/subscribers.py @@ -0,0 +1,14 @@ +from Products.CMFCore.utils import getToolByName + +def index_object(obj, event): + """Index the object when it is added to the conversation. + """ + catalog = getToolByName(obj, 'portal_catalog') + return catalog.reindexObject(obj) + +def unindex_object(obj, event): + """Unindex the object when it is removed from the conversation. + """ + catalog = getToolByName(obj, 'portal_catalog') + return catalog.unindexObject(obj) + diff --git a/plone/app/discussion/subscribers.zcml b/plone/app/discussion/subscribers.zcml index d0d848d..e563f80 100644 --- a/plone/app/discussion/subscribers.zcml +++ b/plone/app/discussion/subscribers.zcml @@ -24,13 +24,13 @@ My Text

\n') - self.assertEqual(comment1.mime_type, 'text/html') - self.assertEqual(comment1.Creator(), 'Jim') - self.assertEqual( - comment1.creation_date, - datetime(2003, 3, 11, 9, 28, 6) - ) - self.assertEqual( - comment1.modification_date, - datetime(2009, 7, 12, 19, 38, 7) - ) - self.assertEqual([ - {'comment': comment1, 'depth': 0, 'id': long(comment1.id)} - ], list(conversation.getThreads())) - self.assertFalse(self.doc.talkback) - - def test_migrate_comment_with_creator(self): - # Create a comment - talkback = self.discussion.getDiscussionFor(self.doc) - self.doc.talkback.createReply('My Title', 'My Text', Creator='Jim') - reply = talkback.getReplies()[0] - reply.setReplyTo(self.doc) - reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6, 'GMT') - reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7, 'GMT') - reply.author_username = 'Jim' - reply.email = 'jimmy@jones.xyz' - - self._publish(reply) - self.assertEqual(reply.Title(), 'My Title') - self.assertEqual(reply.EditableBody(), 'My Text') - self.assertTrue('Jim' in reply.listCreators()) - self.assertEqual(talkback.replyCount(self.doc), 1) - self.assertEqual(reply.inReplyTo(), self.doc) - self.assertEqual(reply.author_username, 'Jim') - self.assertEqual(reply.email, 'jimmy@jones.xyz') - - # Call migration script - self.view() - - # Make sure a conversation has been created - self.assertTrue( - 'plone.app.discussion:conversation' in IAnnotations(self.doc) - ) - conversation = IConversation(self.doc) - - # Check migration - self.assertEqual(conversation.total_comments, 1) - self.assertTrue(conversation.getComments().next()) - comment1 = conversation.values()[0] - self.assertTrue(IComment.providedBy(comment1)) - self.assertEqual(comment1.Title(), 'My Title') - self.assertEqual(comment1.text, '

My Text

\n') - self.assertEqual(comment1.mime_type, 'text/html') - self.assertEqual(comment1.Creator(), 'Jim') - self.assertEqual( - comment1.creation_date, - datetime(2003, 3, 11, 9, 28, 6) - ) - self.assertEqual( - comment1.modification_date, - datetime(2009, 7, 12, 19, 38, 7) - ) - self.assertEqual([ - {'comment': comment1, 'depth': 0, 'id': long(comment1.id)} - ], list(conversation.getThreads())) - self.assertFalse(self.doc.talkback) - - # Though this should be Jimmy, but looks like getProperty won't pick - # up 'author_username' (reply.author_username is not None), so it's - # propagating Creator()..? - self.assertEqual(comment1.author_username, 'Jim') - - self.assertEqual(comment1.author_name, 'Jimmy Jones') - self.assertEqual(comment1.author_email, 'jimmy@jones.xyz') - - def test_migrate_nested_comments(self): - # Create some nested comments and migrate them - # - # self.doc - # +- First comment - # +- Re: First comment - # + Re: Re: First comment - # + Re: Re: Re: First comment - # +- Re: First comment (2) - # +- Re: First comment (3) - # +- Re: First comment (4) - # +- Second comment - - talkback = self.discussion.getDiscussionFor(self.doc) - - # First comment - talkback.createReply(title='First comment', - text='This is my first comment.') - comment1 = talkback.getReplies()[0] - self._publish(comment1) - - talkback_comment1 = self.discussion.getDiscussionFor(comment1) - - # Re: First comment - talkback_comment1.createReply(title='Re: First comment', - text='This is my first reply.') - comment1_1 = talkback_comment1.getReplies()[0] - self._publish(comment1_1) - - talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1) - - self.assertEqual(len(talkback.getReplies()), 1) - self.assertEqual(len(talkback_comment1.getReplies()), 1) - self.assertEqual(len(talkback_comment1_1.getReplies()), 0) - - #Re: Re: First comment - talkback_comment1_1.createReply(title='Re: Re: First comment', - text='This is my first re-reply.') - comment1_1_1 = talkback_comment1_1.getReplies()[0] - self._publish(comment1_1_1) - - talkback_comment1_1_1 = self.discussion.getDiscussionFor(comment1_1_1) - - # Re: Re: Re: First comment - talkback_comment1_1_1.createReply(title='Re: Re: Re: First comment', - text='This is my first re-re-reply.') - self._publish(talkback_comment1_1_1.getReplies()[0]) - - # Re: First comment (2) - talkback_comment1.createReply(title='Re: First comment (2)', - text='This is my first reply (2).') - self._publish(talkback_comment1.getReplies()[1]) - - # Re: First comment (3) - talkback_comment1.createReply(title='Re: First comment (3)', - text='This is my first reply (3).') - self._publish(talkback_comment1.getReplies()[2]) - - # Re: First comment (4) - talkback_comment1.createReply(title='Re: First comment (4)', - text='This is my first reply (4).') - self._publish(talkback_comment1.getReplies()[3]) - - # Second comment - talkback.createReply(title='Second comment', - text='This is my second comment.') - self._publish(talkback.getReplies()[1]) - - # Call migration script - self.view() - - # Check migration - conversation = IConversation(self.doc) - self.assertEqual(conversation.total_comments, 8) - - comment1 = conversation.values()[0] - comment1_1 = conversation.values()[1] - comment1_1_1 = conversation.values()[2] - comment1_1_1_1 = conversation.values()[3] - comment1_2 = conversation.values()[4] - comment1_3 = conversation.values()[5] - comment1_4 = conversation.values()[6] - comment2 = conversation.values()[7] - - self.assertEqual([ - {'comment': comment1, 'depth': 0, 'id': long(comment1.id)}, - {'comment': comment1_1, 'depth': 1, 'id': long(comment1_1.id)}, - {'comment': comment1_1_1, 'depth': 2, 'id': long(comment1_1_1.id)}, - {'comment': comment1_1_1_1, 'depth': 3, - 'id': long(comment1_1_1_1.id)}, - {'comment': comment1_2, 'depth': 1, 'id': long(comment1_2.id)}, - {'comment': comment1_3, 'depth': 1, 'id': long(comment1_3.id)}, - {'comment': comment1_4, 'depth': 1, 'id': long(comment1_4.id)}, - {'comment': comment2, 'depth': 0, 'id': long(comment2.id)}, - ], list(conversation.getThreads())) - - talkback = self.discussion.getDiscussionFor(self.doc) - self.assertEqual(len(talkback.getReplies()), 0) - - def test_migrate_nested_comments_with_filter(self): - # Create some nested comments and migrate them. - # But use a filter that filters the top-level comment. - # All the comments should be removed, but not migrated. - # - # self.doc - # +- First comment - # +- Re: First comment - - talkback = self.discussion.getDiscussionFor(self.doc) - - # First comment - talkback.createReply(title='First comment', - text='This is my first comment.') - comment1 = talkback.getReplies()[0] - talkback_comment1 = self.discussion.getDiscussionFor(comment1) - - # Re: First comment - talkback_comment1.createReply(title='Re: First comment', - text='This is my first reply.') - comment1_1 = talkback_comment1.getReplies()[0] - talkback_comment1_1 = self.discussion.getDiscussionFor(comment1_1) - - self.assertEqual(len(talkback.getReplies()), 1) - self.assertEqual(len(talkback_comment1.getReplies()), 1) - self.assertEqual(len(talkback_comment1_1.getReplies()), 0) - - def deny_comments(reply): - return False - - # Call migration script - self.view(filter_callback=deny_comments) - - # Check migration - conversation = IConversation(self.doc) - self.assertEqual(conversation.total_comments, 0) - talkback = self.discussion.getDiscussionFor(self.doc) - self.assertEqual(len(talkback.getReplies()), 0) - - def test_migrate_no_comment(self): - - # Call migration script - self.view() - - # Make sure no conversation has been created - self.assertTrue( - 'plone.app.discussion:conversation' not in IAnnotations(self.doc) - ) - - -def test_suite(): - return unittest.defaultTestLoader.loadTestsFromName(__name__) diff --git a/plone/app/discussion/tests/test_moderation_view.py b/plone/app/discussion/tests/test_moderation_view.py index ac0a7bd..33064b6 100644 --- a/plone/app/discussion/tests/test_moderation_view.py +++ b/plone/app/discussion/tests/test_moderation_view.py @@ -58,29 +58,6 @@ class ModerationViewTest(unittest.TestCase): ('comment_review_workflow,')) self.assertEqual(self.view.moderation_enabled(), True) - def test_old_comments_not_shown_in_moderation_view(self): - # Create old comment - discussion = getToolByName(self.portal, 'portal_discussion', None) - discussion.overrideDiscussionFor(self.portal.doc1, 1) - talkback = discussion.getDiscussionFor(self.portal.doc1) - self.portal.doc1.talkback.createReply('My Title', - 'My Text', - Creator='Jim') - reply = talkback.getReplies()[0] - reply.setReplyTo(self.portal.doc1) - reply.creation_date = DateTime(2003, 3, 11, 9, 28, 6) - reply.modification_date = DateTime(2009, 7, 12, 19, 38, 7) - self.assertEqual(reply.Title(), 'My Title') - self.assertEqual(reply.EditableBody(), 'My Text') - self.assertTrue('Jim' in reply.listCreators()) - self.assertEqual(talkback.replyCount(self.portal.doc1), 1) - self.assertEqual(reply.inReplyTo(), self.portal.doc1) - - view = self.view() - - self.assertTrue('No comments to moderate' in view) - self.assertEqual(len(self.view.comments), 0) - class ModerationBulkActionsViewTest(unittest.TestCase): diff --git a/plone/app/discussion/tests/test_notifications.py b/plone/app/discussion/tests/test_notifications.py index 1c397c1..90b6707 100644 --- a/plone/app/discussion/tests/test_notifications.py +++ b/plone/app/discussion/tests/test_notifications.py @@ -42,7 +42,6 @@ class TestUserNotificationUnit(unittest.TestCase): '.user_notification_enabled'] = True # Create test content self.portal.invokeFactory('Document', 'doc1') - self.portal_discussion = self.portal.portal_discussion # Archetypes content types store data as utf-8 encoded strings # The missing u in front of a string is therefor not missing self.portal.doc1.title = 'Kölle Alaaf' # What is "Fasching"? @@ -189,7 +188,6 @@ class TestModeratorNotificationUnit(unittest.TestCase): ] = True # Create test content self.portal.invokeFactory('Document', 'doc1') - self.portal_discussion = self.portal.portal_discussion # Archetypes content types store data as utf-8 encoded strings # The missing u in front of a string is therefor not missing self.portal.doc1.title = 'Kölle Alaaf' # What is "Fasching"? diff --git a/plone/app/discussion/tests/test_tool.py b/plone/app/discussion/tests/test_tool.py deleted file mode 100644 index 1386cff..0000000 --- a/plone/app/discussion/tests/test_tool.py +++ /dev/null @@ -1,56 +0,0 @@ -import unittest2 as unittest - -from zope.component import queryUtility, createObject - -from plone.app.testing import TEST_USER_ID, setRoles - -from plone.app.discussion.testing import \ - PLONE_APP_DISCUSSION_INTEGRATION_TESTING - -from plone.app.discussion.interfaces import ICommentingTool, IConversation - - -class ToolTest(unittest.TestCase): - - layer = PLONE_APP_DISCUSSION_INTEGRATION_TESTING - - def setUp(self): - self.portal = self.layer['portal'] - setRoles(self.portal, TEST_USER_ID, ['Manager']) - self.portal.invokeFactory(id='doc1', - title='Document 1', - type_name='Document') - - def test_tool_indexing(self): - # Create a conversation. In this case we doesn't assign it to an - # object, as we just want to check the Conversation object API. - conversation = IConversation(self.portal.doc1) - - # Add a comment. - comment = createObject('plone.Comment') - comment.creator = 'jim' - comment.author_name = "Jim" - comment.text = 'Comment text' - - conversation.addComment(comment) - - # Check that the comment got indexed in the tool: - tool = queryUtility(ICommentingTool) - comment = list(tool.searchResults()) - self.assertTrue( - len(comment) == 1, - "There is only one comment, but we got" - " %s results in the search" % len(comment) - ) - self.assertEqual(comment[0].Title, 'Jim on Document 1') - - def test_unindexing(self): - pass - - def test_search(self): - # search returns only comments - pass - - -def test_suite(): - return unittest.defaultTestLoader.loadTestsFromName(__name__) diff --git a/plone/app/discussion/tests/test_workflow.py b/plone/app/discussion/tests/test_workflow.py index 8ea9e30..e54fecd 100644 --- a/plone/app/discussion/tests/test_workflow.py +++ b/plone/app/discussion/tests/test_workflow.py @@ -32,7 +32,6 @@ class WorkflowSetupTest(unittest.TestCase): self.portal.invokeFactory('Folder', 'test-folder') self.folder = self.portal['test-folder'] self.portal.portal_types['Document'].allow_discussion = True - self.portal_discussion = self.portal.portal_discussion self.folder.invokeFactory('Document', 'doc1') self.doc = self.folder.doc1 @@ -190,7 +189,6 @@ class CommentReviewWorkflowTest(unittest.TestCase): # Create a Document self.portal.invokeFactory('Document', 'doc1') - self.portal_discussion = self.portal.portal_discussion # Create a conversation for this Document conversation = IConversation(self.portal.doc1)