[CMF-checkins] CVS: CMF/DCWorkflow - DCWorkflow.py:1.33 WorkflowUIMixin.py:1.9

Shane Hathaway shane at zope.com
Wed Feb 4 15:35:51 EST 2004


Update of /cvs-repository/CMF/DCWorkflow
In directory cvs.zope.org:/tmp/cvs-serv8911

Modified Files:
	DCWorkflow.py WorkflowUIMixin.py 
Log Message:
Added allowCreate(), which can prevent the creation of object instances.


=== CMF/DCWorkflow/DCWorkflow.py 1.32 => 1.33 ===
--- CMF/DCWorkflow/DCWorkflow.py:1.32	Wed Jan 28 17:05:11 2004
+++ CMF/DCWorkflow/DCWorkflow.py	Wed Feb  4 15:35:20 2004
@@ -78,6 +78,8 @@
     roles = None  # The role names managed by this workflow.
     # If roles is None, listRoles() provides a default.
 
+    creation_guard = None  # The guard that can veto object creation.
+
     manager_bypass = 0  # Boolean: 'Manager' role bypasses guards
 
     manage_options = (
@@ -364,12 +366,21 @@
 
         return value
 
+    security.declarePrivate('allowCreate')
+    def allowCreate(self, container, type_name):
+        """Returns true if the user is allowed to create a workflow instance.
+
+        The object passed to the guard is the prospective container.
+        """
+        if self.creation_guard is not None:
+            return self.creation_guard.check(
+                getSecurityManager(), self, container)
+        return 1
+
     security.declarePrivate('notifyCreated')
     def notifyCreated(self, ob):
-        '''
-        Notifies this workflow after an object has been created
-        and put in its new place.
-        '''
+        """Notifies this workflow after an object has been created and added.
+        """
         try:
             self._changeStateOf(ob, None)
         except ( ObjectDeleted, ObjectMoved ):


=== CMF/DCWorkflow/WorkflowUIMixin.py 1.8 => 1.9 ===
--- CMF/DCWorkflow/WorkflowUIMixin.py:1.8	Wed Jan 28 17:05:11 2004
+++ CMF/DCWorkflow/WorkflowUIMixin.py	Wed Feb  4 15:35:20 2004
@@ -22,6 +22,7 @@
 from Products.CMFCore.CMFCorePermissions import ManagePortal
 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
 
+from Guard import Guard
 from utils import _dtmldir
 
 try:
@@ -43,11 +44,16 @@
     manage_groups = PageTemplateFile('workflow_groups.pt', _dtmldir)
 
     security.declareProtected(ManagePortal, 'setProperties')
-    def setProperties(self, title, manager_bypass=0, REQUEST=None):
+    def setProperties(self, title, manager_bypass=0, props=None, REQUEST=None):
         """Sets basic properties.
         """
         self.title = str(title)
         self.manager_bypass = manager_bypass and 1 or 0
+        g = Guard()
+        if g.changeFromProperties(props or REQUEST):
+            self.creation_guard = g
+        else:
+            self.creation_guard = None
         if REQUEST is not None:
             return self.manage_properties(
                 REQUEST, manage_tabs_message='Properties changed.')
@@ -184,5 +190,17 @@
             RESPONSE.redirect(
                 "%s/manage_groups?manage_tabs_message=Roles+changed."
                 % self.absolute_url())
+
+    security.declareProtected(ManagePortal, 'getGuard')
+    def getGuard(self):
+        """Returns the initiation guard.
+
+        If no init guard has been created, returns a temporary object.
+        """
+        if self.creation_guard is not None:
+            return self.creation_guard
+        else:
+            return Guard().__of__(self)  # Create a temporary guard.
+
 
 Globals.InitializeClass(WorkflowUIMixin)




More information about the CMF-checkins mailing list