source: trunk/LeMillWorkflow.py @ 330

Revision 330, 5.9 KB checked in by tarmo, 13 years ago (diff)

Added new workflows for different resource types.
Also improved migration scripts so that both
initial history versions and workflows are updated
properly. Closes #378, spent 1h.

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
23view = permissions.View
24edit = permissions.ModifyPortalContent
25access = permissions.AccessContentsInformation
26
27def createGroup_workflow(id):
28    """ create workflow """
29    ob = DCWorkflowDefinition(id)
30    setupGroup_workflow(ob)
31    return ob
32
33def createWikish_workflow(id):
34    """ create workflow """
35    ob = DCWorkflowDefinition(id)
36    setupWikish_workflow(ob)
37    return ob
38
39def createPersonal_workflow(id):
40    """ create workflow """
41    ob = DCWorkflowDefinition(id)
42    setupPersonal_workflow(ob)
43    return ob
44
45def setupGroup_workflow(wf):
46    """ define workflow """
47    wf.setProperties(title='LeMill Group Workflow')
48
49    for s in ['draft', 'public', 'hidden']:
50        wf.states.addState(s)
51    for t in ['publish', 'retract', 'hide']:
52        wf.transitions.addTransition(t)
53    for v in ['review_history', 'comments', 'time', 'actor', 'action']:
54        wf.variables.addVariable(v)
55    for p in (view, edit, access):
56        wf.addManagedPermission(p)
57   
58    # initial state.
59    wf.states.setInitialState('draft')
60
61    # permissions
62
63    state = wf.states['draft']
64    state.setProperties(title='draft', transitions=('publish','hide'))
65    state.setPermission(view, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
66    state.setPermission(edit, 0, ('Manager', 'Owner'))
67    state.setPermission(access, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
68
69    state = wf.states['public']
70    state.setProperties(title='published', transitions=('retract','hide'))
71    state.setPermission(view, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
72    state.setPermission(edit, 0, ('Manager', 'Owner'))
73    state.setPermission(access, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
74
75    state = wf.states['hidden']
76    state.setProperties(title='hidden', transitions=())
77    state.setPermission(view, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
78    state.setPermission(edit, 0, ('Manager', 'Owner'))
79    state.setPermission(access, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous'))
80   
81    # transitions
82
83    trans = wf.transitions['publish']
84    trans.setProperties(title='Publish content',
85            new_state_id='public',
86            trigger_type=1,
87            actbox_name='publish',
88            actbox_category='workflow',
89            props={'guard_roles':'Manager;Owner'},
90            )
91    trans = wf.transitions['retract']
92    trans.setProperties(title='retract',
93            new_state_id='draft',
94            trigger_type=1,
95            actbox_name='retract',
96            actbox_category='workflow',
97            props={'guard_roles':'Manager'},
98            )
99    trans = wf.transitions['hide']
100    trans.setProperties(title='hide',
101            new_state_id='hidden',
102            trigger_type=1,
103            actbox_name='hide',
104            actbox_category='workflow',
105            props={'guard_roles':'Manager;Owner'},
106            )
107
108
109    # variables. are these good for something?
110    wf.variables.setStateVar('review_state')
111
112    vdef = wf.variables['action']
113
114    vdef = wf.variables['action']
115    vdef.setProperties(description='The last transition',
116            default_expr='transition/getId|nothing',
117            for_status=1, update_always=1)
118
119    vdef = wf.variables['actor']
120    vdef.setProperties(description='The ID of the user who performed '
121            'the last transition',
122            default_expr='user/getId',
123            for_status=1, update_always=1)
124
125    vdef = wf.variables['comments']
126    vdef.setProperties(description='Comments about the last transition',
127            default_expr="python:state_change.kwargs.get('comment', '')",
128            for_status=1, update_always=1)
129
130    vdef = wf.variables['review_history']
131    vdef.setProperties(description='Provides access to workflow history',
132            default_expr="state_change/getHistory",
133            props={'guard_permissions': 'Request review; Review portal content'})
134
135    vdef = wf.variables['time']
136    vdef.setProperties(description='Time of the last transition',
137            default_expr="state_change/getDateTime",
138            for_status=1, update_always=1)
139
140def setupPersonal_workflow(wf):
141    # Get defaults from here:
142    setupGroup_workflow(wf)
143
144    wf.setProperties(title='LeMill Personal Workflow')
145
146    # Don't need draft state - just public and hidden
147    wf.states.deleteStates(('draft',))
148    wf.states.setInitialState('public')
149    wf.transitions.deleteTransitions(('publish','retract'))
150
151def setupWikish_workflow(wf):
152    # Get defaults from here:
153    setupPersonal_workflow(wf)
154
155    wf.setProperties(title='LeMill Wiki-Like Workflow')
156
157    # Add edit access to all members
158    state=wf.states['public']
159    state.setPermission(edit, 0, ('Manager', 'Owner', 'Member'))
160
161addWorkflowFactory(createGroup_workflow,
162        id='group_workflow',
163        title='LeMill group workflow')
164
165addWorkflowFactory(createWikish_workflow,
166        id='wikish_workflow',
167        title='LeMill wiki-like workflow')
168
169addWorkflowFactory(createPersonal_workflow,
170        id='personal_workflow',
171        title='LeMill personal workflow')
172
Note: See TracBrowser for help on using the repository browser.