Commit 246d37c8 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_trial: Send and store Mail Messages when it is sent.

parent a31fd79b
...@@ -4,9 +4,8 @@ person = portal.portal_catalog.getResultValue( ...@@ -4,9 +4,8 @@ person = portal.portal_catalog.getResultValue(
portal_type="Person", portal_type="Person",
reference="free_trial_user") reference="free_trial_user")
if context.getStopDate() >= DateTime(): if context.getStopDate() >= DateTime():
return return
if person is None: if person is None:
return return
...@@ -18,21 +17,34 @@ if context.getValidationState() != "validated": ...@@ -18,21 +17,34 @@ if context.getValidationState() != "validated":
return return
state = "destroyed" state = "destroyed"
shared = False
hosting_subscription = context.getSpecialiseValue()
request_kw = {} request_kw = {}
request_kw.update( request_kw.update(
software_release=context.getUrlString(), software_release=hosting_subscription.getUrlString(),
software_title=context.getTitle(), software_title=hosting_subscription.getTitle(),
software_type="RootSoftwareInstance", software_type=hosting_subscription.getSourceReference(),
instance_xml=context.getTextContent(), instance_xml=hosting_subscription.getTextContent(),
sla_xml="", sla_xml="",
shared=shared, shared=hosting_subscription.getRootSlave(),
state=state, state=state,
) )
person.requestSoftwareInstance(**request_kw) person.requestSoftwareInstance(**request_kw)
context.invalidate()
return connection_dict = hosting_subscription.getPredecessorValue().getConnectionXmlAsDict()
connection_key_list = context.getSubjectList()
connection_string = '\n'.join(['%s: %s' % (x,y) for x,y in connection_dict.items() if x in connection_key_list])
mapping_dict = {"token": connection_string }
context.TrialRequest_sendMailMessage(person,
context.getDefaultEmailText(),
'slapos-free.trial.destroy',
mapping_dict)
context.invalidate()
...@@ -10,18 +10,13 @@ if person is None: ...@@ -10,18 +10,13 @@ if person is None:
return "Free Trial Person not Found" return "Free Trial Person not Found"
connection_key_list = context.getSubjectList() connection_key_list = context.getSubjectList()
instance = context.getAggregateValue() instance = context.getAggregateValue()
email = context.getDefaultEmailText()
connection_dict = instance.getConnectionXmlAsDict()
state = instance.getSlapState()
if context.getValidationState() in ["validated", "invalidated"]: if context.getValidationState() in ["validated", "invalidated"]:
return "Already Valid Skip" return
if state != "destroy_requested": if instance.getSlapState() != "destroy_requested":
connection_dict = instance.getConnectionXmlAsDict()
if connection_dict: if connection_dict:
if len([ x for x, y in connection_dict.items() if x in connection_key_list]) != len(connection_key_list): if len([ x for x, y in connection_dict.items() if x in connection_key_list]) != len(connection_key_list):
...@@ -31,50 +26,14 @@ if state != "destroy_requested": ...@@ -31,50 +26,14 @@ if state != "destroy_requested":
if x in connection_key_list and y in ['None', None, 'http://', '']: if x in connection_key_list and y in ['None', None, 'http://', '']:
return "key %s has invalid value %s" % (x, y) return "key %s has invalid value %s" % (x, y)
connection_string = '\n'.join(['%s: %s' % (x,y) for x,y in connection_dict.items() if x in connection_key_list]) connection_string = '\n'.join(
['%s: %s' % (x,y) for x,y in connection_dict.items() if x in connection_key_list])
notification_message_reference = 'slapos-free.trial.token'
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_message_reference)
subject = notification_message.getTitle()
mapping_dict = {"token": connection_string } mapping_dict = {"token": connection_string }
message = message = notification_message.asText( context.TrialRequest_sendMailMessage(person,
substitution_method_parameter_dict={'mapping_dict': mapping_dict}) context.getDefaultEmailText(),
'slapos-free.trial.token',
person_title = "%s FREE TRIAL" % email mapping_dict)
free_trial_destination = portal.portal_catalog.getResultValue(
portal_type="Person",
title=person_title,
reference=None)
if free_trial_destination is None:
free_trial_destination = portal.person_module.newContent(
portal_type="Person",
title=person_title)
free_trial_destination.setDefaultEmailText(email)
event = portal.event_module.newContent(
portal_type="Mail Message",
start_date=DateTime(),
destination=free_trial_destination.getRelativeUrl(),
follow_up=context.getRelativeUrl(),
source=person.getRelativeUrl(),
title=subject,
resource="service_module/slapos_crm_information",
text_content=message,
)
portal.portal_workflow.doActionFor(event, 'start_action', send_mail=True)
event.stop()
event.deliver()
event.reindexObject()
context.validate() context.validate()
portal = context.getPortalObject()
notification_message = portal.portal_notifications.getDocumentValue(
reference=notification_message_reference)
subject = notification_message.getTitle()
message = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict': mapping_dict})
person_title = "%s FREE TRIAL" % email
free_trial_destination = portal.portal_catalog.getResultValue(
portal_type="Person",
title=person_title,
reference=None)
if free_trial_destination is None:
free_trial_destination = portal.person_module.newContent(
portal_type="Person",
title=person_title)
free_trial_destination.setDefaultEmailText(email)
event = portal.event_module.newContent(
portal_type="Mail Message",
start_date=DateTime(),
destination=free_trial_destination.getRelativeUrl(),
follow_up=context.getRelativeUrl(),
source=sender.getRelativeUrl(),
title=subject,
resource="service_module/slapos_crm_information",
text_content=message,
)
portal.portal_workflow.doActionFor(event, 'start_action', send_mail=True)
event.stop()
event.deliver()
event.reindexObject()
return event
<?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>sender, email, notification_message_reference, mapping_dict</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>TrialRequest_sendMailMessage</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
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