from Products.CMFCore.WorkflowTool import addWorkflowFactory from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition from Products.CMFCore import permissions from Permissions import MarkTask, EditTask view = permissions.View mark = 'Mark Task' edit = 'Edit Task' reply = permissions.ReplyToItem def createTask_workflow(id): """ create workflow """ ob = DCWorkflowDefinition(id) setupTask_workflow(ob) #setupScripts(ob) return ob def createSimpleWorkflow(id): """ create a simple workflow """ ob = DCWorkflowDefinition(id) setupSimpleWorkflow(ob) return ob def setupSimpleWorkflow(wf): """ define simple workflow """ wf.setProperties(title = "Eportfolio simple workflow") for s in ['public', 'private']: wf.states.addState(s) for t in ['publish', 'hide']: wf.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: wf.variables.addVariable(v) for p in (view,): wf.addManagedPermission(p) # initial state wf.states.setInitialState('public') # permissions state = wf.states['public'] state.setProperties(title='public', transitions=('hide',)) state.setPermission(view, 0, ('Manager', 'Owner', 'Member', 'Authenticated', 'Anonymous')) state = wf.states['private'] state.setProperties(title='private', transitions=('publish',)) state.setPermission(view, 0, ('Manager', 'Owner')) # transitions trans = wf.transitions['publish'] trans.setProperties(title='Publish', new_state_id = 'public', trigger_type = 1, actbox_name = 'publish', actbox_category = 'workflow', props = {'guard_roles': 'Manager;Owner'}, ) trans = wf.transitions['hide'] trans.setProperties(title='Hide', new_state_id = 'private', trigger_type = 1, actbox_name = 'hide', actbox_category = 'workflow', props = {'guard_roles': 'Manager;Owner'}, ) # variables wf.variables.setStateVar('review_state') 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) def setupTask_workflow(wf): """ define workflow """ wf.setProperties(title='Eportfolio Task Workflow') for s in ['public', 'hidden', 'restricted', 'public_accepted', 'restricted_accepted']: wf.states.addState(s) for t in ['publish', 'hide', 'restrict', 'accept_public', 'accept_restricted']: wf.transitions.addTransition(t) for v in ['review_history', 'comments', 'time', 'actor', 'action']: wf.variables.addVariable(v) for p in (view, mark, edit, reply): wf.addManagedPermission(p) # initial state. wf.states.setInitialState('public') # permissions state = wf.states['restricted'] state.setProperties(title='restricted', transitions=('publish','hide','accept_restricted')) #state.setPermission(view, 0, ('Manager', 'Owner', 'Viewer', 'Lecturer', 'Student')) state.setPermission(view, 0, ('Manager', 'Owner', 'Viewer', 'Lecturer')) state.setPermission(reply, 0, ('Manager', 'Owner', 'Viewer', 'Lecturer')) state.setPermission(mark, 0, ('Manager', 'Owner', 'Lecturer')) state.setPermission(edit, 0, ('Manager', 'Owner')) state = wf.states['public'] state.setProperties(title='published', transitions=('restrict','hide','accept_public')) state.setPermission(view, 0, ('Manager', 'Owner', 'Student', 'Lecturer', 'Member', 'Authenticated', 'Anonymous')) state.setPermission(reply, 0, ('Manager', 'Owner', 'Student', 'Lecturer', 'Member', 'Authenticated')) state.setPermission(mark, 0, ('Manager', 'Owner', 'Lecturer')) state.setPermission(edit, 0, ('Manager', 'Owner')) state = wf.states['hidden'] state.setProperties(title='hidden', transitions=('restrict','publish')) state.setPermission(view, 0, ('Manager', 'Owner')) state.setPermission(reply, 0, ('Manager', 'Owner')) state.setPermission(mark, 0, ('Manager', 'Owner')) state.setPermission(edit, 0, ('Manager', 'Owner')) state = wf.states['public_accepted'] state.setProperties(title='public, accepted', transitions=()) state.setPermission(view, 0, ('Manager', 'Owner', 'Student', 'Lecturer', 'Member', 'Authenticated', 'Anonymous')) state.setPermission(reply, 0, ('Manager', 'Owner', 'Student', 'Lecturer', 'Member', 'Authenticated')) state.setPermission(mark, 0, ('Manager', 'Owner', 'Lecturer')) state.setPermission(edit, 0, ('Manager')) state = wf.states['restricted_accepted'] state.setProperties(title='restricted, accepted', transitions=()) state.setPermission(view, 0, ('Manager', 'Owner', 'Lecturer', 'Student')) state.setPermission(reply, 0, ('Manager', 'Owner', 'Lecturer', 'Student')) state.setPermission(mark, 0, ('Manager', 'Owner', 'Lecturer')) state.setPermission(edit, 0, ('Manager')) # 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['restrict'] trans.setProperties(title='restrict', new_state_id='restricted', trigger_type=1, actbox_name='restrict', actbox_category='workflow', props={'guard_roles':'Manager;Owner', 'guard_expr': 'here/allowRestricted'}, ) 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'}, ) trans = wf.transitions['accept_public'] trans.setProperties(title='accept', new_state_id='public_accepted', trigger_type=1, actbox_name='accept', actbox_category='workflow', props={'guard_roles':'Manager;Lecturer', 'guard_expr': 'here/allowAccepted'}, ) trans = wf.transitions['accept_restricted'] trans.setProperties(title='accept', new_state_id='restricted_accepted', trigger_type=1, actbox_name='accept', actbox_category='workflow', props={'guard_roles':'Manager;Lecturer', 'guard_expr': 'here/allowAccepted'}, ) # variables. are these good for something? wf.variables.setStateVar('review_state') 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(createTask_workflow, id='task_workflow', title='Eportfolio task workflow') addWorkflowFactory(createSimpleWorkflow, id = 'simple_workflow', title = 'Eportfolio simple workflow')