diff --git a/CHANGES.rst b/CHANGES.rst index f61ce24..a5df199 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -17,6 +17,7 @@ Changelog PLONE_FIXTURE. [timo] +- Fix ownership of comments. [toutpt] 2.2.10 (2013-09-24) ------------------- diff --git a/plone/app/discussion/browser/comments.py b/plone/app/discussion/browser/comments.py index bcf5dbe..87608c3 100644 --- a/plone/app/discussion/browser/comments.py +++ b/plone/app/discussion/browser/comments.py @@ -196,6 +196,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form): # Member member = portal_membership.getAuthenticatedMember() username = member.getUserName() + user = member.getUser() email = member.getProperty('email') fullname = member.getProperty('fullname') if not fullname or fullname == '': @@ -205,6 +206,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form): fullname = unicode(fullname, 'utf-8') if email and isinstance(email, str): email = unicode(email, 'utf-8') + comment.changeOwnership(user, recursive=False) + comment.manage_setLocalRoles(username, ["Owner"]) comment.creator = username comment.author_username = username comment.author_name = fullname diff --git a/plone/app/discussion/tests/test_comments_viewlet.py b/plone/app/discussion/tests/test_comments_viewlet.py index c2375af..f4a3d1e 100644 --- a/plone/app/discussion/tests/test_comments_viewlet.py +++ b/plone/app/discussion/tests/test_comments_viewlet.py @@ -120,6 +120,21 @@ class TestCommentForm(unittest.TestCase): self.assertEqual(len(errors), 0) self.assertFalse(commentForm.handleComment(commentForm, "foo")) + comments = IConversation(commentForm.context).getComments() + comments = [comment for comment in comments] # consume itertor + self.assertEqual(len(comments), 1) + + for comment in comments: + self.assertEqual(comment.text, u"bar") + self.assertEqual(comment.creator, "test-user") + self.assertEqual(comment.getOwner().getUserName(), "test-user") + local_roles = comment.get_local_roles() + self.assertEqual(len(local_roles), 1) + userid, roles = local_roles[0] + self.assertEqual(userid, 'test-user') + self.assertEqual(len(roles), 1) + self.assertEqual(roles[0], 'Owner') + def test_add_anonymous_comment(self): self.portal.doc1.allow_discussion = True @@ -160,6 +175,16 @@ class TestCommentForm(unittest.TestCase): self.assertEqual(len(errors), 0) self.assertFalse(commentForm.handleComment(commentForm, "action")) + comments = IConversation(commentForm.context).getComments() + comments = [comment for comment in comments] # consume itertor + self.assertEqual(len(comments), 1) + + for comment in IConversation(commentForm.context).getComments(): + self.assertEqual(comment.text, u"bar") + self.assertIsNone(comment.creator) + roles = comment.get_local_roles() + self.assertEqual(len(roles), 0) + def test_can_not_add_comments_if_discussion_is_not_allowed(self): """Make sure that comments can't be posted if discussion is disabled. """