Commit a74849c4 authored by Łukasz Nowak's avatar Łukasz Nowak

Implement computer request via SlapTool.

parent 36e0ccc0
<?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 encoding="cdata"><![CDATA[
person = state_change[\'object\']\n
portal = person.getPortalObject()\n
# Get required arguments\n
kwargs = state_change.kwargs\n
\n
# Required args\n
# Raise TypeError if all parameters are not provided\n
try:\n
computer_title = kwargs[\'computer_title\']\n
except KeyError:\n
raise TypeError, "Person_requestComputer takes exactly 1 argument"\n
\n
tag = "%s_%s_computerInProgress" % (person.getUid(), \n
computer_title)\n
if (portal.portal_activities.countMessageWithTag(tag) > 0):\n
# The software instance is already under creation but can not be fetched from catalog\n
# As it is not possible to fetch informations, it is better to raise an error\n
raise NotImplementedError(tag)\n
\n
computer_portal_type = "Computer"\n
certificate_dict = {\'certificate\': None, \'key\': None}\n
computer = portal.portal_catalog.getResultValue(portal_type=computer_portal_type, title=computer_title)\n
if computer is None:\n
reference = "COMP-%s" % portal.portal_ids.generateNewId(\n
id_group=\'slap_computer_reference\',\n
id_generator=\'uid\')\n
certificate_dict = portal.portal_certificate_authority.getNewCertificate(reference)\n
module = portal.getDefaultModule(portal_type=computer_portal_type)\n
computer = module.newContent(\n
portal_type=computer_portal_type,\n
title=computer_title,\n
reference=reference,\n
destination_reference=certificate_dict["id"],\n
capacity_scope=\'open\',\n
activate_kw={\'tag\': tag}\n
)\n
computer.requestComputerRegistration()\n
computer.approveComputerRegistration()\n
\n
\n
computer = context.restrictedTraverse(computer.getRelativeUrl())\n
\n
context.REQUEST.set("computer_certificate", certificate_dict["certificate"])\n
context.REQUEST.set("computer_key", certificate_dict["key"])\n
context.REQUEST.set("computer", computer.getRelativeUrl())\n
context.REQUEST.set("computer_url", computer.absolute_url())\n
context.REQUEST.set("computer_reference", computer.getReference())\n
]]></string> </value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>state_change</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Person_requestComputer</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -22,6 +22,7 @@
<key> <string>transitions</string> </key>
<value>
<tuple>
<string>request_computer</string>
<string>request_software_instance</string>
</tuple>
</value>
......
......@@ -23,6 +23,7 @@
<value>
<tuple>
<string>draft</string>
<string>request_computer</string>
<string>request_software_instance</string>
</tuple>
</value>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="TransitionDefinition" module="Products.DCWorkflow.Transitions"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</string> </value>
</item>
<item>
<key> <string>actbox_icon</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_name</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>actbox_url</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value> <string>Person_requestComputer</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>guard</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>request_computer</string> </value>
</item>
<item>
<key> <string>new_state_id</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>script_name</string> </key>
<value> <string>Person_checkConsistency</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>trigger_type</string> </key>
<value> <int>2</int> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
839
\ No newline at end of file
840
\ No newline at end of file
......@@ -364,6 +364,24 @@ class SlapTool(BaseTool):
"""
return self._supplySupply(url, computer_id, state)
@convertToREST
def _requestComputer(self, computer_title):
portal = self.getPortalObject()
person = portal.ERP5Site_getAuthenticatedMemberPersonValue()
person.requestComputer(computer_title=computer_title)
computer = Computer(self.REQUEST.get('computer_reference'))
computer._certificate = self.REQUEST.get('computer_certificate')
computer._key = self.REQUEST.get('computer_key')
return xml_marshaller.xml_marshaller.dumps(computer)
security.declareProtected(Permissions.AccessContentsInformation,
'requestComputer')
def requestComputer(self, computer_title):
"""
Request Computer
"""
return self._requestComputer(computer_title)
security.declareProtected(Permissions.AccessContentsInformation,
'buildingSoftwareRelease')
def buildingSoftwareRelease(self, url, computer_id):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment