Fix ownership of comments.
This commit is contained in:
parent
dcba2c2714
commit
410b8c998a
@ -17,6 +17,7 @@ Changelog
|
|||||||
PLONE_FIXTURE.
|
PLONE_FIXTURE.
|
||||||
[timo]
|
[timo]
|
||||||
|
|
||||||
|
- Fix ownership of comments. [toutpt]
|
||||||
|
|
||||||
2.2.10 (2013-09-24)
|
2.2.10 (2013-09-24)
|
||||||
-------------------
|
-------------------
|
||||||
|
@ -196,6 +196,7 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
|
|||||||
# Member
|
# Member
|
||||||
member = portal_membership.getAuthenticatedMember()
|
member = portal_membership.getAuthenticatedMember()
|
||||||
username = member.getUserName()
|
username = member.getUserName()
|
||||||
|
user = member.getUser()
|
||||||
email = member.getProperty('email')
|
email = member.getProperty('email')
|
||||||
fullname = member.getProperty('fullname')
|
fullname = member.getProperty('fullname')
|
||||||
if not fullname or fullname == '':
|
if not fullname or fullname == '':
|
||||||
@ -205,6 +206,8 @@ class CommentForm(extensible.ExtensibleForm, form.Form):
|
|||||||
fullname = unicode(fullname, 'utf-8')
|
fullname = unicode(fullname, 'utf-8')
|
||||||
if email and isinstance(email, str):
|
if email and isinstance(email, str):
|
||||||
email = unicode(email, 'utf-8')
|
email = unicode(email, 'utf-8')
|
||||||
|
comment.changeOwnership(user, recursive=False)
|
||||||
|
comment.manage_setLocalRoles(username, ["Owner"])
|
||||||
comment.creator = username
|
comment.creator = username
|
||||||
comment.author_username = username
|
comment.author_username = username
|
||||||
comment.author_name = fullname
|
comment.author_name = fullname
|
||||||
|
@ -120,6 +120,21 @@ class TestCommentForm(unittest.TestCase):
|
|||||||
self.assertEqual(len(errors), 0)
|
self.assertEqual(len(errors), 0)
|
||||||
self.assertFalse(commentForm.handleComment(commentForm, "foo"))
|
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):
|
def test_add_anonymous_comment(self):
|
||||||
self.portal.doc1.allow_discussion = True
|
self.portal.doc1.allow_discussion = True
|
||||||
|
|
||||||
@ -160,6 +175,16 @@ class TestCommentForm(unittest.TestCase):
|
|||||||
self.assertEqual(len(errors), 0)
|
self.assertEqual(len(errors), 0)
|
||||||
self.assertFalse(commentForm.handleComment(commentForm, "action"))
|
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):
|
def test_can_not_add_comments_if_discussion_is_not_allowed(self):
|
||||||
"""Make sure that comments can't be posted if discussion is disabled.
|
"""Make sure that comments can't be posted if discussion is disabled.
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user