##############################################################################
# Copyright (c) 2004-2005 Black Rock City, LLC
# Copyright (c) 2004-2005 ObjectRealms, LLC
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
##############################################################################
"""
$Id: $
"""
#
# Generated by dumpDCWorkflow.py written by Sebastien Bigaret
# Original workflow id/title: folder_team_workflow/Team-centric Folder Workflow [Plone]
# Date: 2004/09/17 15:36:43.345 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.
#
# No script detected in this workflow
# 
"""
Programmatically creates a workflow type
"""
__version__ = "$Revision: 1.1.1.1 $"[11:-2]

from Products.CMFCore.WorkflowTool import addWorkflowFactory

from Products.DCWorkflow.DCWorkflow import DCWorkflowDefinition

def setupFolder_team_workflow(wf):
    "..."
    wf.setProperties(title='Team-centric Folder Workflow [Plone]')

    for s in ['team_visible', 'visible', 'private', 'published']:
        wf.states.addState(s)
    for t in ['retract', 'team', 'hide', 'publish', 'show']:
        wf.transitions.addTransition(t)
    for v in ['action', 'time', 'comments', 'actor', 'review_history']:
        wf.variables.addVariable(v)
    for l in []:
        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('visible')

    ## States initialization
    sdef = wf.states['team_visible']
    sdef.setProperties(title="""""",
                       transitions=('hide', 'publish', 'show'))
    sdef.setPermission('Access contents information', 0, ['Manager', 'Owner', 'TeamMember', 'TeamReviewer'])
    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner', 'TeamMember'])
    sdef.setPermission('View', 0, ['Manager', 'Owner', 'TeamMember', 'TeamReviewer'])
    sdef.setPermission('List folder contents', 0, ['Manager', 'Owner', 'TeamMember', 'TeamReviewer'])

    sdef = wf.states['visible']
    sdef.setProperties(title="""Visible but not published""",
                       transitions=('hide', 'publish', 'team'))
    sdef.setPermission('Access contents information', 1, ['Anonymous', 'Manager', 'Reviewer'])
    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner', 'TeamMember'])
    sdef.setPermission('View', 1, ['Anonymous', 'Manager', 'Reviewer'])
    sdef.setPermission('List folder contents', 0, ['Manager', 'Member', 'Owner', 'TeamMember'])

    sdef = wf.states['private']
    sdef.setProperties(title="""Visible and editable only by owner""",
                       transitions=('publish', 'show', 'team'))
    sdef.setPermission('Access contents information', 0, ['Manager', 'Owner'])
    sdef.setPermission('Modify portal content', 0, ['Manager', 'Owner'])
    sdef.setPermission('View', 0, ['Manager', 'Owner'])
    sdef.setPermission('List folder contents', 0, ['Manager', 'Owner'])

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


    ## Transitions initialization
    tdef = wf.transitions['retract']
    tdef.setProperties(title="""Member retracts submission""",
                       new_state_id="""visible""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Retract""",
                       actbox_url="""%(content_url)s/content_retract_form""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': 'Request review'},
                       )

    tdef = wf.transitions['team']
    tdef.setProperties(title="""Member makes content team visible""",
                       new_state_id="""team_visible""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Make team visible""",
                       actbox_url="""%(content_url)s/what_is_this_for""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': 'Modify portal content'},
                       )

    tdef = wf.transitions['hide']
    tdef.setProperties(title="""Member makes content private""",
                       new_state_id="""private""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Make private""",
                       actbox_url="""%(content_url)s/content_hide_form""",
                       actbox_category="""workflow""",
                       props={'guard_roles': 'Owner'},
                       )

    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_permissions': 'Modify portal content', 'guard_roles': 'Owner; Manager'},
                       )

    tdef = wf.transitions['show']
    tdef.setProperties(title="""Member makes content visible""",
                       new_state_id="""visible""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Make visible""",
                       actbox_url="""%(content_url)s/content_show_form""",
                       actbox_category="""workflow""",
                       props={'guard_roles': 'Owner'},
                       )

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

    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['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['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'})

    ## Worklists Initialization

def createFolder_team_workflow(id):
    "..."
    ob = DCWorkflowDefinition(id)
    setupFolder_team_workflow(ob)
    return ob

addWorkflowFactory(createFolder_team_workflow,
                   id='folder_team_workflow',
                   title='Team-centric Folder Workflow [Plone]')

    
