Commit 661a3bfe authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_ingestion: Use script and type based method to add or not published state

The initial idea was that publishing documents is something really exceptional, the "attach document" normal use case is typically use cases like attaching a PDF invoice to an invoice document in accounting, ie. most of the time it's with sensitive information that we don't want users to be mistakenly publish on the internet just because they selected a wrong value in the field.

Now we have a project with use cases where the attached documents needs to be published, we did not change our mind that publishing an attached document is an exceptional case, but we want to make it possible to configure so that in certain contexts, publishing documents is possible.

So we reuse the existing configuration by type based method idea and when the getPreferredAttachedDocumentPublicationState returns "published" we make it possible to publish by default.
parent 9371393b
Pipeline #19854 failed with stage
in 0 seconds
translate = context.Base_translateString
item_list = [("", "")] + [
(translate(x), y) for x,y in [
("Draft", "draft"), ("Shared", "shared"), ("Released", "released"),
]
]
if context.getTypeBasedMethod('getPreferredAttachedDocumentPublicationState')() == "published":
item_list.append((translate("Published"), "published"))
return item_list
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Base_getAttachedDocumentPublicationStateItemList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -142,7 +142,7 @@ ...@@ -142,7 +142,7 @@
<dictionary> <dictionary>
<item> <item>
<key> <string>_text</string> </key> <key> <string>_text</string> </key>
<value> <string>python: [("", ""),] + [(here.Base_translateString(x), y) for x,y in [("Draft", "draft"), ("Shared", "shared"), ("Released", "released"),]]</string> </value> <value> <string>here/Base_getAttachedDocumentPublicationStateItemList</string> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
......
...@@ -195,6 +195,9 @@ class DiscoverableMixin(CachedConvertableMixin): ...@@ -195,6 +195,9 @@ class DiscoverableMixin(CachedConvertableMixin):
document.share() document.share()
elif publication_state == "released": elif publication_state == "released":
document.release() document.release()
elif publication_state == "published":
document.publish()
maybeChangeState(self) maybeChangeState(self)
# Finish ingestion by calling method # Finish ingestion by calling method
......
...@@ -6,6 +6,12 @@ ...@@ -6,6 +6,12 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item> <item>
<key> <string>default_reference</string> </key> <key> <string>default_reference</string> </key>
<value> <string>DiscoverableMixin</string> </value> <value> <string>DiscoverableMixin</string> </value>
...@@ -53,13 +59,28 @@ ...@@ -53,13 +59,28 @@
<item> <item>
<key> <string>workflow_history</string> </key> <key> <string>workflow_history</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="2" aka="AAAAAAAAAAI="> <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> <pickle>
<global name="PersistentMapping" module="Persistence.mapping"/> <global name="PersistentMapping" module="Persistence.mapping"/>
</pickle> </pickle>
...@@ -72,7 +93,7 @@ ...@@ -72,7 +93,7 @@
<item> <item>
<key> <string>component_validation_workflow</string> </key> <key> <string>component_validation_workflow</string> </key>
<value> <value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent> <persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value> </value>
</item> </item>
</dictionary> </dictionary>
...@@ -81,7 +102,7 @@ ...@@ -81,7 +102,7 @@
</dictionary> </dictionary>
</pickle> </pickle>
</record> </record>
<record id="3" aka="AAAAAAAAAAM="> <record id="4" aka="AAAAAAAAAAQ=">
<pickle> <pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/> <global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle> </pickle>
......
...@@ -40,7 +40,8 @@ from Products.ERP5Type.Utils import convertToUpperCase ...@@ -40,7 +40,8 @@ from Products.ERP5Type.Utils import convertToUpperCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ( from Products.ERP5Type.tests.ERP5TypeTestCase import (
ERP5TypeTestCase, _getConversionServerUrlList) ERP5TypeTestCase, _getConversionServerUrlList)
from Products.ERP5Type.tests.Sequence import SequenceList from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.tests.utils import FileUpload, createZODBPythonScript from Products.ERP5Type.tests.utils import FileUpload, removeZODBPythonScript, \
createZODBPythonScript
from Products.ERP5OOo.OOoUtils import OOoBuilder from Products.ERP5OOo.OOoUtils import OOoBuilder
from Products.CMFCore.utils import getToolByName from Products.CMFCore.utils import getToolByName
from zExceptions import BadRequest from zExceptions import BadRequest
...@@ -2025,6 +2026,53 @@ return result ...@@ -2025,6 +2026,53 @@ return result
self.assertTrue(document is not None) self.assertTrue(document is not None)
self.assertEqual(document.getData(), data) self.assertEqual(document.getData(), data)
def test_publication_state_in_Base_viewNewFileDialog(self):
"""
Checks that with type based method returning 'published',
we can upload with Base_viewNewFileDialog and declare the document as 'published'
"""
person = self.portal.person_module.newContent(portal_type="Person")
method_id = "Person_getPreferredAttachedDocumentPublicationState"
skin_folder = self.portal.portal_skins.custom
if not getattr(skin_folder, method_id, False):
createZODBPythonScript(skin_folder, method_id, "", "return")
skin_folder[method_id].ZPythonScript_edit('', 'return ""')
self.tic()
item_list = person.Base_viewNewFileDialog.your_publication_state.get_value("items")
self.assertEqual(
item_list,
[('', ''), ('Draft', 'draft'), ('Shared', 'shared'), ('Released', 'released')])
skin_folder[method_id].ZPythonScript_edit('', 'return None')
self.tic()
item_list = person.Base_viewNewFileDialog.your_publication_state.get_value("items")
self.assertEqual(
item_list,
[('', ''), ('Draft', 'draft'), ('Shared', 'shared'), ('Released', 'released')])
skin_folder[method_id].ZPythonScript_edit('', 'return "published"')
self.tic()
item_list = person.Base_viewNewFileDialog.your_publication_state.get_value("items")
self.assertEqual(
item_list, [
('', ''), ('Draft', 'draft'), ('Shared', 'shared'),
('Released', 'released'), ('Published', 'published')
])
# clean up and check if we don't have the script and published state in the list
removeZODBPythonScript(skin_folder, method_id)
self.tic()
self.assertEqual(
person.getTypeBasedMethod('getPreferredAttachedDocumentPublicationSection').getId(),
"Base_getPreferredAttachedDocumentPublicationSection"
)
self.portal.changeSkin(None)
item_list = person.Base_viewNewFileDialog.your_publication_state.get_value("items")
self.assertEqual(
item_list,
[('', ''), ('Draft', 'draft'), ('Shared', 'shared'), ('Released', 'released')])
class Base_contributeMixin: class Base_contributeMixin:
"""Tests for Base_contribute script. """Tests for Base_contribute script.
...@@ -2149,6 +2197,24 @@ class Base_contributeMixin: ...@@ -2149,6 +2197,24 @@ class Base_contributeMixin:
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf')) file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic() self.tic()
self.assertEqual(contributed_document.getValidationState(), 'released') self.assertEqual(contributed_document.getValidationState(), 'released')
contributed_document.setReference(None)
self.tic()
contributed_document = person.Base_contribute(
synchronous_metadata_discovery=False,
publication_state='published',
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'published')
contributed_document.setReference(None)
self.tic()
contributed_document = person.Base_contribute(
synchronous_metadata_discovery=True,
publication_state='published',
file=makeFileUpload('TEST-en-002.pdf', as_name='doc.pdf'))
self.tic()
self.assertEqual(contributed_document.getValidationState(), 'published')
def test_Base_contribute_publication_state_vs_finishIngestion_script(self): def test_Base_contribute_publication_state_vs_finishIngestion_script(self):
"""Contribute dialog allow choosing a publication state, but there's """Contribute dialog allow choosing a publication state, but there's
......
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