File: FolderWorkflow.py

package info (click to toggle)
zope-cmfplone 2.5.1-4
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 7,740 kB
  • ctags: 5,226
  • sloc: python: 28,179; xml: 3,723; php: 129; makefile: 99; sh: 2
file content (72 lines) | stat: -rw-r--r-- 3,343 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
from warnings import warn
warn('FolderWorkflow is deprecated and will be removed in Plone 3.0. '
     'Please use a GenericSetup profile instead.', DeprecationWarning)

from Products.CMFCore.WorkflowTool import addWorkflowFactory
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.CMFCore.permissions import AccessContentsInformation, \
        ListFolderContents, ModifyPortalContent, View
from Products.DCWorkflow.Default import setupDefaultWorkflowRev2

def setupFolderWorkflow(wf):
    setupDefaultWorkflowRev2(wf)
    #Published folders means that anonymous should be able to 'list the folder contents'
    wf.permissions+=(ListFolderContents, )
    wf.states.published.permission_roles[ListFolderContents]=['Anonymous',]
    wf.states.published.permission_roles[ModifyPortalContent]=('Manager', 'Owner')
    wf.states.visible.permission_roles[ListFolderContents]=('Manager', 'Owner', 'Member')
    wf.states.private.permission_roles[ListFolderContents]=('Manager', 'Owner')
    wf.states.deleteStates( ('pending', ) )
    state_priv=wf.states['private']
    state_priv.transitions = ('publish', 'show')
    state_pub=wf.states['published']
    state_pub.transitions = ('hide', 'retract')
    wf.transitions.deleteTransitions( ('submit', 'reject') )
    trans_publish=wf.transitions['publish']
    trans_publish_guard=trans_publish.getGuard()
    trans_publish_guard.permissions=(ModifyPortalContent, )
    trans_publish_guard.roles=('Owner', 'Manager')

def createFolderWorkflow(id):
    ob=DCWorkflowDefinition(id)
    setupFolderWorkflow(ob)
    ob.setProperties(title='Folder Workflow [Plone]')
    return ob

addWorkflowFactory( createFolderWorkflow, id='folder_workflow'
                  , title='Folder Workflow [Plone]')


def setupPrivateFolderWorkflow(wf):
    setupFolderWorkflow(wf)
    wf.states.visible.permission_roles[View] = ('Member', 'Reviewer', 'Manager')
    wf.states.published.permission_roles[ListFolderContents] = ('Authenticated', 'Manager')
    wf.states.published.permission_roles[View] = ('Member', 'Reviewer', 'Manager')
    wf.states.setInitialState(id='private')

    wf.states.addState('public')
    sdef=wf.states.public
    sdef.setProperties( title='Publicly available'
                      , transitions=('reject', 'retract', 'hide') )
    sdef.setPermission( View, 1, ('Anonymous', 'Authenticated') )
    sdef.setPermission( AccessContentsInformation, 1, ('Anonymous', 'Authenticated') )
    sdef.setPermission( ListFolderContents, 1, ('Anonymous', 'Authenticated') )
    sdef.setPermission( ModifyPortalContent, 1, ('Manager', ) )
    wf.transitions.addTransition('publicize')
    tdef=wf.transitions.publicize
    tdef.setProperties( title='Publicize content'
                      , new_state_id='public'
                      , actbox_name='Publicize'
                      , actbox_url='%(content_url)s/content_history_form'
                      , props={'guard_permissions':ModifyPortalContent
                              ,'guard_roles':'Owner;Manager'} )
    for sdef in wf.states.objectValues():
        sdef.setProperties( transitions=tuple(sdef.transitions)+('publicize',) )


def createPrivateFolderWorkflow(id):
    ob=DCWorkflowDefinition(id)
    setupPrivateFolderWorkflow(ob)
    ob.setProperties(title='Private Folder Workflow [Plone]')
    return ob