Commit 8d5a3ce4 authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

workflow: provide legacy WorkflowHistoryList for backward compatibility even...

workflow: provide legacy WorkflowHistoryList for backward compatibility even if WITH_LEGACY_WORKFLOW is False.
parent cd967cac
...@@ -37,8 +37,7 @@ if WITH_LEGACY_WORKFLOW: ...@@ -37,8 +37,7 @@ if WITH_LEGACY_WORKFLOW:
from Products.ERP5Type.patches import DCWorkflow from Products.ERP5Type.patches import DCWorkflow
from Products.ERP5Type.patches import Worklists from Products.ERP5Type.patches import Worklists
from Products.ERP5Type.patches import BTreeFolder2 from Products.ERP5Type.patches import BTreeFolder2
if WITH_LEGACY_WORKFLOW: from Products.ERP5Type.patches import WorkflowTool
from Products.ERP5Type.patches import WorkflowTool
from Products.ERP5Type.patches import DynamicType from Products.ERP5Type.patches import DynamicType
from Products.ERP5Type.patches import Expression from Products.ERP5Type.patches import Expression
from Products.ERP5Type.patches import sqltest from Products.ERP5Type.patches import sqltest
......
...@@ -13,41 +13,7 @@ ...@@ -13,41 +13,7 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type import WITH_LEGACY_WORKFLOW
assert WITH_LEGACY_WORKFLOW
from zLOG import LOG, WARNING
from types import StringTypes
# Make sure Interaction Workflows are called even if method not wrapped
from AccessControl import ClassSecurityInfo, Unauthorized
from Products.ERP5Type.Globals import InitializeClass
from Products.CMFCore.WorkflowTool import WorkflowTool
from Products.CMFCore.WorkflowCore import ObjectDeleted
from Products.CMFCore.WorkflowCore import WorkflowException
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD
from Products.DCWorkflow.utils import Message as _
from Products.DCWorkflow.Transitions import TRIGGER_USER_ACTION
from Products.CMFCore.utils import getToolByName
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, AutoQuery, ComplexQuery, NegatedQuery
from Products.CMFCore.utils import _getAuthenticatedUser
from Products.ERP5Type import Permissions
from Products.ERP5Type.Cache import CachingMethod
from Products.ERP5Type.Workflow import WorkflowHistoryList as NewWorkflowHistoryList from Products.ERP5Type.Workflow import WorkflowHistoryList as NewWorkflowHistoryList
from sets import ImmutableSet
from Acquisition import aq_base
from Products.ERP5Type.Globals import PersistentMapping
from MySQLdb import ProgrammingError, OperationalError
from DateTime import DateTime
security = ClassSecurityInfo()
WorkflowTool.security = security
WORKLIST_METADATA_KEY = 'metadata'
SECURITY_PARAMETER_ID = 'local_roles'
class WorkflowHistoryList(NewWorkflowHistoryList): class WorkflowHistoryList(NewWorkflowHistoryList):
...@@ -105,21 +71,56 @@ class WorkflowHistoryList(NewWorkflowHistoryList): ...@@ -105,21 +71,56 @@ class WorkflowHistoryList(NewWorkflowHistoryList):
# BBB: A production instance used a temporary patch to speed up. # BBB: A production instance used a temporary patch to speed up.
WorkflowHistoryBucketList = WorkflowHistoryList WorkflowHistoryBucketList = WorkflowHistoryList
def WorkflowTool_getChainDict(self): from Products.ERP5Type import WITH_LEGACY_WORKFLOW
if WITH_LEGACY_WORKFLOW:
import six
from zLOG import LOG, WARNING
from types import StringTypes
# Make sure Interaction Workflows are called even if method not wrapped
from AccessControl import ClassSecurityInfo, Unauthorized
from Products.ERP5Type.Globals import InitializeClass
from Products.CMFCore.WorkflowTool import WorkflowTool
from Products.CMFCore.WorkflowCore import ObjectDeleted
from Products.CMFCore.WorkflowCore import WorkflowException
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.DCWorkflow.Transitions import TRIGGER_WORKFLOW_METHOD
from Products.DCWorkflow.utils import Message as _
from Products.DCWorkflow.Transitions import TRIGGER_USER_ACTION
from Products.CMFCore.utils import getToolByName
from Products.ZSQLCatalog.SQLCatalog import SimpleQuery, AutoQuery, ComplexQuery, NegatedQuery
from Products.CMFCore.utils import _getAuthenticatedUser
from Products.ERP5Type import Permissions
from Products.ERP5Type.Cache import CachingMethod
from sets import ImmutableSet
from Acquisition import aq_base
from Products.ERP5Type.Globals import PersistentMapping
from MySQLdb import ProgrammingError, OperationalError
from DateTime import DateTime
security = ClassSecurityInfo()
WorkflowTool.security = security
WORKLIST_METADATA_KEY = 'metadata'
SECURITY_PARAMETER_ID = 'local_roles'
def WorkflowTool_getChainDict(self):
"""Test if the given transition exist from the current state. """Test if the given transition exist from the current state.
""" """
chain_dict = {} chain_dict = {}
for portal_type, wf_id_list in self._chains_by_type.iteritems(): for portal_type, wf_id_list in six.iteritems(self._chains_by_type):
for wf_id in wf_id_list: for wf_id in wf_id_list:
chain_dict.setdefault(wf_id, []).append(portal_type) chain_dict.setdefault(wf_id, []).append(portal_type)
return chain_dict return chain_dict
security.declareProtected(Permissions.ManagePortal, 'getChainDict') security.declareProtected(Permissions.ManagePortal, 'getChainDict')
WorkflowTool.getChainDict = WorkflowTool_getChainDict WorkflowTool.getChainDict = WorkflowTool_getChainDict
# Backward compatibility, as WorkflowMethod has been removed in CMFCore 2.2 # Backward compatibility, as WorkflowMethod has been removed in CMFCore 2.2
from MethodObject import Method from MethodObject import Method
class WorkflowMethod( Method ): class WorkflowMethod( Method ):
""" Wrap a method to workflow-enable it. """ Wrap a method to workflow-enable it.
""" """
...@@ -150,14 +151,14 @@ class WorkflowMethod( Method ): ...@@ -150,14 +151,14 @@ class WorkflowMethod( Method ):
res = wf.wrapWorkflowMethod(instance, self._id, self._m, res = wf.wrapWorkflowMethod(instance, self._id, self._m,
(instance,) + args, kw) (instance,) + args, kw)
from Products.CMFCore import WorkflowCore from Products.CMFCore import WorkflowCore
# BBB: WorkflowMethod has been removed from CMFCore 2 # BBB: WorkflowMethod has been removed from CMFCore 2
WorkflowCore.WorkflowAction = WorkflowMethod WorkflowCore.WorkflowAction = WorkflowMethod
# XXX: Kept here instead of ERP5Type.Tool.WorkflowTool because not used in # XXX: Kept here instead of ERP5Type.Tool.WorkflowTool because not used in
# erp5.git: is it used in projects? # erp5.git: is it used in projects?
security.declarePublic('canDoActionFor') security.declarePublic('canDoActionFor')
def canDoActionFor(self, ob, action, wf_id=None, guard_kw={}): def canDoActionFor(self, ob, action, wf_id=None, guard_kw={}):
""" Check we can perform the given workflow action on 'ob'. """ Check we can perform the given workflow action on 'ob'.
""" """
if wf_id is None: if wf_id is None:
...@@ -180,10 +181,10 @@ def canDoActionFor(self, ob, action, wf_id=None, guard_kw={}): ...@@ -180,10 +181,10 @@ def canDoActionFor(self, ob, action, wf_id=None, guard_kw={}):
raise WorkflowException(_(u"No workflow provides the '${action_id}' action.", raise WorkflowException(_(u"No workflow provides the '${action_id}' action.",
mapping={'action_id': action})) mapping={'action_id': action}))
WorkflowTool.canDoActionFor = canDoActionFor WorkflowTool.canDoActionFor = canDoActionFor
security.declarePrivate('_listTypeInfo') security.declarePrivate('_listTypeInfo')
def _listTypeInfo(self): def _listTypeInfo(self):
""" List the portal types which are available. """ List the portal types which are available.
""" """
# <patch> # <patch>
...@@ -193,17 +194,17 @@ def _listTypeInfo(self): ...@@ -193,17 +194,17 @@ def _listTypeInfo(self):
return ttool.listTypeInfo() return ttool.listTypeInfo()
return () return ()
WorkflowTool._listTypeInfo = _listTypeInfo WorkflowTool._listTypeInfo = _listTypeInfo
## From here on: migration/compatibility code DCWorkflow => ERP5 Workflow ## From here on: migration/compatibility code DCWorkflow => ERP5 Workflow
# The following 2 functions are necessary for workflow tool dynamic migration # The following 2 functions are necessary for workflow tool dynamic migration
def WorkflowTool_isBootstrapRequired(self): def WorkflowTool_isBootstrapRequired(self):
# migration is required if the tool is not the new one from ERP5 Workflow # migration is required if the tool is not the new one from ERP5 Workflow
# in case of old workflow tool, it acquires the portal type from ERP5 Site # in case of old workflow tool, it acquires the portal type from ERP5 Site
return self.getPortalType() != "Workflow Tool" return self.getPortalType() != "Workflow Tool"
def WorkflowTool_bootstrap(self): def WorkflowTool_bootstrap(self):
""" """
Migrate portal_workflow from CMFCore to ERP5 Workflow. Also migrate Migrate portal_workflow from CMFCore to ERP5 Workflow. Also migrate
Workflow Chains not defined anymore on portal_workflow but on the Portal Workflow Chains not defined anymore on portal_workflow but on the Portal
...@@ -244,20 +245,20 @@ def WorkflowTool_bootstrap(self): ...@@ -244,20 +245,20 @@ def WorkflowTool_bootstrap(self):
if getattr(new_tool, '_chains_by_type', None) is not None: if getattr(new_tool, '_chains_by_type', None) is not None:
new_tool.reassignWorkflowWithoutConversion() new_tool.reassignWorkflowWithoutConversion()
WorkflowTool._isBootstrapRequired = WorkflowTool_isBootstrapRequired WorkflowTool._isBootstrapRequired = WorkflowTool_isBootstrapRequired
WorkflowTool._bootstrap = WorkflowTool_bootstrap WorkflowTool._bootstrap = WorkflowTool_bootstrap
WorkflowTool.getWorkflowValueListFor = WorkflowTool.getWorkflowsFor WorkflowTool.getWorkflowValueListFor = WorkflowTool.getWorkflowsFor
def _deleteChainsByType(self, pt, wf_id): def _deleteChainsByType(self, pt, wf_id):
self._chains_by_type[pt] = tuple(wf for wf in self._chains_by_type[pt] if wf!=wf_id) self._chains_by_type[pt] = tuple(wf for wf in self._chains_by_type[pt] if wf!=wf_id)
def getChainsByType(self): def getChainsByType(self):
# XXX(WORKFLOW): compatibility code # XXX(WORKFLOW): compatibility code
# get old workflow tool's chains_by_type # get old workflow tool's chains_by_type
if self._chains_by_type is None: if self._chains_by_type is None:
return {} return {}
return self._chains_by_type.copy() return self._chains_by_type.copy()
WorkflowTool.getChainsByType = getChainsByType WorkflowTool.getChainsByType = getChainsByType
def reassignWorkflow(self, workflow_id): def reassignWorkflow(self, workflow_id):
# type-workflow reassignment # type-workflow reassignment
type_workflow_dict = self.getChainsByType() type_workflow_dict = self.getChainsByType()
type_tool = self.getPortalObject().portal_types type_tool = self.getPortalObject().portal_types
...@@ -274,8 +275,8 @@ def reassignWorkflow(self, workflow_id): ...@@ -274,8 +275,8 @@ def reassignWorkflow(self, workflow_id):
portal_type.setTypeWorkflowList( portal_type.setTypeWorkflowList(
type_workflow_list + [workflow_id] type_workflow_list + [workflow_id]
) )
WorkflowTool.reassignWorkflow = reassignWorkflow WorkflowTool.reassignWorkflow = reassignWorkflow
def reassignWorkflowWithoutConversion(self): def reassignWorkflowWithoutConversion(self):
# This function should be called when a new template installed and add # This function should be called when a new template installed and add
# portal_types assignment with converted and non-converted workflows into # portal_types assignment with converted and non-converted workflows into
# portal_type's workflow list. # portal_type's workflow list.
...@@ -305,10 +306,10 @@ def reassignWorkflowWithoutConversion(self): ...@@ -305,10 +306,10 @@ def reassignWorkflowWithoutConversion(self):
portal_type.setTypeWorkflowList( portal_type.setTypeWorkflowList(
type_workflow_list + [workflow_id] type_workflow_list + [workflow_id]
) )
WorkflowTool.reassignWorkflowWithoutConversion = reassignWorkflowWithoutConversion WorkflowTool.reassignWorkflowWithoutConversion = reassignWorkflowWithoutConversion
WorkflowTool.security.declareProtected(Permissions.AccessContentsInformation, WorkflowTool.security.declareProtected(Permissions.AccessContentsInformation,
'getWorkflowTempObjectList') 'getWorkflowTempObjectList')
def getWorkflowTempObjectList(self, temp_object=1, **kw): def getWorkflowTempObjectList(self, temp_object=1, **kw):
""" Return a list of converted temporary workflows. Only necessary in """ Return a list of converted temporary workflows. Only necessary in
Workflow Tool to get temporarilly converted DCWorkflow. Workflow Tool to get temporarilly converted DCWorkflow.
""" """
...@@ -320,6 +321,6 @@ def getWorkflowTempObjectList(self, temp_object=1, **kw): ...@@ -320,6 +321,6 @@ def getWorkflowTempObjectList(self, temp_object=1, **kw):
temp_workflow = dc_workflow.convertToERP5Workflow(temp_object=temp_object) temp_workflow = dc_workflow.convertToERP5Workflow(temp_object=temp_object)
temp_workflow_list.append(temp_workflow) temp_workflow_list.append(temp_workflow)
return temp_workflow_list return temp_workflow_list
WorkflowTool.getWorkflowTempObjectList = getWorkflowTempObjectList WorkflowTool.getWorkflowTempObjectList = getWorkflowTempObjectList
InitializeClass(WorkflowTool) InitializeClass(WorkflowTool)
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