How to set up a custom workflow (written by: Ben Calder)
Workflow Documentation on how to set-up a custom workflow designed so that, for example, a document needs to be reviewed by more than one person before it is published can be found here.
Original URL
We needed to set-up a document so that it had to be approved ('reviewed') by a certain number of people before it was published. The following instructions are a combination of instructions from http://plone.org/documentation/howto/HowToWorkflowPerms and the generous help of Riccardo Lemmi.
Setting up a custom workflow
As this workflow is only required for this specific document it was necessary to create a custom workflow rather than edit the standard Plone workflow.
- In the ZMI, under Plone/portal workflow click on the contents tab.
- Copy and paste the default Plone_workflow then rename the copy with a relevant name.
- Click on the new workflow to edit it.
Making the pending document 'invisible'
Whilst the document is awaiting approval we don't want it to be available to anonymous users or members. As I wasn't sure where the view permission for the pending and visible states is acquired from, I wanted to manually set this within the workflow.
- Click in the States tab for your custom workflow.
- Click on the pending state, then the permissions tab.
- Remove the tick from 'Acquire permission settings' for 'Access contents information' and 'View' and then make sure there are no ticks in the corresponding 'Anonymous' and 'Authenticated' columns.
- Save the changes.
- Do the same for the 'Visible' state.
Adding variables
- Click on the 'Variables' tab.
- At the bottom of the page add a variable called 'approvals'.
- Click on your new approvals variable.
- change 'Variable update mode' to: "update only when the new state specifies a new value"
- Change the 'Default Value' to 0 (zero).
- Save your changes.
- Now add a variable called 'reviewer_name'.
- You don't need to edit this one - just save your changes.
Adding a new transition
- Click on the 'Transitions' tab.
- At the bottom of the page add a transition called 'approve'.
- Click on your new approve transition.
- Add the Title - Reviewer approves content.
- In Guard -
- add Permission: Review portal content (for any reviewer) or Role: 'name_of_reviewer' (to specifiy the reviewer type)
- in the Expression box add:
python:state_change.status.get('reviewer_name','')!=request.AUTHENTICATED_USER.getUserName()
- In 'Display in actions box' add - Name: Approve, URL: %(content_url)s/content_approve_form
- Save changes then click on the 'Variables' tab.
- From the variables drop-down box choose approvals.
- In the Expression box add:
python:int(state_change.status.get('approvals',0))+1 - Click Add.
- From the variables drop-down box choose reviewer_name.
- In the Expression box add:
python:request.AUTHENTICATED_USER.getUserName() - Click Add.
Changing the Publish transition
- Go back to 'Transitions' and click on 'publish' to edit it.
- Change the 'Trigger type' to Automatic.
- In Guard, in the Expression box add:
python:int(state_change.status.get('approvals',0))>=2 - Save changes.
Changing the state
- Go back to your custom workflows 'front page' and click on the States tab.
- Click on the pending state and add a tick next to the transition 'Approve'.
- Save changes.
Applying the workflow to a document
- Go back to the portal workflow page with the list of documents and their workflows.
- Next to the document that you want to add your custom workflow to, change the name to that of the new workflow.
- Click change.
- Click the 'update security settings' to apply the new workflow to all relevant documents.
Send any comments to me at b.calder@ucl.ac.uk
