# 
#
# Generated by dumpDCWorkflow.py written by Sebastien Bigaret
# Original workflow id/title: helpcenter_workflow/Default Workflow [Plone]
# Date: 2004/06/06 04:31:31.859 GMT-4
#
# 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.
#
# No script detected in this workflow
# 
"""
Programmatically creates a workflow type
"""
__version__ = "$Revision: 1.1 $"[11:-2]

from Products.CMFCore.WorkflowTool import addWorkflowFactory
from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition
from Products.PloneHelpCenter.config import *

def setupHelpcentersubitem_workflow(wf):
    "..."
    wf.setProperties(title='Sub-item workflow [PloneHelpCenter]')

    for s in ['hidden', 'published']:
        wf.states.addState(s)
    for t in ['hide', 'publish']:
        wf.transitions.addTransition(t)
    for v in ['action', 'review_history', 'actor', 'comments', 'time']:
        wf.variables.addVariable(v)
    for l in ['reviewer_queue']:
        wf.worklists.addWorklist(l)
    for p in ('Access contents information', 'Modify portal content', 'View', 'Change portal events',):
        wf.addManagedPermission(p)
        

    ## Initial State
    wf.states.setInitialState('hidden')

    ## States initialization
    sdef = wf.states['hidden']
    sdef.setProperties(title="""Draft""",
                       transitions=('publish',))
    sdef.setPermission('Access contents information', 0, ['Manager', 'Owner', 'Reviewer'])
    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner', 'Reviewer'])
    sdef.setPermission('View', 0, ['Manager', 'Owner', 'Reviewer'])
    sdef.setPermission('Change portal events', 0, ['Manager', 'Owner', 'Reviewer'])

    sdef = wf.states['published']
    sdef.setProperties(title="""Public""",
                       transitions=('hide',))
    sdef.setPermission('Access contents information', 1, ['Manager'])
    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner'])
    sdef.setPermission('View', 1, ['Manager'])
    sdef.setPermission('Change portal events', 0, ['Manager'])


    ## Transitions initialization
    tdef = wf.transitions['hide']
    tdef.setProperties(title="""Owner hides item from the public""",
                       new_state_id="""hidden""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Hide""",
                       actbox_url="""%(content_url)s/content_hide_form""",
                       actbox_category="""workflow""",
                       props={'guard_expr': 'python: user.has_permission("Review portal content", here) or user.has_role("Owner", here)' },
                       )

    tdef = wf.transitions['publish']
    tdef.setProperties(title="""Reviewer publishes content""",
                       new_state_id="""published""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Publish""",
                       actbox_url="""%(content_url)s/content_publish_form""",
                       actbox_category="""workflow""",
                       props={'guard_expr': 'python: user.has_permission("Review portal content", here) or user.has_role("Owner", here)' },
                       )

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

    ## Variables 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['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['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['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)

    ## Worklists 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'})


def createHelpcentersubitem_workflow(id):
    "..."
    ob = DCWorkflowDefinition(id)
    setupHelpcentersubitem_workflow(ob)
    return ob

def install():
    addWorkflowFactory(createHelpcentersubitem_workflow,
                       id='helpcentersubitem_workflow',
                       title='Workflow for Help Center Sub-items.')
