[Zope-CVS] CVS: Packages3/workflow/stateful - configure.zcml:1.3 definition.py:1.4 instance.py:1.4
Ulrich Eck
ueck@net-labs.de
Fri, 7 Feb 2003 10:30:00 -0500
Update of /cvs-repository/Packages3/workflow/stateful
In directory cvs.zope.org:/tmp/cvs-serv17461/stateful
Modified Files:
configure.zcml definition.py instance.py
Log Message:
next steps towards a usable Stateful Workflow:
- Schema for ProcessDefinition, State, Transition
- views for TTW-Editing
- another try to get the transition-permissions working (still not done)
- configure optimization
=== Packages3/workflow/stateful/configure.zcml 1.2 => 1.3 ===
--- Packages3/workflow/stateful/configure.zcml:1.2 Thu Feb 6 17:03:06 2003
+++ Packages3/workflow/stateful/configure.zcml Fri Feb 7 10:29:29 2003
@@ -1,20 +1,94 @@
<zopeConfigure
xmlns="http://namespaces.zope.org/zope">
+<!-- Stateful ProcessDefintion -->
+
<content class="zope.app.workflow.stateful.definition.StatefulProcessDefinition">
<factory
id="StatefulProcessDefinition"
- permission="zope.ManageServices"
+ permission="zope.workflow.ManageProcessDefinitions"
+ />
+ <require
+ permission="zope.workflow.ManageProcessDefinitions"
+ interface="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
+ set_schema="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
+ />
+ <require
+ permission="zope.workflow.ManageProcessDefinitions"
+ interface="zope.app.interfaces.container.IReadContainer"
+ />
+ <implements
+ interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+ />
+</content>
+
+
+
+<!-- States Container -->
+
+<content class="zope.app.workflow.stateful.definition.StatesContainer">
+ <factory
+ id="StatefulStatesContainer"
+ permission="zope.workflow.ManageProcessDefinitions"
+ />
+ <require
+ permission="zope.workflow.ManageProcessDefinitions"
+ interface="zope.app.interfaces.workflow.stateful.IStatefulStatesContainer"
+ />
+ <implements
+ interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+ />
+</content>
+
+<!-- State -->
+
+<content class="zope.app.workflow.stateful.definition.State">
+ <factory
+ id="StatefulState"
+ permission="zope.workflow.ManageProcessDefinitions"
+ />
+ <require
+ permission="zope.workflow.ManageProcessDefinitions"
+ interface="zope.app.interfaces.workflow.stateful.IState"
+ set_schema="zope.app.interfaces.workflow.stateful.IState"
+ />
+ <implements
+ interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+ />
+</content>
+
+<!-- Transitions Container -->
+
+<content class="zope.app.workflow.stateful.definition.TransitionsContainer">
+ <factory
+ id="StatefulTransitionsContainer"
+ permission="zope.workflow.ManageProcessDefinitions"
/>
<require
- permission="zope.ManageServices"
- interface="zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition"
+ permission="zope.workflow.ManageProcessDefinitions"
+ interface="zope.app.interfaces.workflow.stateful.IStatefulTransitionsContainer"
/>
<implements
interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
/>
</content>
+<!-- Transition -->
+
+<content class="zope.app.workflow.stateful.definition.Transition">
+ <factory
+ id="StatefulTransition"
+ permission="zope.workflow.ManageProcessDefinitions"
+ />
+ <require
+ permission="zope.workflow.ManageProcessDefinitions"
+ interface="zope.app.interfaces.workflow.stateful.ITransition"
+ set_schema="zope.app.interfaces.workflow.stateful.ITransition"
+ />
+ <implements
+ interface="zope.app.interfaces.annotation.IAttributeAnnotatable"
+ />
+</content>
<!-- ContentWorkflowsUtility
=== Packages3/workflow/stateful/definition.py 1.3 => 1.4 ===
--- Packages3/workflow/stateful/definition.py:1.3 Thu Feb 6 17:03:06 2003
+++ Packages3/workflow/stateful/definition.py Fri Feb 7 10:29:30 2003
@@ -18,14 +18,13 @@
"""
__metaclass__ = type
-from types import StringTypes
from persistence import Persistent
from persistence.dict import PersistentDict
from zope.proxy.context import ContextMethod, ContextWrapper
-from zope.proxy.context import getWrapperData
+from zope.proxy.context import getWrapperData, getWrapperContainer
-from zope.component import getServiceManager
+from zope.app.interfaces.container import IReadContainer
from zope.app.interfaces.workflow import IProcessDefinition
from zope.app.interfaces.workflow.stateful import IStatefulProcessDefinition
@@ -39,7 +38,7 @@
-class State:
+class State(Persistent):
"""State."""
__implements__ = IState
@@ -53,12 +52,12 @@
-class Transition:
+class Transition(Persistent):
"""Transition."""
__implements__ = ITransition
- def __init__(self, source, destination, condition=None, permission=None,
+ def __init__(self, source=None, destination=None, condition=None, permission=None,
name=None, description=None):
super(Transition, self).__init__()
self.__source = source
@@ -66,14 +65,49 @@
self.__condition = condition
self.__permission = permission
- sourceState = property(lambda self: self.__source)
- destinationState = property(lambda self: self.__destination)
+ def getSourceState(self):
+ return self.__source
- condition = property(lambda self: self.__condition)
+ def setSourceState(self, source):
+ self.__source = source
+
+ def getDestinationState(self):
+ return self.__destination
+
+ def setDestinationState(self, destination):
+ self.__destination = destination
+
+ def getCondition(self):
+ return self.__condition
+
+ def setCondition(self, condition):
+ self.__condition = condition or None
+
+ def getPermission(self):
+ return self.__permission
+
+ def setPermission(self, permission):
+ self.__permission = permission or None
+
+
+ # See ITransition
+ sourceState = property(getSourceState, setSourceState, None,
+ "Source State of Transition.")
+
+ destinationState = property(getDestinationState, setDestinationState, None,
+ "Destination State of Transition.")
+
+ condition = property(getCondition, setCondition, None,
+ "Condition for Transition.")
+
+ permission = property(getPermission, setPermission, None,
+ "Permission for Transition.")
- permission = property(lambda self: self.__permission)
+ def getProcessDefinition(self):
+ return getWrapperContainer(self).getProcessDefinition()
+ getProcessDefinition = ContextMethod(getProcessDefinition)
@@ -88,7 +122,7 @@
class StatefulProcessDefinition(ProcessDefinition):
"""Stateful workflow process definition."""
- __implements__ = IStatefulProcessDefinition
+ __implements__ = IStatefulProcessDefinition, IReadContainer
def __init__(self):
super(StatefulProcessDefinition, self).__init__()
@@ -103,12 +137,23 @@
# Implementation methods for interface
# zope.app.interfaces.workflow.stateful.IStatefulProcessDefinition
+ def getRelevantDataSchema(self):
+ return self.__schema
+
+ def setRelevantDataSchema(self, schema):
+ self.__schema = schema
+
+ relevantDataSchema = property(getRelevantDataSchema,
+ setRelevantDataSchema,
+ None,
+ "Schema for RelevantData.")
- states = property(lambda self: ContextWrapper(self.__states, self))
- transitions = property(lambda self: ContextWrapper(self.__transitions,
- self))
+ states = property(lambda self: self.__states)
+
+ transitions = property(lambda self: self.__transitions)
+
def addState(self, name, state):
if name in self.states:
raise KeyError, name
@@ -152,16 +197,63 @@
return pi_obj
createProcessInstance = ContextMethod(createProcessInstance)
- def setSchema(self, schema):
- self.__schema = schema
+ #
+ ############################################################
+
+
+ ############################################################
+ # Implementation methods for interface
+ # zope.app.interfaces.container.IReadContainer
+
+ def __getitem__(self, key):
+ "See Interface.Common.Mapping.IReadMapping"
+
+ result = self.get(key)
+ if result is None:
+ raise KeyError(key)
+
+ return result
+
+ __getitem__ = ContextMethod(__getitem__)
+
+ def get(self, key, default=None):
+ "See Interface.Common.Mapping.IReadMapping"
+
+ if key == 'states':
+ return self.states
+
+ if key == 'transitions':
+ return self.transitions
+
+ return default
+
+ get = ContextMethod(get)
+
+ def __contains__(self, key):
+ "See Interface.Common.Mapping.IReadMapping"
+
+ return self.get(key) is not None
+
+ # Enumeration methods. We'll only expose Packages for now:
+ def __iter__(self):
+ return iter(self.keys())
+
+ def keys(self):
+ return ['states', 'transitions']
+
+ def values(self):
+ return map(self.get, self.keys())
+
+ values = ContextMethod(values)
+
+ def items(self):
+ return [(key, self.get(key)) for key in self.keys()]
+
+ items = ContextMethod(items)
+
+ def __len__(self):
+ return 2
- def getSchema(self):
- schema = self.__schema
- if type(schema) in StringTypes:
- sm = getServiceManager(self)
- return sm.resolve(schema)
- return schema
- getSchema = ContextMethod(getSchema)
#
############################################################
=== Packages3/workflow/stateful/instance.py 1.3 => 1.4 ===
--- Packages3/workflow/stateful/instance.py:1.3 Thu Feb 6 17:03:06 2003
+++ Packages3/workflow/stateful/instance.py Fri Feb 7 10:29:30 2003
@@ -19,15 +19,23 @@
"""
__metaclass__ = type
-
+from types import StringTypes
from persistence import Persistent
+from zope.schema import getFields
+
from zope.exceptions import Unauthorized
+
from zope.component import getService
+from zope.component import getServiceManager
+
from zope.proxy.context import ContextMethod
from zope.proxy.context import ContextWrapper,ContextAware
+
from zope.security.management import getSecurityManager
+from zope.security.checker import CheckerPublic
+from zope.app.security.permission import checkPermission
+
from zope.pagetemplate.engine import Engine
-from zope.schema import getFields
from zope.app.interfaces.workflow.stateful import IStatefulProcessInstance
from zope.app.workflow.instance import ProcessInstance
@@ -64,8 +72,14 @@
def initialize(self):
pd = self._getProcessDefinition()
self._status = pd.getInitialStateName()
+
+ # resolve schema class
+ schema = pd.getRelevantDataSchema()
+ if type(schema) in StringTypes:
+ sm = getServiceManager(self)
+ schema = sm.resolve(schema)
+
# create relevant-data
- schema = pd.getSchema()
self._data = self._buildRelevantData(schema)
# setup permission on data
@@ -80,8 +94,14 @@
for name, trans in pd.transitions.items():
if self.status == trans.sourceState:
# check permissions
- if trans.permission:
- if not sm.checkPermission(trans.permission, self):
+ if trans.permission is not None:
+ if trans.permission == 'zope.Public':
+ permission = CheckerPublic
+ else:
+ permission = checkPermission(self, trans.permission)
+
+ print str(permission), trans.permission, name
+ if not sm.checkPermission(permission, self):
continue
# evaluate conditions