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