source: products/ShortMessage/tags/0.1.3/Extensions/Sm_Workflow.py @ 1591

Last change on this file since 1591 was 1, checked in by myroslav, 15 years ago

Building directory structure

File size: 5.0 KB
Line 
1from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
2from Products.CMFCore.CMFCorePermissions import ModifyPortalContent
3from AccessControl.Permissions import view, access_contents_information
4from Products.DCWorkflow.Default import r_anon, r_manager, r_owner, r_reviewer, \
5                                        p_access, p_modify, p_view, p_request , p_review
6from Products.CMFCore.WorkflowTool import addWorkflowFactory
7from Products.CMFCore import CMFCorePermissions
8from Products.ShortMessage.config import *
9from Products import ShortMessage
10
11#add ExternalMethod named 'send_publishedMessage'
12def addWorkflowScripts(wf):
13    if 'send_publishedMessage' not in wf.scripts.objectIds():
14        wf.scripts.manage_addProduct['ExternalMethod'].manage_addExternalMethod('send_publishedMessage', 'Send Message', 'ShortMessage.Sm_Workflow', 'send_publishedMessage')
15
16def fillWorkflow(wf):
17    for state in  ('pending', 'visible', 'published',):
18        wf.states.addState(state)
19    for transition in ('publish', 'submit', 'retract'):
20        wf.transitions.addTransition(transition)
21    for permision in (p_access, p_modify, view):
22        wf.addManagedPermission(permision)
23    for l in ('reviewer_queue',):
24        wf.worklists.addWorklist(l)
25
26    # set initial state
27    wf.states.setInitialState('visible')
28
29    wf_visible = wf.states['visible']
30    wf_visible.setProperties(
31                             title='Visible but not published',
32                             transitions=('publish','submit'))
33    wf_visible.setPermission(p_access, 1, (r_anon, r_manager, r_reviewer))
34    wf_visible.setPermission(p_view, 1, (r_anon, r_manager, r_reviewer))
35    wf_visible.setPermission(p_modify, 0, (r_manager, r_owner))
36
37#    wf.permissions+=(CMFCorePermissions.ListFolderContents, )
38#    wf.states.private.permission_roles[CMFCorePermissions.ListFolderContents]=['Authenticated', r_manager]
39
40    wf_visible = wf.states['pending']
41    wf_visible.setProperties(
42                             title='Waiting for reviewer',
43                             transitions=('retract', 'publish',))
44    wf_visible.setPermission(p_access, 1, (r_manager, r_owner,  r_reviewer))
45    wf_visible.setPermission(p_view, 1, (r_manager, r_owner,  r_reviewer))
46    wf_visible.setPermission(p_modify, 0, (r_manager, r_reviewer))
47
48    wf_published = wf.states['published']
49    wf_published.setProperties(
50                               title='Public',
51                               transitions=())
52    wf_published.setPermission(p_access, 1, (r_anon, r_manager,))
53    wf_published.setPermission(p_view, 1, (r_anon, r_manager))
54    wf_published.setPermission(p_modify, 0, (r_manager, ))
55
56#    wf.states.published.permission_roles[CMFCorePermissions.ListFolderContents]=[r_anon,]
57
58    tdef = wf.transitions['submit']
59    tdef.setProperties(
60                       title='Member requests publishing',
61                       new_state_id='pending',
62                       actbox_name='Submit',
63                       actbox_url='%(content_url)s/content_submit_form',
64                       props={'guard_permissions':p_request})
65
66    tdef = wf.transitions['retract']
67    tdef.setProperties(
68                       title='Member retracts submission',
69                       new_state_id='visible',
70                       actbox_name='Retract',
71                       actbox_url='%(content_url)s/content_retract_form',
72                       props={'guard_permissions':p_request})
73
74    tdef = wf.transitions['publish']
75    tdef.setProperties(
76                       title='Reviewer publishes content',
77                       new_state_id='published',
78                       script_name = 'send_publishedMessage',
79                       actbox_name='Publish',
80                       actbox_url='%(content_url)s/content_publish_form',
81                       props={'guard_permissions':r_anon})
82
83    wf.variables.setStateVar('review_state')
84
85    ldef = wf.worklists['reviewer_queue']
86    ldef.setProperties(description='Reviewer tasks',
87                       actbox_name='Pending (%(count)d)',
88                       actbox_url='%(portal_url)s/search?review_state=pending',
89                       props={'var_match_review_state':'pending',
90                              'guard_permissions':p_review})
91
92
93def setupWorkflow(portal):
94    portal_workflow = portal.portal_workflow
95    addWorkflowFactory(createWorkflow,
96                   id=Sm_WORKFLOWID,
97                   title='ShortMessage Workflow')
98    portal_workflow.manage_addWorkflow(id=Sm_WORKFLOWID, workflow_type=Sm_WORKFLOWID +' (ShortMessage Workflow)')
99    addWorkflowScripts(portal_workflow[Sm_WORKFLOWID])
100    #set workflow for SMS
101    portal_workflow.setChainForPortalTypes( ('ShortMessage'), Sm_WORKFLOWID)
102
103def send_publishedMessage(self, state_change):
104    """Sending message if it is published"""
105    message_obj = state_change.object
106    #send message to user(s)
107    state_change.getPortal().portal_smsCommunicator.send_Request(message_obj.getSender(), message_obj.getRecipient(), message_obj.getBody())
108
109#create workflow
110def createWorkflow(id):
111    wf = DCWorkflowDefinition(id)
112    fillWorkflow(wf)
113    return wf
Note: See TracBrowser for help on using the repository browser.