Commit be7cf1e3 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 ed2f2376
Pipeline #19799 failed with stage
......@@ -2856,6 +2856,39 @@ return 1
[sub_document_value]
)
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 = "Base_getPreferredAttachedDocumentPublicationState"
skin_folder = self.portal.portal_skins.erp5_ingestion
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')
])
class TestDocumentWithSecurity(TestDocumentMixin):
username = 'yusei'
......
......@@ -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>testDms</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>
......
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 @@
<dictionary>
<item>
<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>
</dictionary>
</pickle>
......
......@@ -195,6 +195,9 @@ class DiscoverableMixin(CachedConvertableMixin):
document.share()
elif publication_state == "released":
document.release()
elif publication_state == "published":
document.publish()
maybeChangeState(self)
# Finish ingestion by calling method
......
......@@ -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>DiscoverableMixin</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>
......
......@@ -2091,6 +2091,16 @@ class Base_contributeMixin:
file=makeFileUpload('TEST-en-002.odt'))
self.assertEqual('PDF', contributed_document.getPortalType())
def test_Base_contribute_forced_publication_state(self):
"""Test contributing while forcing the publication state.
"""
person = self.portal.person_module.newContent(portal_type='Person')
contributed_document = person.Base_contribute(
publication_state='published',
file=makeFileUpload('TEST-en-002.odt'))
self.tic()
self.assertEqual('published', contributed_document.getValidationState())
def test_Base_contribute_input_parameter_dict(self):
"""Test contributing while entering input parameters.
"""
......
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