1 | """ WAeUP Workflfow |
---|
2 | """ |
---|
3 | |
---|
4 | __author__ = "Joachim Schmitz <js@aixtraware.de>" |
---|
5 | |
---|
6 | import os, sys |
---|
7 | from zLOG import LOG, INFO, DEBUG |
---|
8 | |
---|
9 | from Products.CMFCore.permissions import View, ModifyPortalContent |
---|
10 | #from Products.WAeUP.permissions import |
---|
11 | |
---|
12 | from Products.CPSWorkflow.transitions import \ |
---|
13 | TRANSITION_INITIAL_CREATE, \ |
---|
14 | TRANSITION_ALLOWSUB_CHECKOUT, \ |
---|
15 | TRANSITION_ALLOWSUB_CREATE, \ |
---|
16 | TRANSITION_ALLOWSUB_DELETE, \ |
---|
17 | TRANSITION_ALLOWSUB_MOVE, \ |
---|
18 | TRANSITION_ALLOWSUB_COPY |
---|
19 | |
---|
20 | from Products.DCWorkflow.Transitions import \ |
---|
21 | TRIGGER_USER_ACTION |
---|
22 | |
---|
23 | def waeupWorkflowsInstall(self): |
---|
24 | """Install the workflow for the WAeUP Types |
---|
25 | """ |
---|
26 | |
---|
27 | portal = self.portal_url.getPortalObject() |
---|
28 | wftool = portal.portal_workflow |
---|
29 | |
---|
30 | wfids = wftool.objectIds() |
---|
31 | wfid = 'waeup_section_wf' |
---|
32 | |
---|
33 | if wfid in wfids: |
---|
34 | wftool.manage_delObjects([wfid]) |
---|
35 | |
---|
36 | wftool.manage_addWorkflow(id=wfid, |
---|
37 | workflow_type='cps_workflow (Web-configurable workflow for CPS)') |
---|
38 | |
---|
39 | wf = wftool[wfid] |
---|
40 | |
---|
41 | for p in (View, |
---|
42 | ModifyPortalContent, |
---|
43 | |
---|
44 | ): |
---|
45 | wf.addManagedPermission(p) |
---|
46 | |
---|
47 | ########################################################################### |
---|
48 | ########################################################################### |
---|
49 | |
---|
50 | # STATES |
---|
51 | |
---|
52 | ########################################################################### |
---|
53 | ########################################################################### |
---|
54 | |
---|
55 | for s in ('work', |
---|
56 | ): |
---|
57 | wf.states.addState(s) |
---|
58 | |
---|
59 | ########################################################################## |
---|
60 | # WORK |
---|
61 | ########################################################################## |
---|
62 | |
---|
63 | s = wf.states.get('work') |
---|
64 | |
---|
65 | s.setPermission(View, 1, ('Students',)) |
---|
66 | s.setPermission(ModifyPortalContent, 1, ('StudentManager','UniversityManager',)) |
---|
67 | |
---|
68 | s.setInitialState('work') |
---|
69 | s.setProperties(title='Work', |
---|
70 | description='', |
---|
71 | transitions=('create_content', |
---|
72 | 'cut_copy_paste', |
---|
73 | 'close',),) |
---|
74 | |
---|
75 | ########################################################################## |
---|
76 | # CLOSED |
---|
77 | ########################################################################## |
---|
78 | |
---|
79 | ## s = wf.states.get('closed') |
---|
80 | ## |
---|
81 | ## s.setPermission(View, 1, ('ChatPoster',)) |
---|
82 | ## s.setPermission(ModifyPortalContent, 1, ('ChatModerator',)) |
---|
83 | ## s.setPermission(chatReply, 1, ('ChatModerator',)) |
---|
84 | ## s.setPermission(chatPost, 1, ('ChatModerator',)) |
---|
85 | ## s.setPermission(chatModerate, 1, ('ChatModerator',)) |
---|
86 | |
---|
87 | ## s.setProperties(title='Closed', |
---|
88 | ## description='', |
---|
89 | ## transitions=('unclose', |
---|
90 | ## 'cut_copy_paste',),) |
---|
91 | ## |
---|
92 | ########################################################################### |
---|
93 | ########################################################################### |
---|
94 | |
---|
95 | # TRANSITIONS |
---|
96 | |
---|
97 | ########################################################################### |
---|
98 | ########################################################################### |
---|
99 | |
---|
100 | for t in ('create', |
---|
101 | 'create_content', |
---|
102 | 'cut_copy_paste', |
---|
103 | ): |
---|
104 | wf.transitions.addTransition(t) |
---|
105 | |
---|
106 | |
---|
107 | ########################################################################### |
---|
108 | # CREATE |
---|
109 | ########################################################################### |
---|
110 | |
---|
111 | t = wf.transitions.get('create') |
---|
112 | t.setProperties(title='Initial creation', |
---|
113 | description='Intial transition like', |
---|
114 | new_state_id='work', |
---|
115 | transition_behavior=(TRANSITION_INITIAL_CREATE, ), |
---|
116 | clone_allowed_transitions=None, |
---|
117 | actbox_name='', actbox_category='workflow', actbox_url='', |
---|
118 | props={'guard_permissions':'', |
---|
119 | 'guard_roles':'Manager; StudentManager ; UniversityManager', |
---|
120 | 'guard_expr':''},) |
---|
121 | |
---|
122 | ########################################################################### |
---|
123 | # CREATE CONTENT |
---|
124 | ########################################################################### |
---|
125 | |
---|
126 | t = wf.transitions.get('create_content') |
---|
127 | t.setProperties(title='Create content', |
---|
128 | description='Allow sub Object Create', |
---|
129 | new_state_id='work', |
---|
130 | transition_behavior=(TRANSITION_ALLOWSUB_CREATE, |
---|
131 | TRANSITION_ALLOWSUB_CHECKOUT,), |
---|
132 | trigger_type=TRIGGER_USER_ACTION, |
---|
133 | actbox_name='New', |
---|
134 | actbox_category='', |
---|
135 | actbox_url='', |
---|
136 | props={'guard_permissions':'', |
---|
137 | 'guard_roles':'Manager; StudentManager ; UniversityManager', |
---|
138 | 'guard_expr':''},) |
---|
139 | |
---|
140 | ########################################################################## |
---|
141 | # CUT/COPY/PASTE |
---|
142 | ########################################################################## |
---|
143 | |
---|
144 | t = wf.transitions.get('cut_copy_paste') |
---|
145 | t.setProperties(title='Cut/Copy/Paste', |
---|
146 | new_state_id='work', |
---|
147 | transition_behavior=(TRANSITION_ALLOWSUB_DELETE, |
---|
148 | TRANSITION_ALLOWSUB_MOVE, |
---|
149 | TRANSITION_ALLOWSUB_COPY), |
---|
150 | clone_allowed_transitions=None, |
---|
151 | trigger_type=TRIGGER_USER_ACTION, |
---|
152 | actbox_name='New', |
---|
153 | actbox_category='', |
---|
154 | actbox_url='', |
---|
155 | props={'guard_permissions':'', |
---|
156 | 'guard_roles':'Manager; StudentManager ; UniversityManager', |
---|
157 | 'guard_expr':''},) |
---|
158 | |
---|
159 | ########################################################################## |
---|
160 | # CLOSE |
---|
161 | ########################################################################## |
---|
162 | |
---|
163 | ## t = wf.transitions.get('close') |
---|
164 | ## t.setProperties(title='close', |
---|
165 | ## new_state_id='closed', |
---|
166 | ## transition_behavior=(), |
---|
167 | ## clone_allowed_transitions=None, |
---|
168 | ## trigger_type=TRIGGER_USER_ACTION, |
---|
169 | ## actbox_name='label_chat_close', |
---|
170 | ## actbox_category='workflow', |
---|
171 | ## actbox_url='%(content_url)s/cps_chat_close', |
---|
172 | ## props={'guard_permissions':'', |
---|
173 | ## 'guard_roles':'Manager; SectionManager; SectionReviewer', |
---|
174 | ## 'guard_expr':''},) |
---|
175 | ## |
---|
176 | ## ########################################################################## |
---|
177 | ## # UNCLOSE |
---|
178 | ## ########################################################################## |
---|
179 | ## |
---|
180 | ## t = wf.transitions.get('unclose') |
---|
181 | ## t.setProperties(title='unclose', |
---|
182 | ## new_state_id='work', |
---|
183 | ## transition_behavior=(), |
---|
184 | ## clone_allowed_transitions=None, |
---|
185 | ## trigger_type=TRIGGER_USER_ACTION, |
---|
186 | ## actbox_name='label_chat_unclose', |
---|
187 | ## actbox_category='workflow', |
---|
188 | ## actbox_url='%(content_url)s/cps_chat_unclose', |
---|
189 | ## props={'guard_permissions':'', |
---|
190 | ## 'guard_roles':'Manager; SectionManager; SectionReviewer', |
---|
191 | ## 'guard_expr':''},) |
---|
192 | |
---|
193 | ################################################################ |
---|
194 | # VARIABLES |
---|
195 | ################################################################ |
---|
196 | |
---|
197 | for v in ('action', |
---|
198 | 'actor', |
---|
199 | 'comments', |
---|
200 | 'review_history', |
---|
201 | 'time', |
---|
202 | 'dest_container', |
---|
203 | ): |
---|
204 | wf.variables.addVariable(v) |
---|
205 | |
---|
206 | |
---|
207 | wf.variables.setStateVar('review_state') |
---|
208 | |
---|
209 | vdef = wf.variables['action'] |
---|
210 | vdef.setProperties(description='The last transition', |
---|
211 | default_expr='transition/getId|nothing', |
---|
212 | for_status=1, update_always=1) |
---|
213 | |
---|
214 | vdef = wf.variables['actor'] |
---|
215 | vdef.setProperties(description='The ID of the user who performed ' |
---|
216 | 'the last transition', |
---|
217 | default_expr='user/getId', |
---|
218 | for_status=1, update_always=1) |
---|
219 | |
---|
220 | vdef = wf.variables['comments'] |
---|
221 | vdef.setProperties(description='Comments about the last transition', |
---|
222 | default_expr="python:state_change.kwargs.get('comment', '')", |
---|
223 | for_status=1, update_always=1) |
---|
224 | |
---|
225 | vdef = wf.variables['review_history'] |
---|
226 | vdef.setProperties(description='Provides access to workflow history', |
---|
227 | default_expr="state_change/getHistory", |
---|
228 | props={'guard_permissions':'', |
---|
229 | 'guard_roles':'Manager; WorkspaceManager; WorkspaceMember; WorkspaceReader; Member', |
---|
230 | 'guard_expr':''}) |
---|
231 | |
---|
232 | vdef = wf.variables['time'] |
---|
233 | vdef.setProperties(description='Time of the last transition', |
---|
234 | default_expr="state_change/getDateTime", |
---|
235 | for_status=1, update_always=1) |
---|
236 | |
---|
237 | vdef = wf.variables['dest_container'] |
---|
238 | vdef.setProperties(description='Destination container for the last paste/publish', |
---|
239 | default_expr="python:state_change.kwargs.get('dest_container', '')", |
---|
240 | for_status=1, update_always=1) |
---|
241 | |
---|
242 | |
---|
243 | ###################################################################################### |
---|
244 | ###################################################################################### |
---|
245 | wfid = 'waeup_workspace_wf' |
---|
246 | |
---|
247 | if wfid in wfids: |
---|
248 | wftool.manage_delObjects([wfid]) |
---|
249 | |
---|
250 | wftool.manage_addWorkflow(id=wfid, |
---|
251 | workflow_type='cps_workflow (Web-configurable workflow for CPS)') |
---|
252 | |
---|
253 | wf = wftool[wfid] |
---|
254 | |
---|
255 | for p in (View, |
---|
256 | ModifyPortalContent, |
---|
257 | ): |
---|
258 | wf.addManagedPermission(p) |
---|
259 | |
---|
260 | ########################################################################### |
---|
261 | ########################################################################### |
---|
262 | |
---|
263 | # STATES |
---|
264 | |
---|
265 | ########################################################################### |
---|
266 | ########################################################################### |
---|
267 | |
---|
268 | for s in ('work', |
---|
269 | 'closed'): |
---|
270 | wf.states.addState(s) |
---|
271 | |
---|
272 | ########################################################################## |
---|
273 | # WORK |
---|
274 | ########################################################################## |
---|
275 | |
---|
276 | s = wf.states.get('work') |
---|
277 | |
---|
278 | ## s.setPermission(View, 1, ('ChatPoster',)) |
---|
279 | ## s.setPermission(ModifyPortalContent, 1, ('ChatModerator',)) |
---|
280 | ## s.setPermission(chatReply, 1, ('ChatModerator', 'ChatGuest',)) |
---|
281 | ## s.setPermission(chatPost, 1, ('ChatModerator', 'ChatPoster', 'ChatGuest',)) |
---|
282 | ## s.setPermission(chatModerate, 1, ('ChatModerator',)) |
---|
283 | |
---|
284 | s.setInitialState('work') |
---|
285 | s.setProperties(title='Work', |
---|
286 | description='', |
---|
287 | transitions=('create_content', |
---|
288 | 'cut_copy_paste', |
---|
289 | 'close',),) |
---|
290 | |
---|
291 | |
---|
292 | ########################################################################## |
---|
293 | # CLOSED |
---|
294 | ########################################################################## |
---|
295 | |
---|
296 | s = wf.states.get('closed') |
---|
297 | |
---|
298 | ## s.setPermission(View, 1, ('ChatPoster',)) |
---|
299 | ## s.setPermission(ModifyPortalContent, 1, ('ChatModerator',)) |
---|
300 | ## s.setPermission(chatReply, 1, ('ChatModerator',)) |
---|
301 | ## s.setPermission(chatPost, 1, ('ChatModerator',)) |
---|
302 | ## s.setPermission(chatModerate, 1, ('ChatModerator',)) |
---|
303 | |
---|
304 | s.setProperties(title='Closed', |
---|
305 | description='', |
---|
306 | transitions=('unclose', |
---|
307 | 'cut_copy_paste',),) |
---|
308 | |
---|
309 | ########################################################################### |
---|
310 | ########################################################################### |
---|
311 | |
---|
312 | # TRANSITIONS |
---|
313 | |
---|
314 | ########################################################################### |
---|
315 | ########################################################################### |
---|
316 | |
---|
317 | for t in ('create', |
---|
318 | 'create_content', |
---|
319 | 'cut_copy_paste', |
---|
320 | 'close', |
---|
321 | 'unclose',): |
---|
322 | wf.transitions.addTransition(t) |
---|
323 | |
---|
324 | |
---|
325 | ########################################################################### |
---|
326 | # CREATE |
---|
327 | ########################################################################### |
---|
328 | |
---|
329 | t = wf.transitions.get('create') |
---|
330 | t.setProperties(title='Initial creation', |
---|
331 | description='Intial transition like', |
---|
332 | new_state_id='work', |
---|
333 | transition_behavior=(TRANSITION_INITIAL_CREATE, ), |
---|
334 | clone_allowed_transitions=None, |
---|
335 | actbox_name='', actbox_category='workflow', actbox_url='', |
---|
336 | props={'guard_permissions':'', |
---|
337 | 'guard_roles':'Manager; WorkspaceManager', |
---|
338 | 'guard_expr':''},) |
---|
339 | |
---|
340 | ########################################################################### |
---|
341 | # CREATE CONTENT |
---|
342 | ########################################################################### |
---|
343 | |
---|
344 | t = wf.transitions.get('create_content') |
---|
345 | t.setProperties(title='Create content', |
---|
346 | description='Allow sub Object Create', |
---|
347 | new_state_id='work', |
---|
348 | transition_behavior=(TRANSITION_ALLOWSUB_CREATE, |
---|
349 | TRANSITION_ALLOWSUB_CHECKOUT,), |
---|
350 | trigger_type=TRIGGER_USER_ACTION, |
---|
351 | actbox_name='New', |
---|
352 | actbox_category='', |
---|
353 | actbox_url='', |
---|
354 | props={'guard_permissions':'', |
---|
355 | 'guard_roles':'Manager; WorkspaceManager; WorkspaceMember; WorkspaceReader', |
---|
356 | 'guard_expr':''},) |
---|
357 | |
---|
358 | ########################################################################## |
---|
359 | # CUT/COPY/PASTE |
---|
360 | ########################################################################## |
---|
361 | |
---|
362 | t = wf.transitions.get('cut_copy_paste') |
---|
363 | t.setProperties(title='Cut/Copy/Paste', |
---|
364 | new_state_id='work', |
---|
365 | transition_behavior=(TRANSITION_ALLOWSUB_DELETE, |
---|
366 | TRANSITION_ALLOWSUB_MOVE, |
---|
367 | TRANSITION_ALLOWSUB_COPY), |
---|
368 | clone_allowed_transitions=None, |
---|
369 | trigger_type=TRIGGER_USER_ACTION, |
---|
370 | actbox_name='New', |
---|
371 | actbox_category='', |
---|
372 | actbox_url='', |
---|
373 | props={'guard_permissions':'', |
---|
374 | 'guard_roles':'Manager; WorkspaceManager; WorkspaceMember', |
---|
375 | 'guard_expr':''},) |
---|
376 | |
---|
377 | ## ########################################################################## |
---|
378 | ## # CLOSE |
---|
379 | ## ########################################################################## |
---|
380 | ## |
---|
381 | ## t = wf.transitions.get('close') |
---|
382 | ## t.setProperties(title='close', |
---|
383 | ## new_state_id='closed', |
---|
384 | ## transition_behavior=(), |
---|
385 | ## clone_allowed_transitions=None, |
---|
386 | ## trigger_type=TRIGGER_USER_ACTION, |
---|
387 | ## actbox_name='label_chat_close', |
---|
388 | ## actbox_category='workflow', |
---|
389 | ## actbox_url='%(content_url)s/cps_chat_close', |
---|
390 | ## props={'guard_permissions':'', |
---|
391 | ## 'guard_roles':'Manager; WorkspaceManager', |
---|
392 | ## 'guard_expr':''},) |
---|
393 | ## |
---|
394 | ## ########################################################################## |
---|
395 | ## # UNCLOSE |
---|
396 | ## ########################################################################## |
---|
397 | ## |
---|
398 | ## t = wf.transitions.get('unclose') |
---|
399 | ## t.setProperties(title='unclose', |
---|
400 | ## new_state_id='work', |
---|
401 | ## transition_behavior=(), |
---|
402 | ## clone_allowed_transitions=None, |
---|
403 | ## trigger_type=TRIGGER_USER_ACTION, |
---|
404 | ## actbox_name='label_chat_unclose', |
---|
405 | ## actbox_category='workflow', |
---|
406 | ## actbox_url='%(content_url)s/cps_chat_unclose', |
---|
407 | ## props={'guard_permissions':'', |
---|
408 | ## 'guard_roles':'Manager; WorkspaceManager; ChatModerator', |
---|
409 | ## 'guard_expr':''},) |
---|
410 | |
---|
411 | ################################################################ |
---|
412 | # VARIABLES |
---|
413 | ################################################################ |
---|
414 | |
---|
415 | for v in ('action', |
---|
416 | 'actor', |
---|
417 | 'comments', |
---|
418 | 'review_history', |
---|
419 | 'time', |
---|
420 | 'dest_container', |
---|
421 | ): |
---|
422 | wf.variables.addVariable(v) |
---|
423 | |
---|
424 | |
---|
425 | wf.variables.setStateVar('review_state') |
---|
426 | |
---|
427 | vdef = wf.variables['action'] |
---|
428 | vdef.setProperties(description='The last transition', |
---|
429 | default_expr='transition/getId|nothing', |
---|
430 | for_status=1, update_always=1) |
---|
431 | |
---|
432 | vdef = wf.variables['actor'] |
---|
433 | vdef.setProperties(description='The ID of the user who performed ' |
---|
434 | 'the last transition', |
---|
435 | default_expr='user/getId', |
---|
436 | for_status=1, update_always=1) |
---|
437 | |
---|
438 | vdef = wf.variables['comments'] |
---|
439 | vdef.setProperties(description='Comments about the last transition', |
---|
440 | default_expr="python:state_change.kwargs.get('comment', '')", |
---|
441 | for_status=1, update_always=1) |
---|
442 | |
---|
443 | vdef = wf.variables['review_history'] |
---|
444 | vdef.setProperties(description='Provides access to workflow history', |
---|
445 | default_expr="state_change/getHistory", |
---|
446 | props={'guard_permissions':'', |
---|
447 | 'guard_roles':'Manager; WorkspaceManager; WorkspaceMember; WorkspaceReader; Member', |
---|
448 | 'guard_expr':''}) |
---|
449 | |
---|
450 | vdef = wf.variables['time'] |
---|
451 | vdef.setProperties(description='Time of the last transition', |
---|
452 | default_expr="state_change/getDateTime", |
---|
453 | for_status=1, update_always=1) |
---|
454 | |
---|
455 | vdef = wf.variables['dest_container'] |
---|
456 | vdef.setProperties(description='Destination container for the last paste/publish', |
---|
457 | default_expr="python:state_change.kwargs.get('dest_container', '')", |
---|
458 | for_status=1, update_always=1) |
---|