vendor/CMF/1.6.1/DCWorkflow

view WorkflowUIMixin.py @ 0:238bab7e7116

CMF 1.6.1 vendor import
author fguillaume
date Tue, 13 Jun 2006 14:57:59 +0000
parents
children
line source
1 ##############################################################################
2 #
3 # Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
4 #
5 # This software is subject to the provisions of the Zope Public License,
6 # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
10 # FOR A PARTICULAR PURPOSE.
11 #
12 ##############################################################################
13 """ Web-configurable workflow UI.
15 $Id: WorkflowUIMixin.py 36457 2004-08-12 15:07:44Z jens $
16 """
18 import os
20 from Globals import DTMLFile
21 from Globals import InitializeClass
22 from AccessControl import ClassSecurityInfo
23 from Acquisition import aq_get
25 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
27 from permissions import ManagePortal
28 from Guard import Guard
29 from utils import _dtmldir
31 try:
32 #
33 # XXX: 2004/04/28 This factoring *has* to go; if necessary,
34 # this module could have a hook function, which the dependent
35 # module could replace.
36 #
38 # If base_cms exists, include the roles it defines.
39 from Products.base_cms.permissions import getDefaultRolePermissionMap
40 except ImportError:
41 def getDefaultRolePermissionMap():
42 return {}
45 class WorkflowUIMixin:
46 '''
47 '''
49 security = ClassSecurityInfo()
51 security.declareProtected(ManagePortal, 'manage_properties')
52 manage_properties = DTMLFile('workflow_properties', _dtmldir)
53 manage_groups = PageTemplateFile('workflow_groups.pt', _dtmldir)
55 security.declareProtected(ManagePortal, 'setProperties')
56 def setProperties(self, title, manager_bypass=0, props=None, REQUEST=None):
57 """Sets basic properties.
58 """
59 self.title = str(title)
60 self.manager_bypass = manager_bypass and 1 or 0
61 g = Guard()
62 if g.changeFromProperties(props or REQUEST):
63 self.creation_guard = g
64 else:
65 self.creation_guard = None
66 if REQUEST is not None:
67 return self.manage_properties(
68 REQUEST, manage_tabs_message='Properties changed.')
70 _permissions_form = DTMLFile('workflow_permissions', _dtmldir)
72 security.declareProtected(ManagePortal, 'manage_permissions')
73 def manage_permissions(self, REQUEST, manage_tabs_message=None):
74 """Displays the form for choosing which permissions to manage.
75 """
76 return self._permissions_form(REQUEST,
77 management_view='Permissions',
78 manage_tabs_message=manage_tabs_message,
79 )
81 security.declareProtected(ManagePortal, 'addManagedPermission')
82 def addManagedPermission(self, p, REQUEST=None):
83 """Adds to the list of permissions to manage.
84 """
85 if p in self.permissions:
86 raise ValueError, 'Already a managed permission: ' + p
87 if REQUEST is not None and p not in self.getPossiblePermissions():
88 raise ValueError, 'Not a valid permission name:' + p
89 self.permissions = self.permissions + (p,)
90 if REQUEST is not None:
91 return self.manage_permissions(
92 REQUEST, manage_tabs_message='Permission added.')
94 security.declareProtected(ManagePortal, 'delManagedPermissions')
95 def delManagedPermissions(self, ps, REQUEST=None):
96 """Removes from the list of permissions to manage.
97 """
98 if ps:
99 l = list(self.permissions)
100 for p in ps:
101 l.remove(p)
102 self.permissions = tuple(l)
103 if REQUEST is not None:
104 return self.manage_permissions(
105 REQUEST, manage_tabs_message='Permission(s) removed.')
107 security.declareProtected(ManagePortal, 'getPossiblePermissions')
108 def getPossiblePermissions(self):
109 """Returns the list of all permissions that can be managed.
110 """
111 # possible_permissions is in AccessControl.Role.RoleManager.
112 return list(self.possible_permissions())
114 security.declareProtected(ManagePortal, 'getGroups')
115 def getGroups(self):
116 """Returns the names of groups managed by this workflow.
117 """
118 return tuple(self.groups)
120 security.declareProtected(ManagePortal, 'getAvailableGroups')
121 def getAvailableGroups(self):
122 """Returns a list of available group names.
123 """
124 gf = aq_get( self, '__allow_groups__', None, 1 )
125 if gf is None:
126 return ()
127 try:
128 groups = gf.searchGroups()
129 except AttributeError:
130 return ()
131 else:
132 return [g['id'] for g in groups]
134 security.declareProtected(ManagePortal, 'addGroup')
135 def addGroup(self, group, RESPONSE=None):
136 """Adds a group by name.
137 """
138 if group not in self.getAvailableGroups():
139 raise ValueError(group)
140 self.groups = self.groups + (group,)
141 if RESPONSE is not None:
142 RESPONSE.redirect(
143 "%s/manage_groups?manage_tabs_message=Added+group."
144 % self.absolute_url())
146 security.declareProtected(ManagePortal, 'delGroups')
147 def delGroups(self, groups, RESPONSE=None):
148 """Removes groups by name.
149 """
150 self.groups = tuple([g for g in self.groups if g not in groups])
151 if RESPONSE is not None:
152 RESPONSE.redirect(
153 "%s/manage_groups?manage_tabs_message=Groups+removed."
154 % self.absolute_url())
156 security.declareProtected(ManagePortal, 'getAvailableRoles')
157 def getAvailableRoles(self):
158 """Returns the acquired roles mixed with base_cms roles.
159 """
160 roles = list(self.valid_roles())
161 for role in getDefaultRolePermissionMap().keys():
162 if role not in roles:
163 roles.append(role)
164 roles.sort()
165 return roles
167 security.declareProtected(ManagePortal, 'getRoles')
168 def getRoles(self):
169 """Returns the list of roles managed by this workflow.
170 """
171 roles = self.roles
172 if roles is not None:
173 return roles
174 roles = getDefaultRolePermissionMap().keys()
175 if roles:
176 # Map the base_cms roles by default.
177 roles.sort()
178 return roles
179 return self.valid_roles()
181 security.declareProtected(ManagePortal, 'setRoles')
182 def setRoles(self, roles, RESPONSE=None):
183 """Changes the list of roles mapped to groups by this workflow.
184 """
185 avail = self.getAvailableRoles()
186 for role in roles:
187 if role not in avail:
188 raise ValueError(role)
189 self.roles = tuple(roles)
190 if RESPONSE is not None:
191 RESPONSE.redirect(
192 "%s/manage_groups?manage_tabs_message=Roles+changed."
193 % self.absolute_url())
195 security.declareProtected(ManagePortal, 'getGuard')
196 def getGuard(self):
197 """Returns the initiation guard.
199 If no init guard has been created, returns a temporary object.
200 """
201 if self.creation_guard is not None:
202 return self.creation_guard
203 else:
204 return Guard().__of__(self) # Create a temporary guard.
206 security.declarePublic('guardExprDocs')
207 def guardExprDocs(self):
208 """Returns documentation on guard expressions.
209 """
210 here = os.path.dirname(__file__)
211 fn = os.path.join(here, 'doc', 'expressions.stx')
212 f = open(fn, 'rt')
213 try:
214 text = f.read()
215 finally:
216 f.close()
217 from DocumentTemplate.DT_Var import structured_text
218 return structured_text(text)
220 InitializeClass(WorkflowUIMixin)