source: trunk/LeMillWorkflow.py @ 1785

Revision 1785, 8.3 KB checked in by jukka, 13 years ago (diff)

Fixed #1376. Seemed simple, but was complicated. Group_workflow is changed to allow editing by members in general, but actual edit pages have checks to check if user belongs to group if material does. New workflow groupblog_workflow especially for groupblogs.

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 createGroupBlog_workflow(id):
37    """ create workflow """
38    ob = DCWorkflowDefinition(id)
39    setupGroupBlog_workflow(ob)
40    #setupScripts(ob)
41    return ob
42
43def createWikish_workflow(id):
44    """ create workflow """
45    ob = DCWorkflowDefinition(id)
46    setupWikish_workflow(ob)
47    #setupScripts(ob)
48    return ob
49
50def createPersonal_workflow(id):
51    """ create workflow """
52    ob = DCWorkflowDefinition(id)
53    setupPersonal_workflow(ob)
54    #setupScripts(ob)
55    return ob
56
57
58# This really is resource workflow, but if we change the id, other workflows that inherit from this are rebuilt in such way the lose their wf state.
59
60def setupGroup_workflow(wf):
61    """ define workflow """
62    wf.setProperties(title='LeMill *Resource* Workflow')
63
64    for s in ['draft', 'public', 'deleted']:
65        wf.states.addState(s)
66    for t in ['publish', 'retract', 'delete', 'restore']:
67        wf.transitions.addTransition(t)
68    for v in ['review_history', 'comments', 'time', 'actor', 'action']:
69        wf.variables.addVariable(v)
70    for p in (view, edit, access):
71        wf.addManagedPermission(p)
72   
73    # initial state.
74    wf.states.setInitialState('draft')
75
76    # permissions
77
78    state = wf.states['draft']
79    state.setProperties(title='draft', transitions=('publish','delete'))
80    state.setPermission(view, 0, ('Manager', 'Owner', 'CoAuthor', 'Member', 'Authenticated', 'Anonymous'))
81    state.setPermission(edit, 0, ('Manager', 'Owner', 'CoAuthor', 'Member'))
82    state.setPermission(delete, 0, ('Manager', 'Reviewer', 'Owner'))
83    state.setPermission(access, 0, ('Manager', 'Owner', 'CoAuthor', 'Member', 'Authenticated', 'Anonymous'))
84
85    state = wf.states['public']
86    state.setProperties(title='published', transitions=('retract','delete'))
87    state.setPermission(view, 0, ('Manager', 'Owner', 'CoAuthor', 'Member', 'Authenticated', 'Anonymous'))
88    state.setPermission(edit, 0, ('Manager', 'Owner', 'CoAuthor', 'Member'))
89    state.setPermission(delete, 0, ('Manager', 'Reviewer', 'Owner'))
90    state.setPermission(access, 0, ('Manager', 'Reviewer', 'Owner', 'CoAuthor', 'Member', 'Authenticated', 'Anonymous'))
91
92    state = wf.states['deleted']
93    state.setProperties(title='deleted', transitions=('restore','publish'))
94    state.setPermission(view, 0, ('Manager', 'Reviewer', 'Owner', 'CoAuthor', 'Member', 'Authenticated', 'Anonymous'))
95    state.setPermission(edit, 0, ('Manager', 'Owner', 'CoAuthor', 'Member'))
96    state.setPermission(delete, 0, ('Manager', 'Reviewer', 'Owner'))
97    state.setPermission(access, 0, ('Manager', 'Owner', 'CoAuthor', 'Member', 'Authenticated', 'Anonymous'))
98   
99    # transitions
100
101    trans = wf.transitions['publish']
102    trans.setProperties(title='Publish content',
103            new_state_id='public',
104            trigger_type=1,
105            actbox_name='publish',
106            actbox_category='workflow',
107            props={'guard_roles':'Manager;Owner;Reviewer'},
108            )
109    trans = wf.transitions['retract']
110    trans.setProperties(title='retract',
111            new_state_id='draft',
112            trigger_type=1,
113            actbox_name='retract',
114            actbox_category='workflow',
115            props={'guard_roles':'Manager;Reviewer;Owner'},
116            )
117    trans = wf.transitions['restore']
118    trans.setProperties(title='restore',
119            new_state_id='draft',
120            trigger_type=1,
121            actbox_name='restore',
122            actbox_category='workflow',
123            props={'guard_roles':'Manager;Owner;Reviewer'},
124            )
125    trans = wf.transitions['delete']
126    trans.setProperties(title='delete',
127            new_state_id='deleted',
128            trigger_type=1,
129            actbox_name='delete',
130            actbox_category='workflow',
131            props={'guard_roles':'Manager;Owner;Reviewer'},
132            )
133
134
135    # variables. are these good for something?
136    wf.variables.setStateVar('review_state')
137
138    vdef = wf.variables['action']
139
140    vdef = wf.variables['action']
141    vdef.setProperties(description='The last transition',
142            default_expr='transition/getId|nothing',
143            for_status=1, update_always=1)
144
145    vdef = wf.variables['actor']
146    vdef.setProperties(description='The ID of the user who performed '
147            'the last transition',
148            default_expr='user/getId',
149            for_status=1, update_always=1)
150
151    vdef = wf.variables['comments']
152    vdef.setProperties(description='Comments about the last transition',
153            default_expr="python:state_change.kwargs.get('comment', '')",
154            for_status=1, update_always=1)
155
156    vdef = wf.variables['review_history']
157    vdef.setProperties(description='Provides access to workflow history',
158            default_expr="state_change/getHistory",
159            props={'guard_permissions': 'Request review; Review portal content'})
160
161    vdef = wf.variables['time']
162    vdef.setProperties(description='Time of the last transition',
163            default_expr="state_change/getDateTime",
164            for_status=1, update_always=1)
165
166
167def setupGroupBlog_workflow(wf):
168    # Get defaults from here:
169    setupGroup_workflow(wf)
170
171    wf.setProperties(title='LeMill Group Workflow')
172
173    # Don't need draft state - just public and hidden
174    wf.states.deleteStates(('draft',))
175    wf.states.setInitialState('public')
176    wf.transitions.deleteTransitions(('retract','restore'))
177    state=wf.states['public']
178    state.setPermission(edit, 0, ('Manager', 'Owner', 'CoAuthor'))
179
180
181def setupPersonal_workflow(wf):
182    # Get defaults from here (can't inherit GroupBlog_workflow, would mess things up.):
183    setupGroup_workflow(wf)
184
185    wf.setProperties(title='LeMill Personal Workflow')
186
187    # Don't need draft state - just public and hidden
188    wf.states.deleteStates(('draft',))
189    wf.states.setInitialState('public')
190    wf.transitions.deleteTransitions(('retract','restore'))
191    state=wf.states['public']
192    state.setPermission(edit, 0, ('Manager', 'Owner'))
193
194def setupWikish_workflow(wf):
195    # Get defaults from here:
196    setupPersonal_workflow(wf)
197
198    wf.setProperties(title='LeMill Wiki-Like Workflow')
199
200    # Add edit access to all members
201    state=wf.states['public']
202    state.setPermission(edit, 0, ('Manager', 'Owner', 'CoAuthor', 'Member'))
203
204addWorkflowFactory(createGroup_workflow,
205        id='group_workflow',
206        title='LeMill resource workflow')
207
208addWorkflowFactory(createGroupBlog_workflow,
209        id='groupblog_workflow',
210        title='LeMill group workflow')
211
212addWorkflowFactory(createWikish_workflow,
213        id='wikish_workflow',
214        title='LeMill wiki-like workflow')
215
216addWorkflowFactory(createPersonal_workflow,
217        id='personal_workflow',
218        title='LeMill personal workflow')
219
220def setupScripts(wf):
221    """ this is not used but I'll keep it here as an example of how to create workflow scripts """
222    from Products.PythonScripts import PythonScript
223    scripts = wf.scripts
224    pysc = PythonScript.PythonScript('script_updateCoverImage')
225    scripts._setObject('script_updateCoverImage', pysc)
226    upd = getattr(scripts, 'script_updateCoverImage')
227    upd.write("""
228##parameters=param
229
230ob = param.object
231if not ob.getHasCoverImage():
232    return
233coverImage = ob.getCoverImage()
234img = ob.embedIcon(coverImage)
235ob.setCoverImage(img)
236""")
237
Note: See TracBrowser for help on using the repository browser.