Commit ed97d47d authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: Set empty Start/Stop dates for assignments

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