Commit 7e808622 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_crm: Do not suspend Support Requests

Tickets should be automatic suspended if they aren't supposed to be responded by the user.
parent 95eb074e
...@@ -7,6 +7,7 @@ portal.portal_catalog.searchAndActivate( ...@@ -7,6 +7,7 @@ portal.portal_catalog.searchAndActivate(
portal_type='Support Request', portal_type='Support Request',
simulation_state='validated', simulation_state='validated',
default_resource_uid=default_resource_uid, default_resource_uid=default_resource_uid,
default_aggregate_portal_type=["Hosting Subscription"],
method_id='SupportRequest_updateMonitoringState', method_id='SupportRequest_updateMonitoringState',
activate_kw = {'tag':tag} activate_kw = {'tag':tag}
) )
......
from DateTime import DateTime
import json
portal = context.getPortalObject()
if context.getSimulationState() == "invalidated":
return
computer = context.getAggregateValue(portal_type="Computer")
if computer is not None:
memcached_dict = context.getPortalObject().portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
try:
d = json.loads(memcached_dict[computer.getReference()])
last_contact = DateTime(d.get('created_at'))
if not ((DateTime() - last_contact) < 0.01):
return
except KeyError:
return
person = context.getDestinationDecision(portal_type="Person")
if not person:
return
if context.getSimulationState() != "suspended":
context.suspend()
# Send Notification message
message = """ Suspending this ticket as the computer contacted again. """
notification_reference = "slapos-crm-support-request-suspend-computer-back-notification"
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_reference)
if notification_message is not None:
mapping_dict = {'computer_title':computer.getTitle(),
'computer_reference':computer.getTitle(),
'last_contact' : last_contact }
message = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':mapping_dict})
return context.SupportRequest_trySendNotificationMessage(
"Computer is contacting again", message, person)
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupportRequest_updateMonitoringComputerState</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
portal = context.getPortalObject()
document = context.getAggregateValue()
if document is None:
return
has_error = False
software_instance = None
# Check if at least one software Instance is Allocated
for instance in document.getSpecialiseRelatedValueList(
portal_type=["Software Instance", "Slave Instance"]):
if instance.getSlapState() not in ["start_requested", "stop_requested"]:
continue
if instance.getAggregateValue() is not None:
if instance.getPortalType() == "Software Instance" and \
instance.SoftwareInstance_hasReportedError():
software_instance = instance
has_error = True
break
else:
has_error = True
break
if not has_error:
person = context.getDestinationDecision(portal_type="Person")
if not person:
return
if software_instance is not None:
message = software_instance.SoftwareInstance_hasReportedError(include_message=True)
if message in ["Not possible to find the last message", "#access instance available"]:
# Do not change state in case of transitory states.
return
if context.getSimulationState() == "validated":
context.suspend()
else:
return
# Send Notification message
message = """ Suspending this ticket as the problem is not present anymore. """
notification_reference = "slapos-crm-support-request-suspend-hs-notification"
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_reference)
if notification_message is not None:
mapping_dict = {'hosting_subscription_title':document.getTitle()}
message = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':mapping_dict})
return context.SupportRequest_trySendNotificationMessage(
"Suspending this ticket as the problem is not present anymore", message, person)
<?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></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SupportRequest_updateMonitoringHostingSubscriptionState</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
if context.getSimulationState() == "invalidated": if context.getSimulationState() == "invalidated":
return return
document = context.getAggregateValue() document = context.getAggregateValue(portal_type="Hosting Subscription")
if document is None: if document is None:
return return
if document.getPortalType() == "Computer":
return context.SupportRequest_updateMonitoringComputerState()
if document.getPortalType() == "Hosting Subscription": if document.getPortalType() == "Hosting Subscription":
if document.getSlapState() == "destroy_requested": if document.getSlapState() == "destroy_requested":
return context.SupportRequest_updateMonitoringDestroyRequestedState() return context.SupportRequest_updateMonitoringDestroyRequestedState()
return context.SupportRequest_updateMonitoringHostingSubscriptionState()
...@@ -917,6 +917,7 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin): ...@@ -917,6 +917,7 @@ class TestSlapOSisSupportRequestCreationClosed(TestCRMSkinsMixin):
def afterSetUp(self): def afterSetUp(self):
TestCRMSkinsMixin.afterSetUp(self) TestCRMSkinsMixin.afterSetUp(self)
self._cancelTestSupportRequestList() self._cancelTestSupportRequestList()
self.clearCache()
def test_ERP5Site_isSupportRequestCreationClosed(self): def test_ERP5Site_isSupportRequestCreationClosed(self):
...@@ -1891,14 +1892,6 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin): ...@@ -1891,14 +1892,6 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin):
@simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0') @simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0')
@simulate('SupportRequest_updateMonitoringComputerState',
"",
'return "Visited by SupportRequest_updateMonitoringComputerState ' \
'%s" % (context.getRelativeUrl(),)')
@simulate('SupportRequest_updateMonitoringHostingSubscriptionState',
"",
'return "Visited by SupportRequest_updateMonitoringHostingSubscriptionState '\
'%s" % (context.getRelativeUrl(),)')
@simulate('SupportRequest_updateMonitoringDestroyRequestedState', @simulate('SupportRequest_updateMonitoringDestroyRequestedState',
"", "",
'return "Visited by SupportRequest_updateMonitoringDestroyRequestedState '\ 'return "Visited by SupportRequest_updateMonitoringDestroyRequestedState '\
...@@ -1910,21 +1903,11 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin): ...@@ -1910,21 +1903,11 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin):
support_request.validate() support_request.validate()
self.assertEqual(None, self.assertEqual(None,
support_request.SupportRequest_updateMonitoringState()) support_request.SupportRequest_updateMonitoringState())
# Now try to go to set a computer...
support_request.setAggregateValue(self._makeComputer())
self.assertEqual(
"Visited by SupportRequest_updateMonitoringComputerState %s" % \
support_request.getRelativeUrl(),
support_request.SupportRequest_updateMonitoringState())
hs = self._makeHostingSubscription() hs = self._makeHostingSubscription()
support_request.setAggregateValue(hs) support_request.setAggregateValue(hs)
self.assertEqual(
"Visited by SupportRequest_updateMonitoringHostingSubscriptionState %s" %\
support_request.getRelativeUrl(),
support_request.SupportRequest_updateMonitoringState())
hs.getSlapState = getFakeSlapState hs.getSlapState = getFakeSlapState
self.assertEqual( self.assertEqual(
"Visited by SupportRequest_updateMonitoringDestroyRequestedState %s" %\ "Visited by SupportRequest_updateMonitoringDestroyRequestedState %s" %\
support_request.getRelativeUrl(), support_request.getRelativeUrl(),
...@@ -1934,69 +1917,7 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin): ...@@ -1934,69 +1917,7 @@ class TestSupportRequestUpdateMonitoringState(SlapOSTestCaseMixin):
self.assertEqual(None, self.assertEqual(None,
support_request.SupportRequest_updateMonitoringState()) support_request.SupportRequest_updateMonitoringState())
@simulate('SupportRequest_trySendNotificationMessage', @simulate('ERP5Site_isSupportRequestCreationClosed', '','return 0')
"message_title, message, source_relative_url",
'return "Visited by SupportRequest_trySendNotificationMessage '\
'%s %s %s" % (message_title, message, source_relative_url)')
def testSupportRequest_updateMonitoringComputerState(self):
support_request = self._makeSupportRequest()
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringComputerState())
support_request.validate()
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringComputerState())
support_request.setAggregateValue(self._makeHostingSubscription())
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringComputerState())
support_request.setAggregateValue(self._makeComputer())
memcached_dict = self.portal.portal_memcached.getMemcachedDict(
key_prefix='slap_tool',
plugin_path='portal_memcached/default_memcached_plugin')
memcached_dict[support_request.getAggregateValue().getReference()] = json.dumps({
"created_at": DateTime().strftime("%Y/%m/%d %H:%M")
})
# W/o destination decision the ticket is not notified.
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringComputerState())
support_request.setDestinationDecisionValue(self.makePerson(user=0))
expected_text = """Visited by SupportRequest_trySendNotificationMessage Computer is contacting again Suspending this ticket as the computer contacted again. %s""" % support_request.getDestinationDecision()
self.assertEqual(expected_text,
support_request.SupportRequest_updateMonitoringComputerState())
self.assertEqual(support_request.getSimulationState(), "suspended")
@simulate('SupportRequest_trySendNotificationMessage',
"message_title, message, source_relative_url",
'return "Visited by SupportRequest_trySendNotificationMessage '\
'%s %s %s" % (message_title, message, source_relative_url)')
def testSupportRequest_updateMonitoringHostingSubscriptionState(self):
support_request = self._makeSupportRequest()
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringHostingSubscriptionState())
support_request.validate()
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringHostingSubscriptionState())
support_request.setAggregateValue(self._makeComputer())
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringHostingSubscriptionState())
support_request.setAggregateValue(self._makeHostingSubscription())
self.assertEqual(None,
support_request.SupportRequest_updateMonitoringHostingSubscriptionState())
support_request.setDestinationDecisionValue(self.makePerson(user=0))
self.assertEqual("Visited by SupportRequest_trySendNotificationMessage Suspending this ticket as the problem is not present anymore Suspending this ticket as the problem is not present anymore. %s" % \
support_request.getDestinationDecision(),
support_request.SupportRequest_updateMonitoringHostingSubscriptionState())
self.assertEqual("suspended",
support_request.getSimulationState())
@simulate('SupportRequest_trySendNotificationMessage', @simulate('SupportRequest_trySendNotificationMessage',
"message_title, message, source_relative_url", "message_title, message, source_relative_url",
'return "Visited by SupportRequest_trySendNotificationMessage '\ 'return "Visited by SupportRequest_trySendNotificationMessage '\
......
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