summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNicolas Demonte <nicolas@affinitic.be>2019-03-01 13:07:40 (GMT)
committerNicolas Demonte <nicolas@affinitic.be>2019-03-01 13:07:40 (GMT)
commitc7707a34adbb998f570be79d7d935f6074e22769 (patch)
treeb65b0d51e47c9574fda49b74d1ee4cdd7d54ec3f
parentced874866e28099c9ff6bd8fe5a323e9257749c7 (diff)
downloadpfwbged.policy-c7707a34adbb998f570be79d7d935f6074e22769.zip
pfwbged.policy-c7707a34adbb998f570be79d7d935f6074e22769.tar.gz
pfwbged.policy-c7707a34adbb998f570be79d7d935f6074e22769.tar.bz2
Add refused state for versions (+ upgrade step) #22010
-rw-r--r--src/pfwbged/policy/profiles/default/metadata.xml2
-rw-r--r--src/pfwbged/policy/profiles/default/workflows/versionnote_workflow/definition.xml27
-rw-r--r--src/pfwbged/policy/subscribers/document.py4
-rw-r--r--src/pfwbged/policy/upgrades/configure.zcml18
-rw-r--r--src/pfwbged/policy/upgrades/workflow.py51
5 files changed, 97 insertions, 5 deletions
diff --git a/src/pfwbged/policy/profiles/default/metadata.xml b/src/pfwbged/policy/profiles/default/metadata.xml
index d5622a4..045ee67 100644
--- a/src/pfwbged/policy/profiles/default/metadata.xml
+++ b/src/pfwbged/policy/profiles/default/metadata.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<metadata>
- <version>3</version>
+ <version>4</version>
<dependencies>
<dependency>profile-collective.dms.basecontent:default</dependency>
<dependency>profile-collective.dms.batchimport:default</dependency>
diff --git a/src/pfwbged/policy/profiles/default/workflows/versionnote_workflow/definition.xml b/src/pfwbged/policy/profiles/default/workflows/versionnote_workflow/definition.xml
index 5106c65..fb9398e 100644
--- a/src/pfwbged/policy/profiles/default/workflows/versionnote_workflow/definition.xml
+++ b/src/pfwbged/policy/profiles/default/workflows/versionnote_workflow/definition.xml
@@ -16,7 +16,6 @@
<exit-transition transition_id="submit"/>
<exit-transition transition_id="ask_opinion"/>
<exit-transition transition_id="obsolete"/>
- <exit-transition transition_id="cancel-refusal"/>
<permission-map name="View" acquired="False">
<permission-role>Editor</permission-role>
<permission-role>Manager</permission-role>
@@ -134,6 +133,30 @@
<permission-role>Manager</permission-role>
</permission-map>
</state>
+ <state state_id="refused" title="Refused" i18n:attributes="title">
+ <exit-transition transition_id="cancel-refusal"/>
+ <exit-transition transition_id="obsolete"/>
+ <permission-map name="View" acquired="False">
+ <permission-role>Editor</permission-role>
+ <permission-role>Manager</permission-role>
+ <permission-role>Reader</permission-role>
+ <permission-role>Reviewer</permission-role>
+ <permission-role>Owner</permission-role>
+ </permission-map>
+ <permission-map name="Access contents information" acquired="False">
+ <permission-role>Editor</permission-role>
+ <permission-role>Manager</permission-role>
+ <permission-role>Reader</permission-role>
+ <permission-role>Reviewer</permission-role>
+ <permission-role>Owner</permission-role>
+ </permission-map>
+ <permission-map name="Modify portal content" acquired="False">
+ <permission-role>Manager</permission-role>
+ </permission-map>
+ <permission-map name="Delete objects" acquired="False">
+ <permission-role>Manager</permission-role>
+ </permission-map>
+ </state>
<state state_id="trashed" title="Trashed" i18n:attributes="title">
<exit-transition transition_id="restore_from_trash"/>
<permission-map name="View" acquired="False">
@@ -189,7 +212,7 @@
<guard>
</guard>
</transition>
- <transition transition_id="refuse" title="Refuse" new_state="draft" trigger="USER" before_script="" after_script="" i18n:attributes="title">
+ <transition transition_id="refuse" title="Refuse" new_state="refused" trigger="USER" before_script="" after_script="" i18n:attributes="title">
<action url="%(content_url)s/@@refuse?workflow_action=refuse" category="workflow" icon="" i18n:translate="">Refuse</action>
<guard>
<guard-expression>here/@@can_validate_or_refuse</guard-expression>
diff --git a/src/pfwbged/policy/subscribers/document.py b/src/pfwbged/policy/subscribers/document.py
index 0db62c6..841398f 100644
--- a/src/pfwbged/policy/subscribers/document.py
+++ b/src/pfwbged/policy/subscribers/document.py
@@ -89,7 +89,7 @@ def change_validation_state(context, event):
query = {'to_id': version_intid,
'from_interfaces_flattened': IValidation,
'from_attribute': 'target'}
- if event.new_state.id == 'draft':
+ if event.new_state.id == 'refused':
for ref in catalog.findRelations(query):
validation = ref.from_object
if api.content.get_state(validation) == 'todo':
@@ -254,7 +254,7 @@ def version_note_finished(context, event):
# make obsolete other versions
for version_brain in version_notes:
version = version_brain._unrestrictedGetObject()
- if api.content.get_state(obj=version) in ('draft', 'pending', 'validated'):
+ if api.content.get_state(obj=version) in ('draft', 'pending', 'refused', 'validated'):
api.content.transition(obj=version, transition='obsolete')
version.reindexObject(idxs=['review_state'])
context.__ac_local_roles_block__ = False
diff --git a/src/pfwbged/policy/upgrades/configure.zcml b/src/pfwbged/policy/upgrades/configure.zcml
index a29a09d..b2a920f 100644
--- a/src/pfwbged/policy/upgrades/configure.zcml
+++ b/src/pfwbged/policy/upgrades/configure.zcml
@@ -19,4 +19,22 @@
handler=".workflow.update_role_mappings"
profile="pfwbged.policy:default" />
+
+ <genericsetup:upgradeSteps
+ source="3"
+ destination="4"
+ profile="pfwbged.policy:default">
+
+ <genericsetup:upgradeStep
+ title="Set up refused version state"
+ description="Set refused state to version in draft state, that were lastly refused"
+ handler=".workflow.update_refused_version_state"
+ />
+
+ <genericsetup:upgradeDepends
+ title="Reimport workflows"
+ import_steps="workflow" />
+
+ </genericsetup:upgradeSteps>
+
</configure>
diff --git a/src/pfwbged/policy/upgrades/workflow.py b/src/pfwbged/policy/upgrades/workflow.py
index 707cf02..5e46d56 100644
--- a/src/pfwbged/policy/upgrades/workflow.py
+++ b/src/pfwbged/policy/upgrades/workflow.py
@@ -1,3 +1,5 @@
+from Acquisition import aq_base
+from Persistence import PersistentMapping
from Products.CMFCore.utils import getToolByName
from plone import api
@@ -23,3 +25,52 @@ def publish_document_subfolders(context):
transition="publish"
)
subfolder.reindexObject(idxs=['review_state'])
+
+
+def overrideStatusOf(wf_id, ob, old_status, new_status):
+ """Update a particular status in an object's workflow history,
+ e.g. dict returned by wf_tool.getStatusOf.
+ Derived from wf_tool.setStatusOf."""
+ wfh = None
+ has_history = 0
+ if hasattr(aq_base(ob), 'workflow_history'):
+ history = ob.workflow_history
+ if history is not None:
+ has_history = 1
+ wfh = history.get(wf_id, None)
+ if wfh is not None:
+ wfh = list(wfh)
+ if not wfh:
+ wfh = []
+ if old_status in wfh:
+ position = wfh.index(old_status)
+ wfh[position] = new_status
+ if not has_history:
+ ob.workflow_history = PersistentMapping()
+ ob.workflow_history[wf_id] = tuple(wfh)
+
+
+def update_refused_version_state(context):
+ """Set refused versions to refused state (instead of draft)."""
+ portal = api.portal.get()
+ if 'documents' in portal:
+ portal_catalog = api.portal.get_tool('portal_catalog')
+ portal_workflow = api.portal.get_tool('portal_workflow')
+ wf_id = portal_workflow.getChainFor('dmsmainfile')[0]
+ wf_def = portal_workflow.getWorkflowById(wf_id)
+
+ folder_path = '/'.join(portal['documents'].getPhysicalPath())
+ query = {'path': {
+ 'query': folder_path},
+ 'portal_type': 'dmsmainfile',
+ 'review_state': 'draft'}
+ results = portal_catalog.unrestrictedSearchResults(query)
+ for brain in results:
+ version = brain.getObject()
+ old_state = portal_workflow.getStatusOf(wf_id, version)
+ if old_state.get('action') == 'refuse':
+ new_state = old_state.copy()
+ new_state.update({'review_state': 'refused'})
+ overrideStatusOf(wf_id, version, old_state, new_state)
+ wf_def.updateRoleMappingsFor(version)
+ version.reindexObject(idxs=['allowedRolesAndUsers', 'review_state'])