# 
# Generated by dumpDCWorkflow.py written by Sebastien Bigaret
# Original workflow id/title: team_membership_workflow/Team Membership Workflow [Simple Approval]
# Date: 2006/05/31 13:13:35.055 GMT+2
#
# WARNING: this dumps does NOT contain any scripts you might have added to
# the workflow, IT IS YOUR RESPONSABILITY TO MAKE BACKUPS FOR THESE SCRIPTS.
#
# The following scripts have been detected and should be backed up:
# - membershipStateChange (External Method)
# 
"""
Programmatically create a workflow type.
"""
__version__ = "$Id: dumpDCWorkflow.py 20757 2006-03-12 23:02:15Z encolpe $"

from Products.CMFCore.WorkflowTool import addWorkflowFactory
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.PythonScripts.PythonScript import PythonScript
from Products.ExternalMethod.ExternalMethod import ExternalMethod

def setup_team_membership_workflow(wf):
    """Setup the workflow
    """
    wf.setProperties(title='Team Membership Workflow [Simple Approval]')

    for s in ('active', 'inactive', 'pending'):
        wf.states.addState(s)
    for t in ('activate', 'deactivate', 'submit'):
        wf.transitions.addTransition(t)
    for v in ('action', 'actor', 'comments', 'review_history', 'time'):
        wf.variables.addVariable(v)
    for l in ('reviewer_queue',):
        wf.worklists.addWorklist(l)
    for p in ('Access contents information',
              'Modify portal content',
              'View',
              'List folder contents'):
        wf.addManagedPermission(p)
        
    # Initial State
    wf.states.setInitialState('inactive')

    # State Initialization
    sdef = wf.states['active']
    sdef.setProperties(title='Active',
                       description='',
                       transitions=('deactivate',))
    sdef.setPermission('Access contents information', 1,
                       ['Anonymous', 'Manager'])
    sdef.setPermission('Modify portal content', 0,
                       ['Manager'])
    sdef.setPermission('View', 1,
                       ['Anonymous', 'Manager'])
    sdef.setPermission('List folder contents', 1,
                       ['Anonymous'])

    sdef = wf.states['inactive']
    sdef.setProperties(title='Inactive',
                       description='',
                       transitions=('activate', 'submit'))
    sdef.setPermission('Access contents information', 0,
                       ['Manager', 'Owner'])
    sdef.setPermission('Modify portal content', 0,
                       ['Manager'])
    sdef.setPermission('View', 0,
                       ['Manager', 'Owner'])
    sdef.setPermission('List folder contents', 0,
                       ['Manager'])

    sdef = wf.states['pending']
    sdef.setProperties(title='Pending Approval',
                       description='',
                       transitions=('activate', 'deactivate'))
    sdef.setPermission('Access contents information', 1,
                       [])
    sdef.setPermission('Modify portal content', 1,
                       [])
    sdef.setPermission('View', 1,
                       [])
    sdef.setPermission('List folder contents', 1,
                       [])

    # Transition Initialization
    tdef = wf.transitions['activate']
    tdef.setProperties(title='Membership become Active',
                       description='',
                       new_state_id='active',
                       trigger_type=1,
                       script_name='',
                       after_script_name='membershipStateChange',
                       actbox_name='Activate',
                       actbox_url='%(content_url)s/content_publish_form',
                       actbox_category='workflow',
                       props={'guard_permissions': 'Manage team memberships'},
                       )

    tdef = wf.transitions['deactivate']
    tdef.setProperties(title='Membership is Made Inactive',
                       description='',
                       new_state_id='inactive',
                       trigger_type=1,
                       script_name='',
                       after_script_name='membershipStateChange',
                       actbox_name='Deactivate',
                       actbox_url='%(content_url)s/content_retract_form',
                       actbox_category='workflow',
                       props={'guard_permissions': 'Manage team memberships'},
                       )

    tdef = wf.transitions['submit']
    tdef.setProperties(title='Submit For Activation',
                       description='',
                       new_state_id='pending',
                       trigger_type=1,
                       script_name='',
                       after_script_name='',
                       actbox_name='Submit for Approval',
                       actbox_url='%(content_url)s/content_hide_form',
                       actbox_category='workflow',
                       props={'guard_permissions': 'Manage team memberships'},
                       )

    # State Variable
    wf.variables.setStateVar('review_state')

    # Variable Initialization
    vdef = wf.variables['action']
    vdef.setProperties(description='The last transition',
                       default_value='',
                       default_expr='transition/getId|nothing',
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    vdef = wf.variables['actor']
    vdef.setProperties(description='The ID of the user who performed the last transition',
                       default_value='',
                       default_expr='user/getId',
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    vdef = wf.variables['comments']
    vdef.setProperties(description='Comments about the last transition',
                       default_value='',
                       default_expr="python:state_change.kwargs.get('comment', '')",
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    vdef = wf.variables['review_history']
    vdef.setProperties(description='Provides access to workflow history',
                       default_value='',
                       default_expr='state_change/getHistory',
                       for_catalog=0,
                       for_status=0,
                       update_always=0,
                       props={'guard_permissions': 'Request review; Review portal content'})

    vdef = wf.variables['time']
    vdef.setProperties(description='Time of the last transition',
                       default_value='',
                       default_expr='state_change/getDateTime',
                       for_catalog=0,
                       for_status=1,
                       update_always=1,
                       props=None)

    # Worklist Initialization
    ldef = wf.worklists['reviewer_queue']
    ldef.setProperties(description='Reviewer tasks',
                       actbox_name='Pending (%(count)d)',
                       actbox_url='%(portal_url)s/search?review_state=pending',
                       actbox_category='global',
                       props={'guard_permissions': 'Review portal content',
                              'var_match_review_state': 'pending'})

    # Script Initialization
    wf.scripts._setObject('membershipStateChange',
                          ExternalMethod('membershipStateChange', 'Update team security catalog data',
                                         'TeamSpace.workflow', 'membershipStateChange'))

def create_team_membership_workflow(id):
    """Create, setup and return the workflow.
    """
    ob = DCWorkflowDefinition(id)
    setup_team_membership_workflow(ob)
    return ob

addWorkflowFactory(create_team_membership_workflow,
                   id='team_membership_workflow',
                   title='Team Membership Workflow [Simple Approval]')

