from Products.CMFCore.WorkflowTool import addWorkflowFactory from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition from Products.CMFCore import permissions from Permissions import UseTest view = permissions.View use = permissions.ViewManagementScreens list = permissions.ListFolderContents add = permissions.AddPortalContent edit = permissions.ModifyPortalContent def createPsyhvel_workflow(id): """ create workflow """ ob = DCWorkflowDefinition(id) setupPsyhvel_workflow(ob) #setupScripts(ob) return ob def setupPsyhvel_workflow(wf): """ define workflow """ wf.setProperties(title='Psyhvel Workflow') for s in ['public', 'hidden', 'usable', 'protected']: wf.states.addState(s) for t in ['publish', 'hide', 'usable', 'protect']: wf.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: wf.variables.addVariable(v) for p in (view, use, list, add, edit): wf.addManagedPermission(p) # initial state. wf.states.setInitialState('usable') # permissions state = wf.states['protected'] state.setProperties(title='protected', transitions=('publish','hide','usable')) state.setPermission(view, 0, ('Manager', 'Owner', 'Editor', 'Member', 'Authenticated')) state.setPermission(use, 0, ('Manager', 'Owner')) state.setPermission(list, 0, ('Manager', 'Owner', 'Editor')) state.setPermission(add, 0, ('Manager', 'Owner')) state.setPermission(edit, 0, ('Manager', 'Owner')) state = wf.states['usable'] state.setProperties(title='usable', transitions=('publish','hide','protect')) state.setPermission(view, 0, ('Manager', 'Owner', 'Editor', 'Member', 'Authenticated')) state.setPermission(use, 0, ('Manager', 'Owner', 'Editor')) state.setPermission(list, 0, ('Manager', 'Owner', 'Editor')) state.setPermission(add, 0, ('Manager', 'Owner')) state.setPermission(edit, 0, ('Manager', 'Owner')) state = wf.states['public'] state.setProperties(title='published', transitions=('usable','hide','protect')) state.setPermission(view, 0, ('Manager', 'Owner', 'Editor', 'Member', 'Authenticated')) state.setPermission(use, 0, ('Manager', 'Owner', 'Editor')) state.setPermission(list, 0, ('Manager', 'Owner', 'Editor')) state.setPermission(add, 0, ('Manager', 'Owner', 'Editor')) state.setPermission(edit, 0, ('Manager', 'Owner', 'Editor')) state = wf.states['hidden'] state.setProperties(title='hidden', transitions=('usable','publish','protect')) state.setPermission(view, 0, ('Manager', 'Owner')) state.setPermission(use, 0, ('Manager', 'Owner')) state.setPermission(list, 0, ('Manager', 'Owner')) state.setPermission(add, 0, ('Manager', 'Owner')) state.setPermission(edit, 0, ('Manager', 'Owner')) # transitions trans = wf.transitions['publish'] trans.setProperties(title='Publish content', new_state_id='public', trigger_type=1, actbox_name='publish', actbox_category='workflow', props={'guard_roles':'Manager;Owner'}, ) trans = wf.transitions['usable'] trans.setProperties(title='usable', new_state_id='usable', trigger_type=1, actbox_name='usable', actbox_category='workflow', props={'guard_roles':'Manager;Owner'}, ) trans = wf.transitions['protect'] trans.setProperties(title='protect', new_state_id='protected', trigger_type=1, actbox_name='protect', actbox_category='workflow', props={'guard_roles':'Manager;Owner'}, ) trans = wf.transitions['hide'] trans.setProperties(title='hide', new_state_id='hidden', trigger_type=1, actbox_name='hide', actbox_category='workflow', props={'guard_roles':'Manager;Owner'}, ) # variables. are these good for something? wf.variables.setStateVar('review_state') vdef = wf.variables['action'] vdef = wf.variables['action'] vdef.setProperties(description='The last transition', default_expr='transition/getId|nothing', for_status=1, update_always=1) vdef = wf.variables['actor'] vdef.setProperties(description='The ID of the user who performed ' 'the last transition', default_expr='user/getId', for_status=1, update_always=1) vdef = wf.variables['comments'] vdef.setProperties(description='Comments about the last transition', default_expr="python:state_change.kwargs.get('comment', '')", for_status=1, update_always=1) vdef = wf.variables['review_history'] vdef.setProperties(description='Provides access to workflow history', default_expr="state_change/getHistory", props={'guard_permissions': 'Request review; Review portal content'}) vdef = wf.variables['time'] vdef.setProperties(description='Time of the last transition', default_expr="state_change/getDateTime", for_status=1, update_always=1) addWorkflowFactory(createPsyhvel_workflow, id='psyhvel_workflow', title='Psyhvel workflow')