Commit eb785c81 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Add alarm to bootstrap user and notify him.

parent 78bb5c00
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Alarm" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>active_sense_method_id</string> </key>
<value> <string>Alarm_processPlannedSubscriptionRequest</string> </value>
</item>
<item>
<key> <string>automatic_solve</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>enabled</string> </key>
<value> <int>1</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>slapos_subscription_request_process_planned</string> </value>
</item>
<item>
<key> <string>periodicity_hour</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_minute_frequency</string> </key>
<value> <int>10</int> </value>
</item>
<item>
<key> <string>periodicity_month</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_month_day</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>periodicity_start_date</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1357002060.0</float>
<string>GMT</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>periodicity_week</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Alarm</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Process Planned Subscription Requests</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
from DateTime import DateTime
portal = context.getPortalObject()
portal.portal_catalog.searchAndActivate(
portal_type="Subscription Request",
simulation_state="planned",
method_id="SubscriptionRequest_boostrapUserAccount",
activity_kw={tag: tag}
)
context.activate(after_tag=tag).getId()
<?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>tag, fixit, params</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Alarm_processPlannedSubscriptionRequest</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
# Update update user information, by creating
# - creating one cloud contract
# Send an email for the user with a URL, so he can set the password.
# Create conpensation payment for future payment, and attach to the subscription request
# Person_findPartition must check if Subscription Request is on confirmed state to allocate.
from Products.ERP5Type.Errors import UnsupportedWorkflowMethod
portal = context.getPortalObject()
portal_preferences = context.portal_preferences
reference = None
password = None
person = context.getDestinationSectionValue(portal_type="Person")
# Should come from subscription condition probably or preference
role_list = ['member', 'subscriber']
open_assignment_list = person.searchFolder(portal_type="Assignment",
validation_state="open")
#Initialisation
assignment_duration = context.portal_preferences.getPreferredCredentialAssignmentDuration()
today = DateTime()
delay = today+assignment_duration
current_assignment_list = {}
for assignment in open_assignment_list:
role = assignment.getRole()
if role in current_assignment_list:
current_assignment_list[role].append(assignment)
else:
current_assignment_list[role] = [assignment]
for role in role_list:
if role in current_assignment_list:
#Update assignment
for assignment in current_assignment_list[role]:
assignment.update()
assignment.edit(stop_date=delay)
assignment.open()
else:
#Create assignment
assignment = person.newContent(
portal_type='Assignment',
title = '%s Assignment' % (role.capitalize()),
role = role,
start_date = today - 1,
stop_date = delay)
assignment.open()
login_list = [x for x in person.objectValues(portal_type='ERP5 Login') \
if x.getValidationState() == 'validated']
if not login_list:
raise ValueError('Something is wrong')
login = login_list[0]
# Let's reset password if the user is his first login.
if not open_assignment_list and person.getUserId() == login_list[0].getReference():
login.invalidate()
login.setReference(person.getDefaultEmailText())
reference = person.getDefaultEmailText()
# Update password of the user
password = person.Person_generatePassword(alpha=5, numeric=3)
login.setPassword(password)
login.validate()
# Update Roles and Title
try:
person.validate()
except UnsupportedWorkflowMethod:
pass
person.edit(default_career_role_list=role_list)
default_career = getattr(person,'default_career',None)
#Try to validate the default career
try:
default_career.start()
default_career.setStartDate(DateTime())
except UnsupportedWorkflowMethod:
pass
context.activate(activity='SQLQueue').SubscriptionRequest_sendAcceptedNotification(reference, password)
context.order()
<?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>SubscriptionRequest_boostrapUserAccount</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
portal = context.getPortalObject()
recipient = context.getDestinationSectionValue(portal_type="Person")
#Define the type of notification
notification_type = "without-password"
if password:
notification_type = "with-password"
#Get message from catalog
notification_reference = 'subscription_request-confirmation-%s' % notification_type
notification_message = portal.portal_notifications.getDocumentValue(reference=notification_reference,
language=recipient.getLanguage())
if notification_message is None:
raise ValueError, 'Unable to found Notification Message with reference "%s".' % notification_reference
#Set notification mapping
notification_mapping_dict = {'login_name': reference}
if password:
notification_mapping_dict.update(
{'login_password' : password})
#Preserve HTML else convert to text
if notification_message.getContentType() == "text/html":
mail_text = notification_message.asEntireHTML(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
else:
mail_text = notification_message.asText(
substitution_method_parameter_dict={'mapping_dict':notification_mapping_dict})
#Send email
portal.portal_notifications.sendMessage(
sender=None,
recipient=recipient,
subject=notification_message.getTitle(),
message=mail_text,
message_text_format=notification_message.getContentType(),
notifier_list=(portal.portal_preferences.getPreferredLoginAndPasswordNotifier(),),
store_as_event= portal.portal_preferences.isPreferredStoreEvents(),
event_keyword_argument_dict={'follow_up':context.getRelativeUrl()},
)
<?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>reference, password</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SubscriptionRequest_sendAcceptedNotification</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