Commit 20c2d16c authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_erp5: Reimplement Computer_updateAllocationScope into an interaction workflow

This is for adjust subject_list and capacity_scope of the computer after the computer been edited.
parent 3feff300
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
</chain> </chain>
<chain> <chain>
<type>Computer</type> <type>Computer</type>
<workflow>local_permission_slapos_interaction_workflow</workflow> <workflow>local_permission_slapos_interaction_workflow, slapos_erp5_interaction_workflow</workflow>
</chain> </chain>
<chain> <chain>
<type>Computer Model</type> <type>Computer Model</type>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="InteractionDefinition" module="Products.ERP5.Interaction"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>actbox_category</string> </key>
<value> <string>workflow</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>activate_script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>after_script_name</string> </key>
<value>
<list>
<string>Computer_updateAllocation</string>
</list>
</value>
</item>
<item>
<key> <string>before_commit_script_name</string> </key>
<value>
<tuple/>
</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>Computer_setAllocationScope</string> </value>
</item>
<item>
<key> <string>method_id</string> </key>
<value>
<list>
<string>_setAllocationScope*</string>
</list>
</value>
</item>
<item>
<key> <string>once_per_transaction</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>portal_type_filter</string> </key>
<value>
<list>
<string>Computer</string>
</list>
</value>
</item>
<item>
<key> <string>portal_type_group_filter</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>script_name</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>temporary_document_disallowed</string> </key>
<value> <int>0</int> </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>
computer = state_object["object"]
allocation_scope = computer.getAllocationScope()
if allocation_scope == 'open/public':
# Public computer capacity is handle by an alarm
capacity_scope = 'close'
elif allocation_scope.startswith('open'):
# Capacity is not handled for 'private' computers
capacity_scope = 'open'
else:
capacity_scope = 'close'
edit_kw = {
'capacity_scope': capacity_scope,
}
self_person = computer.getSourceAdministrationValue(portal_type="Person")
if self_person is None:
computer.edit(**edit_kw)
return
self_email = self_person.getDefaultEmailCoordinateText()
if allocation_scope == 'open/public':
# reset friends and update in place
edit_kw['subject_list'] = ['']
edit_kw['destination_section'] = None
elif allocation_scope == 'open/personal':
# reset friends to self and update in place
edit_kw['subject_list'] = [self_email]
edit_kw['destination_section_value'] = self_person
else:
subject_list = computer.getSubjectList()
if self_email not in subject_list:
# add self as friend
subject_list.append(self_email)
edit_kw['subject_list'] = subject_list
computer.edit(**edit_kw)
<?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>_params</string> </key>
<value> <string>state_object</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Computer_updateAllocation</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -3,6 +3,7 @@ Computer Model | local_permission_slapos_interaction_workflow ...@@ -3,6 +3,7 @@ Computer Model | local_permission_slapos_interaction_workflow
Computer Network | local_permission_slapos_interaction_workflow Computer Network | local_permission_slapos_interaction_workflow
Computer Network | slapos_erp5_interaction_workflow Computer Network | slapos_erp5_interaction_workflow
Computer | local_permission_slapos_interaction_workflow Computer | local_permission_slapos_interaction_workflow
Computer | slapos_erp5_interaction_workflow
Hosting Subscription | local_permission_slapos_interaction_workflow Hosting Subscription | local_permission_slapos_interaction_workflow
Integration Site | local_permission_slapos_interaction_workflow Integration Site | local_permission_slapos_interaction_workflow
Organisation | slapos_erp5_interaction_workflow Organisation | slapos_erp5_interaction_workflow
......
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