##############################################################################
# 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: plone_team_workflow/Default Team-centric Workflow [Plone]
# Date: 2004/09/17 18:42:41.273 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 setupPlone_team_workflow(wf):
    "..."
    wf.setProperties(title='Default Team-centric Workflow [Plone]')

    for s in ['team_visible', 'visible', 'private', 'pending', 'published']:
        wf.states.addState(s)
    for t in ['hide', 'show', 'team', 'publish', 'submit', 'reject', 'retract']:
        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('visible')

    ## States initialization
    sdef = wf.states['team_visible']
    sdef.setProperties(title="""Team Visible""",
                       transitions=('hide', 'publish', 'show', 'submit'))
    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('Change portal events', 0, ['Manager', 'Owner', 'TeamMember'])

    sdef = wf.states['visible']
    sdef.setProperties(title="""Visible but not published""",
                       transitions=('hide', 'publish', 'submit', '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('Change portal events', 0, ['Manager', 'Owner', 'TeamMember'])

    sdef = wf.states['private']
    sdef.setProperties(title="""Visible and editable only by owner""",
                       transitions=('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('Change portal events', 0, ['Manager', 'Owner'])

    sdef = wf.states['pending']
    sdef.setProperties(title="""Waiting for reviewer""",
                       transitions=('hide', 'publish', 'reject', 'retract'))
    sdef.setPermission('Access contents information', 1, ['Manager', 'Owner', 'Reviewer', 'TeamMember', 'TeamReviewer'])
    sdef.setPermission('Modify portal content', 0, ['Manager', 'Reviewer', 'TeamReviewer'])
    sdef.setPermission('View', 1, ['Manager', 'Owner', 'Reviewer', 'TeamMember', 'TeamReviewer'])
    sdef.setPermission('Change portal events', 0, ['Manager', 'Reviewer', 'TeamReviewer'])

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


    ## Transitions initialization
    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['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'},
                       )

    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['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': 'Review portal content'},
                       )

    tdef = wf.transitions['submit']
    tdef.setProperties(title="""Member requests publishing""",
                       new_state_id="""pending""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Submit""",
                       actbox_url="""%(content_url)s/content_submit_form""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': 'Request review'},
                       )

    tdef = wf.transitions['reject']
    tdef.setProperties(title="""Reviewer rejects submission""",
                       new_state_id="""visible""",
                       trigger_type=1,
                       script_name="""""",
                       after_script_name="""""",
                       actbox_name="""Reject""",
                       actbox_url="""%(content_url)s/content_reject_form""",
                       actbox_category="""workflow""",
                       props={'guard_permissions': 'Review portal content'},
                       )

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

    ## 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 createPlone_team_workflow(id):
    "..."
    ob = DCWorkflowDefinition(id)
    setupPlone_team_workflow(ob)
    return ob

addWorkflowFactory(createPlone_team_workflow,
                   id='plone_team_workflow',
                   title='Default Team-centric Workflow [Plone]')

    
