Commit 0c25cfac authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Set empty Start/Stop dates for assignments

See merge request !408
parents afda535e ed97d47d
# Send an email for the user with a URL, so he can set the password.
from Products.ERP5Type.Errors import UnsupportedWorkflowMethod
portal = context.getPortalObject()
portal_preferences = portal.portal_preferences
reference = None
password = None
......@@ -21,12 +17,6 @@ role_list = ['member', 'subscriber']
open_assignment_list = person.searchFolder(portal_type="Assignment",
validation_state="open")
# Initialisation
assignment_duration = portal_preferences.getPreferredCredentialAssignmentDuration()
today = DateTime()
delay = today+assignment_duration
current_assignment_list = {}
for assignment in open_assignment_list:
role = assignment.getRole()
......@@ -37,21 +27,23 @@ for assignment in open_assignment_list:
for role in role_list:
if role in current_assignment_list:
#Update assignment
# Update assignment (Reset stop/start dates)
for assignment in current_assignment_list[role]:
assignment.update()
assignment.edit(stop_date=delay)
assignment.open()
if assignment.getStartDate() is None or \
assignment.getStopDate() is None:
assignment.update()
assignment.edit(stop_date=None,
start_date=None)
assignment.open(
comment="Start and Stop reset by Subscription Request")
else:
#Create assignment
# Create assignment
assignment = person.newContent(
portal_type='Assignment',
title = '%s Assignment' % (role.capitalize()),
role = role,
start_date = today - 1,
stop_date = delay)
role = role)
assignment.open()
assignment.open(comment="Created by Subscription Request")
login_list = [x for x in person.objectValues(portal_type=['ERP5 Login', 'Google Login', 'Facebook Login']) \
if x.getValidationState() == 'validated']
......@@ -68,7 +60,7 @@ if not open_assignment_list and person.getUserId() == login_list[0].getReference
# Update password of the user
password = person.Person_generatePassword()
login.setPassword(password)
login.validate()
login.validate(comment="Updated by Subscription Request")
# Update Roles and Title
try:
......@@ -79,9 +71,9 @@ except UnsupportedWorkflowMethod:
person.edit(default_career_role_list=role_list)
default_career = getattr(person,'default_career',None)
#Try to validate the default career
# Try to validate the default career
try:
default_career.start()
default_career.start(comment="Started by Subscription Request")
default_career.setStartDate(DateTime())
except UnsupportedWorkflowMethod:
pass
......
......@@ -410,15 +410,10 @@ assert password""")
subscriber_role = [i for i in open_assignment_list if i.getRole() == 'subscriber'][0]
member_role = [i for i in open_assignment_list if i.getRole() == 'member'][0]
self.assertNotEqual(subscriber_role.getStartDate(), None)
self.assertNotEqual(member_role.getStopDate(), None)
self.assertNotEqual(subscriber_role.getStartDate(), None)
self.assertNotEqual(member_role.getStopDate(), None)
self.assertTrue(subscriber_role.getStartDate() < DateTime())
self.assertTrue(member_role.getStopDate() > DateTime() + 365*5)
self.assertTrue(subscriber_role.getStartDate() < DateTime())
self.assertTrue(member_role.getStopDate() > DateTime() + 365*5)
self.assertEqual(subscriber_role.getStartDate(), None)
self.assertEqual(member_role.getStopDate(), None)
self.assertEqual(subscriber_role.getStartDate(), None)
self.assertEqual(member_role.getStopDate(), None)
login_list = person.searchFolder(portal_type='ERP5 Login', validation_state="validated")
self.assertEqual(len(login_list), 1)
......
......@@ -6,12 +6,6 @@
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testSlapOSSubscriptionSkins</string> </value>
......@@ -55,28 +49,13 @@
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
......@@ -89,7 +68,7 @@
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
......@@ -98,7 +77,7 @@
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
......
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