From 6155e8c3362fbd38486e646c6ebf0c88399976e3 Mon Sep 17 00:00:00 2001 From: Rafael Monnerat <rafael@nexedi.com> Date: Fri, 18 Mar 2011 01:46:04 +0000 Subject: [PATCH] Initialize Workflow in a safer way, and do not permit use inconsistent Business Configurations. git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@44416 20353a03-c40f-0410-a6d1-a30d3c3de9de --- .../Document/BusinessConfiguration.py | 15 +++++++++++++-- product/ERP5Configurator/Tool/ConfiguratorTool.py | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/product/ERP5Configurator/Document/BusinessConfiguration.py b/product/ERP5Configurator/Document/BusinessConfiguration.py index 885610a72a..00581ecaec 100644 --- a/product/ERP5Configurator/Document/BusinessConfiguration.py +++ b/product/ERP5Configurator/Document/BusinessConfiguration.py @@ -91,6 +91,18 @@ class BusinessConfiguration(Item): """ return self.getCurrentStateTitle() == END_STATE_TITLE + security.declareProtected(Permissions.ModifyPortalContent, \ + 'initializeWorkflow') + def initializeWorkflow(self): + """ Initialize Related Workflow""" + workflow = self.getResourceValue() + if workflow is not None and \ + (self.getResource() not in self.workflow_history): + if len(self.objectValues("ERP5 Configuration Save")) > 0: + raise ValueError("Business Configuration Cannot be initialized, \ + it contains one or more Configurator Save") + workflow.initializeDocument(self) + security.declareProtected(Permissions.View, 'getNextTransition') def getNextTransition(self): """ Return next transition. """ @@ -269,8 +281,7 @@ class BusinessConfiguration(Item): next_state = self.unrestrictedTraverse(transition.getDestination()) workflow_history = current_state.getWorkflowHistory(self) for wh in workflow_history: - wh_state = self.unrestrictedTraverse(wh['current_state']) - if wh_state == next_state: + if next_state == self.unrestrictedTraverse(wh['current_state']): configuration_save = self.unrestrictedTraverse(wh['configuration_save_url']) return configuration_save diff --git a/product/ERP5Configurator/Tool/ConfiguratorTool.py b/product/ERP5Configurator/Tool/ConfiguratorTool.py index 84430450d0..58d062e1d5 100644 --- a/product/ERP5Configurator/Tool/ConfiguratorTool.py +++ b/product/ERP5Configurator/Tool/ConfiguratorTool.py @@ -231,6 +231,8 @@ class ConfiguratorTool(BaseTool): validation_errors = None response = {} + business_configuration.initializeWorkflow() + ## initial state no previous form to validate if business_configuration.isInitialConfigurationState(): need_validation = 0 -- 2.30.9