<?xml version="1.0" encoding="utf-8"?>
<dc-workflow xmlns:i18n="http://xml.zope.org/namespaces/i18n"
             description="Workflow for Tasks / Todo items"
             initial_state="open"
             manager_bypass="True"
             state_variable="review_state"
             title="Todo Workflow"
             workflow_id="todo_workflow"
             i18n:attributes="title; description"
             i18n:domain="ploneintranet"
>

  <!--XXX
    We don't really want to manage permissions here, but we have to because an
    Editor does not have Modify portal content permission on a workspace, so
    it is not acquired. This is modelled on the ploneintranet_workflow.
    Alternatively we can maybe do this with local role adapters.
  -->
  <permission>Modify portal content</permission>
  <permission>Delete objects</permission>
  <state state_id="done"
         title="Done"
         i18n:attributes="title"
  >
    <description>The task is done.</description>
    <exit-transition transition_id="set_to_open" />
    <exit-transition transition_id="set_to_planned" />
    <permission-map acquired="False"
                    name="Modify portal content"
    >
      <permission-role>Assignee</permission-role>
      <permission-role>Manager</permission-role>
      <permission-role>Owner</permission-role>
      <permission-role>TeamManager</permission-role>
      <permission-role>Editor</permission-role>
      <permission-role>Site Administrator</permission-role>
    </permission-map>
    <permission-map acquired="False"
                    name="Delete objects"
    >
      <permission-role>Manager</permission-role>
      <permission-role>Owner</permission-role>
      <permission-role>TeamManager</permission-role>
      <permission-role>Editor</permission-role>
      <permission-role>Reviewer</permission-role>
      <permission-role>Site Administrator</permission-role>
    </permission-map>
  </state>
  <state state_id="open"
         title="Open"
         i18n:attributes="title"
  >
    <exit-transition transition_id="finish" />
    <exit-transition transition_id="set_to_planned" />
    <permission-map acquired="False"
                    name="Modify portal content"
    >
      <permission-role>Assignee</permission-role>
      <permission-role>Manager</permission-role>
      <permission-role>Owner</permission-role>
      <permission-role>TeamManager</permission-role>
      <permission-role>Editor</permission-role>
      <permission-role>Site Administrator</permission-role>
    </permission-map>
    <permission-map acquired="False"
                    name="Delete objects"
    >
      <permission-role>Manager</permission-role>
      <permission-role>Owner</permission-role>
      <permission-role>TeamManager</permission-role>
      <permission-role>Editor</permission-role>
      <permission-role>Reviewer</permission-role>
      <permission-role>Site Administrator</permission-role>
    </permission-map>
  </state>
  <state state_id="planned"
         title="Planned"
         i18n:attributes="title"
  >
    <description>This task is planned for a future milestone.</description>
    <exit-transition transition_id="finish" />
    <exit-transition transition_id="set_to_open" />
    <permission-map acquired="False"
                    name="Modify portal content"
    >
      <permission-role>Assignee</permission-role>
      <permission-role>Manager</permission-role>
      <permission-role>Owner</permission-role>
      <permission-role>TeamManager</permission-role>
      <permission-role>Editor</permission-role>
      <permission-role>Site Administrator</permission-role>
    </permission-map>
    <permission-map acquired="False"
                    name="Delete objects"
    >
      <permission-role>Manager</permission-role>
      <permission-role>Owner</permission-role>
      <permission-role>TeamManager</permission-role>
      <permission-role>Editor</permission-role>
      <permission-role>Reviewer</permission-role>
      <permission-role>Site Administrator</permission-role>
    </permission-map>
  </state>
  <transition after_script=""
              before_script=""
              new_state="done"
              title="Finish"
              transition_id="finish"
              trigger="USER"
              i18n:attributes="title"
  >
    <action category="workflow"
            icon=""
            url="%(content_url)s/content_status_modify?workflow_action=finish"
            i18n:translate=""
    >Finish</action>
    <guard>
      <guard-permission>Modify portal content</guard-permission>
    </guard>
  </transition>
  <transition after_script=""
              before_script=""
              new_state="open"
              title="Set to Open"
              transition_id="set_to_open"
              trigger="USER"
              i18n:attributes="title"
  >
    <action category="workflow"
            icon=""
            url="%(content_url)s/content_status_modify?workflow_action=set_to_open"
            i18n:translate=""
    >Set to Open</action>
    <guard>
      <guard-permission>Modify portal content</guard-permission>
    </guard>
  </transition>
  <transition after_script=""
              before_script=""
              new_state="planned"
              title="Set to Planned"
              transition_id="set_to_planned"
              trigger="USER"
              i18n:attributes="title"
  >
    <action category="workflow"
            icon=""
            url="%(content_url)s/content_status_modify?workflow_action=set_to_planned"
            i18n:translate=""
    >Set to Planned</action>
    <guard>
</guard>
  </transition>
  <variable for_catalog="False"
            for_status="True"
            update_always="True"
            variable_id="action"
  >
    <description i18n:translate="">Previous transition</description>
    <default>
      <expression>transition/getId|nothing</expression>
    </default>
    <guard>
</guard>
  </variable>
  <variable for_catalog="False"
            for_status="True"
            update_always="True"
            variable_id="actor"
  >
    <description i18n:translate="">The ID of the user who performed the previous transition</description>
    <default>
      <expression>user/getId</expression>
    </default>
    <guard>
</guard>
  </variable>
  <variable for_catalog="False"
            for_status="True"
            update_always="True"
            variable_id="comments"
  >
    <description i18n:translate="">Comment about the last transition</description>
    <default>
      <expression>python:state_change.kwargs.get('comment', '')</expression>
    </default>
    <guard>
</guard>
  </variable>
  <variable for_catalog="False"
            for_status="False"
            update_always="False"
            variable_id="review_history"
  >
    <description i18n:translate="">Provides access to workflow history</description>
    <default>
      <expression>state_change/getHistory</expression>
    </default>
    <guard>
      <guard-permission>Request review</guard-permission>
      <guard-permission>Review portal content</guard-permission>
    </guard>
  </variable>
  <variable for_catalog="False"
            for_status="True"
            update_always="True"
            variable_id="time"
  >
    <description i18n:translate="">When the previous transition was performed</description>
    <default>
      <expression>state_change/getDateTime</expression>
    </default>
    <guard>
</guard>
  </variable>
</dc-workflow>
