<?xml version="1.0"?>
<dc-workflow xmlns:i18n="http://xml.zope.org/namespaces/i18n"
             workflow_id="bika_client_workflow"
             title="Bika Client Workflow"
             description=""
             state_variable="review_state"
             initial_state="active"
             manager_bypass="False"
             i18n:domain="senaite.core">

  <!-- This governs whether you are allowed to delete objects *inside* this folder. -->
  <permission>Delete objects</permission>
  <!-- This governs whether you are allowed to modify some content. -->
  <permission>Modify portal content</permission>
  <!-- This governs whether you are allowed to add some content. -->
  <permission>Add portal content</permission>
  <!-- This governs whether you are allowed to view some content. -->
  <permission>View</permission>
  <!-- This permission allows access to an object, without necessarily viewing
       the object. For example, a user may want to see the object's title in a
       list of results, even though the user can't view the contents of that
       file. -->
  <permission>Access contents information</permission>
  <!-- This governs whether you can get a listing of the contents of a folder;
       it doesn't check whether you have the right to view the objects listed. -->
  <permission>List folder contents</permission>

  <!-- Transitions Permissions -->
  <permission>Activate client</permission>
  <permission>Deactivate client</permission>

  <!-- State: active -->
  <state state_id="active" title="Active" i18n:attributes="title">
    <exit-transition transition_id="deactivate" />

    <!-- Deactivate client -->
    <permission-map name="Deactivate client" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
    </permission-map>

    <!-- Delete objects -->
    <permission-map name="Delete objects" acquired="False">
      <permission-role>Manager</permission-role>
    </permission-map>

    <!-- Modify portal content -->
    <permission-map name="Modify portal content" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>Owner</permission-role>
    </permission-map>

    <!-- Add portal content -->
    <permission-map name="Add portal content" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>Owner</permission-role>
    </permission-map>

    <!-- View -->
    <permission-map name="View" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>Analyst</permission-role>
      <permission-role>Sampler</permission-role>
      <permission-role>Owner</permission-role>
    </permission-map>

    <!-- Access contents information -->
    <permission-map name="Access contents information" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>Analyst</permission-role>
      <permission-role>Sampler</permission-role>
      <permission-role>Owner</permission-role>
    </permission-map>

    <!-- List folder contents -->
    <permission-map name="List folder contents" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
      <permission-role>Analyst</permission-role>
      <permission-role>Sampler</permission-role>
      <permission-role>Owner</permission-role>
    </permission-map>

  </state>
  <!-- /State: active -->

  <!-- State: inactive -->
  <state state_id="inactive" title="Inactive" i18n:attributes="title">
    <exit-transition transition_id="activate" />

    <!-- Activate client -->
    <permission-map name="Activate client" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
    </permission-map>

    <!-- Delete objects -->
    <permission-map name="Delete objects" acquired="False">
    </permission-map>

    <!-- Modify portal content -->
    <permission-map name="Modify portal content" acquired="False">
    </permission-map>

    <!-- Add portal content -->
    <permission-map name="Add portal content" acquired="False">
    </permission-map>

    <!-- View -->
    <permission-map name="View" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
    </permission-map>

    <!-- Access contents information -->
    <permission-map name="Access contents information" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
    </permission-map>

    <!-- List folder contents -->
    <permission-map name="List folder contents" acquired="False">
      <permission-role>Manager</permission-role>
      <permission-role>LabManager</permission-role>
      <permission-role>LabClerk</permission-role>
    </permission-map>
  </state>
  <!-- /State: inactive -->

  <!-- Transition: activate -->
  <transition transition_id="activate" title="Activate" new_state="active" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Activate</action>
    <guard>
      <guard-expression>python:here.guard_activate_transition()</guard-expression>
      <guard-permission>Activate client</guard-permission>
    </guard>
  </transition>
  <!-- /Transition: activate -->

  <!-- Transition: deactivate -->
  <transition transition_id="deactivate" title="Deactivate" new_state="inactive" trigger="USER" before_script="" after_script="" i18n:attributes="title">
    <action url="" category="workflow" icon="">Deactivate</action>
    <guard>
      <guard-expression>python:here.guard_deactivate_transition()</guard-expression>
      <guard-permission>Deactivate client</guard-permission>
    </guard>
  </transition>
  <!-- /Transition: deactivate -->

  <variable variable_id="action" for_catalog="False" for_status="True" update_always="True">
    <description>Previous transition</description>
    <default>
      <expression>transition/getId|nothing</expression>
    </default>
    <guard>
    </guard>
  </variable>

  <variable variable_id="actor" for_catalog="False" for_status="True" update_always="True">
    <description>The ID of the user who performed the last transition</description>
    <default>
      <expression>user/getId</expression>
    </default>
    <guard>
    </guard>
  </variable>

  <variable variable_id="comments" for_catalog="False" for_status="True" update_always="True">
    <description>Comment about the last transition</description>
    <default>
      <expression>python:state_change.kwargs.get('comment', '')</expression>
    </default>
    <guard>
    </guard>
  </variable>

  <variable variable_id="review_history" for_catalog="False" for_status="False" update_always="False">
    <description>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 variable_id="time" for_catalog="False" for_status="True" update_always="True">
    <description>When the previous transition was performed</description>
    <default>
      <expression>state_change/getDateTime</expression>
    </default>
    <guard>
    </guard>
  </variable>

</dc-workflow>
