diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.py b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.py index 4ca13bcf345c3278da40f7109b52b21895507401..e82c405d74347645bde05a84bdfec1fd18b1ddb5 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.py +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/DiscussionThread_createNewDiscussionPost.py @@ -26,10 +26,12 @@ discussion_post = discussion_thread.newContent( # handle attachments if getattr(file, 'filename', '') != '': - document_kw = {'batch_mode': True, - 'redirect_to_document': False, - 'file': file} - document = context.Base_contribute(**document_kw) + document = context.Base_contribute( + batch_mode=True, + redirect_to_document=False, + synchronous_metadata_discovery=True, + file=file, + ) # set relation between post and document discussion_post.setSuccessorValueList([document]) diff --git a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.py b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.py index 04cadaff378f968dcf9e52d4b22c909c6bbb0bb1..36b40c1dca14c86bec0049fa1cdb83e7b1f80eab 100644 --- a/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.py +++ b/bt5/erp5_discussion/SkinTemplateItem/portal_skins/erp5_discussion/WebSection_createNewDiscussionThread.py @@ -94,10 +94,12 @@ discussion_thread.publish() # handle attachments if getattr(file, 'filename', '') != '': - document_kw = {'batch_mode': True, - 'redirect_to_document': False, - 'file': file} - document = context.Base_contribute(**document_kw) + document = context.Base_contribute( + batch_mode=True, + redirect_to_document=False, + synchronous_metadata_discovery=True, + file=file, + ) # set relation between post and document discussion_post.setSuccessorValueList([document]) diff --git a/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.py b/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.py index 3af936063c1ba2149dc0e4a750f13bc7dd47f355..047c6288a2c2523f925239cfed72edb594a290de 100644 --- a/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.py +++ b/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.py @@ -229,6 +229,47 @@ class TestERP5Discussion(ERP5TypeTestCase): s = "a test by ivan !@#$%^&*()[]\\é" self.assertEqual('a-test-by-ivan', self.portal.Base_generateReferenceFromString(s)) + def test_AttachmentIngestion(self): + """ + Test the attachment of a CSV file, from both newDiscussionPost and newDiscussionThread + use cases. + CSV wasn't chosen randomly, as it may be subjected to a portal type migration through + discover metadata, which used to cause a bug. + """ + discussion_thread_id_set = set(self.portal.discussion_thread_module.objectIds()) + + web_site_value = self.portal.web_site_module.newContent(portal_type='Web Site') + web_section_value = web_site_value.newContent(portal_type='Web Section') + file_ = makeFileUpload('simple.csv') + web_section_value.WebSection_createNewDiscussionThread( + "Thread Title", + "Post Content", + file=file_ + ) + self.tic() + thread_value, = [ + x for x in self.portal.discussion_thread_module.objectValues() + if x.getId() not in discussion_thread_id_set + ] + + post_value, = thread_value.objectValues(portal_type='Discussion Post') + tested_post_value_set = {post_value,} + attachment_list = post_value.DiscussionPost_getAttachmentList() + self.assertEqual(1, len(attachment_list)) + + thread_value.DiscussionThread_createNewDiscussionPost( + title="Post Title", + text_content="Post Content", + file=file_, + ) + self.tic() + post_value, = [ + x for x in thread_value.objectValues() + if x not in tested_post_value_set + ] + attachment_list = post_value.DiscussionPost_getAttachmentList() + self.assertEqual(1, len(attachment_list)) + def test_suite(): suite = unittest.TestSuite() suite.addTest(unittest.makeSuite(TestERP5Discussion)) diff --git a/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.xml b/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.xml index 34b0a88ebc23acc6ef19378242689e645cc50487..a158a9d7d2e16f5b67d20901cb73a73a194b776f 100644 --- a/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.xml +++ b/bt5/erp5_discussion/TestTemplateItem/portal_components/test.erp5.testERP5Discussion.xml @@ -6,6 +6,12 @@ </pickle> <pickle> <dictionary> + <item> + <key> <string>_recorded_property_dict</string> </key> + <value> + <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> + </value> + </item> <item> <key> <string>default_reference</string> </key> <value> <string>testERP5Discussion</string> </value> @@ -53,13 +59,28 @@ <item> <key> <string>workflow_history</string> </key> <value> - <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> + <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> </value> </item> </dictionary> </pickle> </record> <record id="2" aka="AAAAAAAAAAI="> + <pickle> + <global name="PersistentMapping" module="Persistence.mapping"/> + </pickle> + <pickle> + <dictionary> + <item> + <key> <string>data</string> </key> + <value> + <dictionary/> + </value> + </item> + </dictionary> + </pickle> + </record> + <record id="3" aka="AAAAAAAAAAM="> <pickle> <global name="PersistentMapping" module="Persistence.mapping"/> </pickle> @@ -72,7 +93,7 @@ <item> <key> <string>component_validation_workflow</string> </key> <value> - <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> + <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent> </value> </item> </dictionary> @@ -81,7 +102,7 @@ </dictionary> </pickle> </record> - <record id="3" aka="AAAAAAAAAAM="> + <record id="4" aka="AAAAAAAAAAQ="> <pickle> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> </pickle> diff --git a/product/ERP5OOo/tests/test_document/simple.csv b/product/ERP5OOo/tests/test_document/simple.csv new file mode 100644 index 0000000000000000000000000000000000000000..ea16e67fc266874b7faa54e1cfb4afe5a10e3948 --- /dev/null +++ b/product/ERP5OOo/tests/test_document/simple.csv @@ -0,0 +1,2 @@ +a,b,c +1,2,3