source: trunk/LeMillWorkflow.py @ 1983

Revision 1919, 7.5 KB checked in by jukka, 12 years ago (diff)

Refactored groups to not use portal_groups. Things should be faster and users from weird sources shouldn't cause so much problems. Not much tested yet, but archetype update and quickinstaller reinstall works fine.

Line 
1# Copyright 2006 by the LeMill Team (see AUTHORS)
2#
3# This file is part of LeMill.
4#
5# LeMill is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# LeMill is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with LeMill; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
19from Products.CMFCore.WorkflowTool import addWorkflowFactory
20from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
21from Products.CMFCore import permissions
22
23
24view = permissions.View
25edit = permissions.ModifyPortalContent
26access = permissions.AccessContentsInformation
27delete = permissions.ReviewPortalContent
28
29def createGroup_workflow(id):
30    """ create workflow """
31    ob = DCWorkflowDefinition(id)
32    setupGroup_workflow(ob)
33    #setupScripts(ob)
34    return ob
35
36def createWikish_workflow(id):
37    """ create workflow """
38    ob = DCWorkflowDefinition(id)
39    setupWikish_workflow(ob)
40    #setupScripts(ob)
41    return ob
42
43def createPersonal_workflow(id):
44    """ create workflow """
45    ob = DCWorkflowDefinition(id)
46    setupPersonal_workflow(ob)
47    #setupScripts(ob)
48    return ob
49
50
51# This really is resource workflow, but if we change the id, other workflows that inherit from this are rebuilt in such way that they lose their wf state.
52
53def setupGroup_workflow(wf):
54    """ define workflow """
55    wf.setProperties(title='LeMill *Resource* Workflow')
56
57    for s in ['draft', 'public', 'deleted']:
58        wf.states.addState(s)
59    for t in ['publish', 'retract', 'delete', 'restore']:
60        wf.transitions.addTransition(t)
61    for v in ['review_history', 'comments', 'time', 'actor', 'action']:
62        wf.variables.addVariable(v)
63    for p in (view, edit, access):
64        wf.addManagedPermission(p)
65   
66    # initial state.
67    wf.states.setInitialState('draft')
68
69    # permissions
70
71    state = wf.states['draft']
72    state.setProperties(title='draft', transitions=('publish','delete'))
73    state.setPermission(view, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
74    state.setPermission(edit, 0, ('Manager', 'Owner', 'Member'))
75    state.setPermission(delete, 0, ('Manager', 'Reviewer', 'Owner'))
76    state.setPermission(access, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
77
78    state = wf.states['public']
79    state.setProperties(title='published', transitions=('retract','delete'))
80    state.setPermission(view, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
81    state.setPermission(edit, 0, ('Manager', 'Owner', 'Member'))
82    state.setPermission(delete, 0, ('Manager', 'Reviewer', 'Owner'))
83    state.setPermission(access, 0, ('Manager', 'Reviewer', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
84
85    state = wf.states['deleted']
86    state.setProperties(title='deleted', transitions=('restore','publish'))
87    state.setPermission(view, 0, ('Manager', 'Reviewer', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
88    state.setPermission(edit, 0, ('Manager', 'Owner', 'Member'))
89    state.setPermission(delete, 0, ('Manager', 'Reviewer', 'Owner'))
90    state.setPermission(access, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
91   
92    # transitions
93
94    trans = wf.transitions['publish']
95    trans.setProperties(title='Publish content',
96            new_state_id='public',
97            trigger_type=1,
98            actbox_name='publish',
99            actbox_category='workflow',
100            props={'guard_roles':'Manager;Owner;Reviewer'},
101            )
102    trans = wf.transitions['retract']
103    trans.setProperties(title='retract',
104            new_state_id='draft',
105            trigger_type=1,
106            actbox_name='retract',
107            actbox_category='workflow',
108            props={'guard_roles':'Manager;Reviewer;Owner'},
109            )
110    trans = wf.transitions['restore']
111    trans.setProperties(title='restore',
112            new_state_id='draft',
113            trigger_type=1,
114            actbox_name='restore',
115            actbox_category='workflow',
116            props={'guard_roles':'Manager;Owner;Reviewer'},
117            )
118    trans = wf.transitions['delete']
119    trans.setProperties(title='delete',
120            new_state_id='deleted',
121            trigger_type=1,
122            actbox_name='delete',
123            actbox_category='workflow',
124            props={'guard_roles':'Manager;Owner;Reviewer'},
125            )
126
127
128    # variables. are these good for something?
129    wf.variables.setStateVar('review_state')
130
131    vdef = wf.variables['action']
132
133    vdef = wf.variables['action']
134    vdef.setProperties(description='The last transition',
135            default_expr='transition/getId|nothing',
136            for_status=1, update_always=1)
137
138    vdef = wf.variables['actor']
139    vdef.setProperties(description='The ID of the user who performed '
140            'the last transition',
141            default_expr='user/getId',
142            for_status=1, update_always=1)
143
144    vdef = wf.variables['comments']
145    vdef.setProperties(description='Comments about the last transition',
146            default_expr="python:state_change.kwargs.get('comment', '')",
147            for_status=1, update_always=1)
148
149    vdef = wf.variables['review_history']
150    vdef.setProperties(description='Provides access to workflow history',
151            default_expr="state_change/getHistory",
152            props={'guard_permissions': 'Request review; Review portal content'})
153
154    vdef = wf.variables['time']
155    vdef.setProperties(description='Time of the last transition',
156            default_expr="state_change/getDateTime",
157            for_status=1, update_always=1)
158
159
160
161def setupPersonal_workflow(wf):
162    # Get defaults from here (can't inherit GroupBlog_workflow, would mess things up.):
163    setupGroup_workflow(wf)
164
165    wf.setProperties(title='LeMill Personal Workflow')
166
167    # Don't need draft state - just public and hidden
168    wf.states.deleteStates(('draft',))
169    wf.states.setInitialState('public')
170    wf.transitions.deleteTransitions(('retract','restore'))
171    state=wf.states['public']
172    state.setPermission(edit, 0, ('Manager', 'Owner'))
173
174def setupWikish_workflow(wf):
175    # Get defaults from here:
176    setupPersonal_workflow(wf)
177
178    wf.setProperties(title='LeMill Wiki-Like Workflow')
179
180    # Add edit access to all members
181    state=wf.states['public']
182    state.setPermission(edit, 0, ('Manager', 'Owner', 'Member'))
183
184addWorkflowFactory(createGroup_workflow,
185        id='group_workflow',
186        title='LeMill resource workflow')
187
188addWorkflowFactory(createWikish_workflow,
189        id='wikish_workflow',
190        title='LeMill wiki-like workflow')
191
192addWorkflowFactory(createPersonal_workflow,
193        id='personal_workflow',
194        title='LeMill personal workflow')
195
196def setupScripts(wf):
197    """ this is not used but I'll keep it here as an example of how to create workflow scripts """
198    from Products.PythonScripts import PythonScript
199    scripts = wf.scripts
200    pysc = PythonScript.PythonScript('script_updateCoverImage')
201    scripts._setObject('script_updateCoverImage', pysc)
202    upd = getattr(scripts, 'script_updateCoverImage')
203    upd.write("""
204##parameters=param
205
206ob = param.object
207if not ob.getHasCoverImage():
208    return
209coverImage = ob.getCoverImage()
210img = ob.embedIcon(coverImage)
211ob.setCoverImage(img)
212""")
213
Note: See TracBrowser for help on using the repository browser.