<?xml version="1.0"?>
<ZopeData>
  <record id="1" aka="AAAAAAAAAAE=">
    <pickle>
      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
    </pickle>
    <pickle>
      <dictionary>
        <item>
            <key> <string>Script_magic</string> </key>
            <value> <int>3</int> </value>
        </item>
        <item>
            <key> <string>_bind_names</string> </key>
            <value>
              <object>
                <klass>
                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
                </klass>
                <tuple/>
                <state>
                  <dictionary>
                    <item>
                        <key> <string>_asgns</string> </key>
                        <value>
                          <dictionary>
                            <item>
                                <key> <string>name_container</string> </key>
                                <value> <string>container</string> </value>
                            </item>
                            <item>
                                <key> <string>name_context</string> </key>
                                <value> <string>context</string> </value>
                            </item>
                            <item>
                                <key> <string>name_m_self</string> </key>
                                <value> <string>script</string> </value>
                            </item>
                            <item>
                                <key> <string>name_subpath</string> </key>
                                <value> <string>traverse_subpath</string> </value>
                            </item>
                          </dictionary>
                        </value>
                    </item>
                  </dictionary>
                </state>
              </object>
            </value>
        </item>
        <item>
            <key> <string>_body</string> </key>
            <value> <string>from DateTime import DateTime\n
\n
computer = context\n
portal = context.getPortalObject()\n
allocation_scope = computer.getAllocationScope()\n
computer_reference = computer.getReference()\n
\n
if allocation_scope not in [\'open/public\', \'open/friend\', \'open/personal\']:\n
  return\n
\n
if allocation_scope == target_allocation_scope:\n
  # already changed\n
  return\n
\n
person = computer.getSourceAdministrationValue(portal_type="Person")\n
if not person:\n
  return\n
\n
if not person.Person_isServiceProvider():\n
  edit_kw = {\n
    \'allocation_scope\': target_allocation_scope,\n
  }\n
\n
  # Create a ticket (or re-open it) for this issue!\n
  support_request = None\n
  request_title = \'We have changed allocation scope for %s\' % computer_reference\n
  request_description = \'Allocation scope has been changed to \' \\\n
                       \'%s for %s\' % (target_allocation_scope, computer_reference)\n
            \n
  support_request_url = context.Base_generateSupportRequestForSlapOS(\n
                 request_title,\n
                 request_description,\n
                 computer.getRelativeUrl()\n
               )\n
  if support_request_url:\n
    support_request = portal.restrictedTraverse(support_request_url)\n
    support_request.suspend()\n
  else:\n
    # XXX - Base_generateSupportRequestForSlapOS return None if the \n
    # support_request already exist, but we want to use it again so...\n
    support_request = portal.portal_catalog.getResultValue(\n
          portal_type = \'Support Request\',\n
          title = request_title,\n
          simulation_state = [\'suspended\', \'open\'],\n
          source_project_uid = computer.getUid()\n
    )\n
  if support_request is None:\n
    # Existing ticket not found, can not create event for the moment\n
    return\n
  \n
  # Send notification message\n
  notification_message = portal.portal_notifications.getDocumentValue(\n
                 reference=notification_message_reference)\n
\n
  if notification_message is not None:\n
    mapping_dict = {\'computer_title\':computer.getTitle(),\n
                    \'computer_id\':computer_reference,\n
                    \'allocation_scope\':allocation_scope}\n
    message = notification_message.asText(\n
              substitution_method_parameter_dict={\'mapping_dict\':mapping_dict})\n
  else:\n
    message = request_description\n
\n
  event = support_request.SupportRequest_trySendNotificationMessage(request_title,\n
              message, person.getRelativeUrl())\n
\n
  if event is not None:\n
    computer.edit(**edit_kw)\n
</string> </value>
        </item>
        <item>
            <key> <string>_params</string> </key>
            <value> <string>target_allocation_scope=\'open/personal\', notification_message_reference=\'slapos-crm-computer_allocation_scope.notification\'</string> </value>
        </item>
        <item>
            <key> <string>id</string> </key>
            <value> <string>Computer_checkAndUpdateAllocationScope</string> </value>
        </item>
      </dictionary>
    </pickle>
  </record>
</ZopeData>
