From b02778939127f43446726204e62779befc8d7d07 Mon Sep 17 00:00:00 2001 From: Andreas Zeidler Date: Thu, 15 Aug 2013 00:01:22 +0200 Subject: [PATCH] prevent the viewlet from raising an error for objects that are not annotatable --- plone/app/discussion/browser/comments.py | 5 ++++- plone/app/discussion/tests/test_comments_viewlet.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index 529df18..bcf5dbe 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -358,7 +358,10 @@ class CommentsViewlet(ViewletBase): returned with workflow actions. """ context = aq_inner(self.context) - conversation = IConversation(context) + conversation = IConversation(context, None) + + if conversation is None: + return iter([]) wf = getToolByName(context, 'portal_workflow') diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index 1844b28..8b742c8 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -370,6 +370,14 @@ class TestCommentsViewlet(unittest.TestCase): replies.next() self.assertRaises(StopIteration, replies.next) + def test_get_replies_on_non_annotatable_object(self): + context = self.portal.MailHost # the mail host is not annotatable + viewlet = CommentsViewlet(context, self.request, None, None) + replies = viewlet.get_replies() + self.assertEqual(len(tuple(replies)), 0) + replies = viewlet.get_replies() + self.assertRaises(StopIteration, replies.next) + def test_get_replies_with_workflow_actions(self): self.assertFalse(self.viewlet.get_replies(workflow_actions=True)) comment = createObject('plone.Comment')