Commit 232ea9c4 authored by Vincent Pelletier's avatar Vincent Pelletier

erp5_dms: Only archive other versions when effective date is reached.

Also, make effective date visible and editable on relevant document views
lacking it.
Add a test.
parent 75a2ca47
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
<string>my_title</string> <string>my_title</string>
<string>my_short_title</string> <string>my_short_title</string>
<string>my_language</string> <string>my_language</string>
<string>my_effective_date</string>
<string>my_url_protocol</string> <string>my_url_protocol</string>
<string>my_url_string</string> <string>my_url_string</string>
<string>my_crawling_scope</string> <string>my_crawling_scope</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Document_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -98,6 +98,7 @@ ...@@ -98,6 +98,7 @@
<string>my_version</string> <string>my_version</string>
<string>my_language</string> <string>my_language</string>
<string>my_int_index</string> <string>my_int_index</string>
<string>my_effective_date</string>
<string>my_file</string> <string>my_file</string>
<string>my_filename</string> <string>my_filename</string>
<string>my_translated_portal_type</string> <string>my_translated_portal_type</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Document_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
<string>my_version</string> <string>my_version</string>
<string>my_language</string> <string>my_language</string>
<string>my_int_index</string> <string>my_int_index</string>
<string>my_effective_date</string>
<string>my_file</string> <string>my_file</string>
<string>my_filename</string> <string>my_filename</string>
<string>my_translated_portal_type</string> <string>my_translated_portal_type</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Document_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
<string>my_version</string> <string>my_version</string>
<string>my_language</string> <string>my_language</string>
<string>my_int_index</string> <string>my_int_index</string>
<string>my_effective_date</string>
<string>my_file</string> <string>my_file</string>
<string>my_filename</string> <string>my_filename</string>
<string>my_thumbnail</string> <string>my_thumbnail</string>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ProxyField" module="Products.ERP5Form.ProxyField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>message_values</string> </key>
<value>
<dictionary>
<item>
<key> <string>external_validator_failed</string> </key>
<value> <string>The input failed the external validator.</string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>overrides</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_effective_date</string> </value>
</item>
<item>
<key> <string>form_id</string> </key>
<value> <string>Document_viewFieldLibrary</string> </value>
</item>
<item>
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -50,26 +50,39 @@ ...@@ -50,26 +50,39 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string>"""\n <value> <string encoding="cdata"><![CDATA[
"""\n
This script is invoked each time a new document is published.\n This script is invoked each time a new document is published.\n
The previous version is archived automatically.\n The previous version is archived automatically if document has a past\n
(None being infinitely in the past) publication date.\n
\n \n
This will only apply to documents with enough coordinates\n This will only apply to documents with enough coordinates\n
(ex. reference, language, version).\n (ex. reference, language, version).\n
"""\n """\n
from Products.ZSQLCatalog.SQLCatalog import ComplexQuery, SimpleQuery\n
document = state_change[\'object\']\n document = state_change[\'object\']\n
reference = document.getReference()\n reference = document.getReference()\n
if not reference:\n if now is None:\n
now = DateTime()\n
if not reference or document.getEffectiveDate() > now:\n
# If this object has no reference, we can not do anything\n # If this object has no reference, we can not do anything\n
return\n return\n
\n \n
portal = document.getPortalObject()\n portal = document.getPortalObject()\n
portal_catalog = portal.portal_catalog\n portal_catalog = portal.portal_catalog\n
language = document.getLanguage()\n language = document.getLanguage()\n
search_kw = dict(reference=reference,\n search_kw = {\n
validation_state=validation_state,\n \'reference\': reference,\n
\'validation_state\': validation_state,\n
# exclude current workflow changed document\n # exclude current workflow changed document\n
uid=\'NOT %s\' %document.getUid())\n \'uid\': SimpleQuery(uid=document.getUid(), comparison_operator=\'!=\'),\n
\'effective_date\': ComplexQuery(\n
SimpleQuery(effective_date=None),\n
SimpleQuery(effective_date=now, comparison_operator=\'<=\'),\n
logical_operator=\'or\',\n
),\n
}\n
if not language:\n if not language:\n
# If language is None, we have to check is this document\n # If language is None, we have to check is this document\n
# is language independent. In this case, archival is possible\n # is language independent. In this case, archival is possible\n
...@@ -86,11 +99,13 @@ search_kw[\'language\'] = language\n ...@@ -86,11 +99,13 @@ search_kw[\'language\'] = language\n
for old_document in portal_catalog(**search_kw):\n for old_document in portal_catalog(**search_kw):\n
old_document = old_document.getObject()\n old_document = old_document.getObject()\n
old_document.archive()\n old_document.archive()\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>state_change, validation_state=[\'published\', \'published_alive\', \'released\', \'released_alive\', \'shared\', \'shared_alive\']</string> </value> <value> <string>state_change, validation_state=[\'published\', \'published_alive\', \'released\', \'released_alive\', \'shared\', \'shared_alive\'], now=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
1276 1277
\ No newline at end of file
...@@ -75,6 +75,7 @@ import re ...@@ -75,6 +75,7 @@ import re
from AccessControl import Unauthorized from AccessControl import Unauthorized
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
from Products.ERP5Type.tests.backportUnittest import expectedFailure from Products.ERP5Type.tests.backportUnittest import expectedFailure
from DateTime import DateTime
QUIET = 0 QUIET = 0
...@@ -2750,7 +2751,8 @@ return 1 ...@@ -2750,7 +2751,8 @@ return 1
def test_document_publication_workflow_archiveVersion(self): def test_document_publication_workflow_archiveVersion(self):
""" Test "visible" instances of a doc are auto archived when a new """ Test "visible" instances of a doc are auto archived when a new
instance is made "visible" """ instance is made "visible" except when they have a future effective date.
"""
portal = self.portal portal = self.portal
upload_file = makeFileUpload('TEST-en-002.doc') upload_file = makeFileUpload('TEST-en-002.doc')
...@@ -2760,20 +2762,36 @@ return 1 ...@@ -2760,20 +2762,36 @@ return 1
self.tic() self.tic()
document_003 = document_002.Base_createCloneDocument(batch_mode=1) document_003 = document_002.Base_createCloneDocument(batch_mode=1)
document_003.setEffectiveDate(DateTime() - 1)
document_003.publish() document_003.publish()
document_future_003 = document_002.Base_createCloneDocument(batch_mode=1)
document_future_003.setEffectiveDate(DateTime() + 10)
document_future_003.publish()
self.tic() self.tic()
self.assertEqual('published', document_003.getValidationState()) self.assertEqual('published', document_003.getValidationState())
self.assertEqual('archived', document_002.getValidationState()) self.assertEqual('archived', document_002.getValidationState())
self.assertEqual('published', document_future_003.getValidationState())
# check if in any case document doesn't archive itself # check if in any case document doesn't archive itself
# (i.e. shared_alive -> published or any other similar chain) # (i.e. shared_alive -> published or any other similar chain)
document_004 = document_003.Base_createCloneDocument(batch_mode=1) document_004 = document_002.Base_createCloneDocument(batch_mode=1)
document_004.shareAlive() document_004.shareAlive()
self.tic() self.tic()
document_004.publish() document_004.publish()
self.tic() self.tic()
self.assertEqual('published', document_004.getValidationState()) self.assertEqual('published', document_004.getValidationState())
# document_future_003 must not have been archived, as its effective date is
# in the future.
self.assertEqual('published', document_future_003.getValidationState())
document_005 = document_004.Base_createCloneDocument(batch_mode=1)
document_005.setEffectiveDate(DateTime() + 5)
document_005.publish()
self.tic()
# Also, document_004 must not have been archived, as document_005's
# effective_date is in the future.
self.assertEqual('published', document_004.getValidationState())
# check case when no language is used # check case when no language is used
document_nolang_005 = document_004.Base_createCloneDocument(batch_mode=1) document_nolang_005 = document_004.Base_createCloneDocument(batch_mode=1)
......
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