Merge pull request #23 from bdbaddog/fix_comment_user_migration
fix migration of author_name and author_username
This commit is contained in:
commit
6f675b6f80
@ -70,6 +70,7 @@ class View(BrowserView):
|
||||
workflow = context.portal_workflow
|
||||
oldchain = workflow.getChainForPortalType('Discussion Item')
|
||||
new_workflow = workflow.comment_review_workflow
|
||||
mt = getToolByName(self.context, 'portal_membership')
|
||||
|
||||
if type(oldchain) == TupleType and len(oldchain) > 0:
|
||||
oldchain = oldchain[0]
|
||||
@ -89,17 +90,30 @@ class View(BrowserView):
|
||||
|
||||
new_in_reply_to = None
|
||||
if should_migrate:
|
||||
|
||||
# create a reply object
|
||||
# create a reply object
|
||||
comment = CommentFactory()
|
||||
comment.title = reply.Title()
|
||||
comment.text = reply.cooked_text
|
||||
comment.mime_type = 'text/html'
|
||||
comment.creator = reply.Creator()
|
||||
|
||||
email = reply.getProperty('email', None)
|
||||
if email:
|
||||
comment.author_email = email
|
||||
try:
|
||||
comment.author_username = reply.author_username
|
||||
except AttributeError:
|
||||
comment.author_username = reply.Creator()
|
||||
|
||||
member = mt.getMemberById(comment.author_username)
|
||||
if member:
|
||||
comment.author_name = member.fullname
|
||||
|
||||
if not comment.author_name:
|
||||
# In migrated site member.fullname ='' while member.getProperty('fullname') has the correct value
|
||||
comment.author_name = member.getProperty('fullname')
|
||||
|
||||
try:
|
||||
comment.author_email = reply.email
|
||||
except AttributeError:
|
||||
comment.author_email = None
|
||||
|
||||
comment.creation_date = DT2dt(reply.creation_date)
|
||||
comment.modification_date = DT2dt(reply.modification_date)
|
||||
|
@ -50,6 +50,13 @@ class MigrationTest(unittest.TestCase):
|
||||
self.workflowTool.setChainForPortalTypes(('Discussion Item',),
|
||||
'comment_review_workflow')
|
||||
|
||||
# Create a user Jimmy Jones so comments creator migration can work?
|
||||
acl_users = getToolByName(self.portal, 'acl_users')
|
||||
acl_users.userFolderAddUser('Jim', 'secret', ['Member'], [])
|
||||
mt = getToolByName(self.portal, 'portal_membership')
|
||||
member = mt.getMemberById('Jim')
|
||||
member.fullname = 'Jimmy Jones'
|
||||
|
||||
self.doc = self.portal.doc
|
||||
|
||||
def test_migrate_comment(self):
|
||||
@ -95,6 +102,63 @@ class MigrationTest(unittest.TestCase):
|
||||
], 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, '<p>My Text</p>\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
|
||||
#
|
||||
|
Loading…
Reference in New Issue
Block a user