Many updates to handle non public comments properly

This commit is contained in:
Patrick Gerken
2013-03-28 14:28:22 +01:00
parent 6320048b37
commit 05f0e7e4d8
8 changed files with 87 additions and 13 deletions
@@ -124,6 +124,11 @@ Anonymous user can not see any posts or comment actions
>>> 'form.button.PublishComment' in unprivileged_browser.contents
False
The catalog does not list the comments yet:
>>> portal.portal_catalog.searchResults(id='doc', total_comments=0)
[<Products...]
Users with 'Review comment' permission can see unapproved comments and comment
actions.
@@ -176,6 +181,11 @@ Make sure anonyous users see the approved comment, but not the unapproved ones.
>>> 'First anonymous comment' in unprivileged_browser.contents
True
Make sure the catalog only lists the public comments.
>>> portal.portal_catalog.searchResults(id='doc', total_comments=1)
[<Products...]
Delete a comment in the comments view
-------------------------------------
@@ -205,4 +215,12 @@ Make sure the second comment has been deleted.
>>> 'Second anonymous comment' in browser.contents
False
Delete the first, published comment.
>>> browser.open(urldoc)
>>> browser.getControl('Delete', index=0).click()
Make sure the catalog has been updated properly.
>>> portal.portal_catalog.searchResults(id='doc', total_comments=0)
[<Products...]
+11 -1
View File
@@ -172,7 +172,7 @@ class ConversationCatalogTest(unittest.TestCase):
))
doc1_brain = brains[0]
self.assertEqual(doc1_brain.commentators, ('Emma', 'Jim'))
self.assertEqual(doc1_brain.commentators, ('Jim', 'Emma'))
# remove one comments
del self.conversation[new_comment2_id]
@@ -205,6 +205,16 @@ class ConversationCatalogTest(unittest.TestCase):
self.assertEqual(comment1_brain.last_comment_date, None)
self.assertEqual(comment1_brain.total_comments, None)
def test_dont_index_private_commentators(self):
self.comment1.manage_permission("View", roles=tuple())
self.portal.doc1.reindexObject()
brains = self.catalog.searchResults(dict(
path={'query':
'/'.join(self.portal.doc1.getPhysicalPath())},
portal_type="Document"
))
doc1_brain = brains[0]
self.assertEqual(doc1_brain.commentators, ())
class CommentCatalogTest(unittest.TestCase):
@@ -69,7 +69,7 @@ class ConversationTest(unittest.TestCase):
self.assertTrue(isinstance(comment.comment_id, long))
self.assertTrue(IComment.providedBy(conversation[new_id]))
self.assertEqual(aq_base(conversation[new_id].__parent__),
aq_base(conversation))
aq_base(conversation))
self.assertEqual(new_id, comment.comment_id)
self.assertEqual(len(list(conversation.getComments())), 1)
self.assertEqual(len(tuple(conversation.getThreads())), 1)
@@ -77,6 +77,18 @@ class ConversationTest(unittest.TestCase):
self.assertTrue(conversation.last_comment_date - datetime.utcnow() <
timedelta(seconds=1))
def test_private_comment(self):
conversation = IConversation(self.portal.doc1)
comment = createObject('plone.Comment')
comment.author_username = "nobody"
conversation.addComment(comment)
comment.manage_permission("View", roles=tuple())
self.assertEquals(0, conversation.total_comments)
self.assertEquals(None, conversation.last_comment_date)
self.assertEquals(["nobody"], list(conversation.commentators))
self.assertEquals([], list(conversation.public_commentators))
def test_delete_comment(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.