Commit e85adb8e authored by Jérome Perrin's avatar Jérome Perrin

officejs_support_request_ui: review document ingestion

Publishing was too open, sharing is a better state.

Setting the document as followup of the ticket and the support request
project and the support request organisation seems a good default to set
security so that project members or users working on the ticket can see
documents.

Also ingest document in two steps:

* first step is to create the document and activate DMS metadata discovery
* second step is to share the document, once the necessary roles have been
  given to the user

What's still not good with this approach is that DMS ingestion might
merge this new document with an already existing document. This case
is not supported and needs an extension to ingestion API
parent cf8e1da2
"""Called on a document ingested from a file post on support request app,
after the document is ingested and metadata are discovered.
"""
post = context.getPortalObject().restrictedTraverse(post_relative_url)
# set relation between post and document
post.setSuccessorValueList([context])
post.publish()
context.share()
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>post_relative_url</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Document_afterSupportRequestFilePostIngestion</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -2,6 +2,9 @@ from Products.ERP5Type.Message import translateString ...@@ -2,6 +2,9 @@ from Products.ERP5Type.Message import translateString
portal = context.getPortalObject() portal = context.getPortalObject()
follow_up_value = portal.restrictedTraverse(follow_up) follow_up_value = portal.restrictedTraverse(follow_up)
assert follow_up_value.getPortalType() == "Support Request" assert follow_up_value.getPortalType() == "Support Request"
if not web_site_relative_url:
web_site_relative_url = context.getWebSiteValue().getRelativeUrl()
web_site = portal.restrictedTraverse(web_site_relative_url)
post = context.PostModule_createHTMLPostFromText( post = context.PostModule_createHTMLPostFromText(
...@@ -10,41 +13,64 @@ post = context.PostModule_createHTMLPostFromText( ...@@ -10,41 +13,64 @@ post = context.PostModule_createHTMLPostFromText(
source_reference=source_reference, source_reference=source_reference,
) )
if file not in ("undefined", None): # XXX "undefined" ? should also be fixed in javascript side
document_kw = {'batch_mode': True,
'redirect_to_document': False,
'file': file}
# XXX this Base_contribute might update in place another document with same reference
# and leave the post with a "dead link" for successor value.
document = context.Base_contribute(**document_kw)
# set relation between post and document
# XXX successor is used as a way to put a relation between the attachment and the post,
# the actual way should be to use a proper container like an Event that will have
# one or several posts and one or several attachments.
post.setSuccessorValueList([document])
# XXX depending on security model this should be changed accordingly
document.publish() # XXX isn't it share a better default ?
# XXX the UI of support request app should be responsible for generating a unique # XXX the UI of support request app should be responsible for generating a unique
# "message id" for each posted message. # "message id" for each posted message.
if not post.getSourceReference(): if not post.getSourceReference():
post.setSourceReference(post.getId()) post.setSourceReference(post.getId())
ingest_document_tag = 'ingest-%s' % post.getSourceReference()
after_ingest_document_tag = 'after-ingest-%s' % post.getSourceReference()
if not web_site_relative_url: document = None
web_site_relative_url = context.getWebSiteValue().getRelativeUrl() if file not in ("undefined", None): # XXX "undefined" ? should also be fixed in javascript side
follow_up_list = []
project = follow_up_value.getSourceProjectValue()
if project is not None:
follow_up_list.append(project.getRelativeUrl())
group = None
section = follow_up_value.getDestinationSectionValue()\
or follow_up_value.getDestinationValue()
if section is not None:
group = section.getGroup()
document_kw = {
'batch_mode': True,
'redirect_to_document': False,
'attach_document_to_context': True,
'follow_up_list': follow_up_list,
'group': group,
'classification': web_site.getLayoutProperty(
'preferred_attached_document_classification') or\
portal.portal_preferences.getPreferredDocumentClassification(),
'file': file,
}
with follow_up_value.defaultActivateParameterDict(
dict(tag=ingest_document_tag), placeless=True):
# XXX this Base_contribute might update in place another document with same reference
# and leave the post with a "dead link" for successor value.
document = follow_up_value.Base_contribute(**document_kw)
# XXX contribution API should allow to call a method on the final ingested document
# after ingestion is complete.
document.activate(
after_tag=ingest_document_tag,
tag=after_ingest_document_tag,
).Document_afterSupportRequestFilePostIngestion(
post_relative_url=post.getRelativeUrl(), )
else:
# when we don't upload a document, we can publish the post now.
post.publish()
post.publish() # XXX post.activate(
post.activate().Post_ingestMailMessageForSupportRequest(# XXX This API is not agreed after_tag=after_ingest_document_tag
web_site_relative_url=web_site_relative_url # XXX This API is not agreed. Also, we need to consider the possibility
) # of ingesting posts through alarm, which is required when we want to ingest
# post without owners (from anoymous users).
).Post_ingestMailMessageForSupportRequest(
web_site_relative_url=web_site_relative_url)
# to be able to display the just posted data in SupportRequest_getCommentPostListAsJson, # to be able to display the just posted data in SupportRequest_getCommentPostListAsJson,
# we store it in a session variable. # we store it in a session variable.
successor_list = post.getSuccessorValueList()
successor_name = successor_link = None successor_name = successor_link = None
if successor_list: if document is not None:
successor_link, successor_name = successor_list[0].getRelativeUrl(), successor_list[0].getFilename() successor_link, successor_name = document.getRelativeUrl(), document.getFilename()
portal.portal_sessions[ portal.portal_sessions[
'%s.latest_comment' % follow_up_value.getRelativeUrl()]['comment_post_list'] = dict( '%s.latest_comment' % follow_up_value.getRelativeUrl()]['comment_post_list'] = dict(
user=post.Base_getOwnerTitle(), user=post.Base_getOwnerTitle(),
......
...@@ -297,6 +297,12 @@ class TestSupportRequestCommentOnExistingSupportRequest(SupportRequestTestCase): ...@@ -297,6 +297,12 @@ class TestSupportRequestCommentOnExistingSupportRequest(SupportRequestTestCase):
) )
self.assertEqual('attached_file.txt', file_document.getFilename()) self.assertEqual('attached_file.txt', file_document.getFilename())
self.assertEqual('the text content', str(file_document.getData())) self.assertEqual('the text content', str(file_document.getData()))
self.assertEqual('shared', file_document.getValidationState())
# this document is also attached to the context of the support request
# and is visible from the document tab.
self.assertIn(
file_document,
[doc.getObject() for doc in support_request.Base_getRelatedDocumentList()])
# the API to get comments also works once ingested # the API to get comments also works once ingested
self.assertEqual( self.assertEqual(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment