Commit ab66c0c0 authored by Rafael Monnerat's avatar Rafael Monnerat

slapos_subscription_request: A valid Assignment is required to be a valid user.

See merge request nexedi/slapos.core!508
parents b8011d42 5bf0d22b
......@@ -53,7 +53,7 @@ if not login_list:
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():
if "%s-FIRST-SUBSCRIBER-LOGIN" % person.getUserId() == login_list[0].getReference():
login.invalidate()
login.setReference(person.getDefaultEmailText())
reference = person.getDefaultEmailText()
......
......@@ -14,7 +14,6 @@ if person is not None:
# Already has login with this.
person = context.SubscriptionRequest_searchExistingUserByEmail(email)
if person is not None:
return person, False
......@@ -23,20 +22,19 @@ person = portal.person_module.newContent(
portal_type="Person",
first_name=name)
password = [random.choice(string.upper(string.ascii_letters)),
random.choice(string.lower(string.ascii_letters)),
random.choice(string.digits),
random.choice("$!*#%$.;:,")]
chars = string.ascii_letters + string.digits + '!@#$%^&*()'
password.extend([random.choice(chars) for _ in range(26)])
for role in ['member', 'subscriber']:
person.newContent(
portal_type='Assignment',
title = '%s Assignment' % (role.capitalize()),
role = role).open(comment="Created by Subscription Request")
password = list("".join([context.Person_generatePassword(15, 5, 4) for _ in range(random.randint(2, 4))]))
random.shuffle(password)
login = person.newContent(
portal_type="ERP5 Login",
reference=person.getUserId(),
password=''.join(password))
reference="%s-FIRST-SUBSCRIBER-LOGIN" % person.getUserId(),
password="".join(password))
login.validate()
......
......@@ -294,7 +294,7 @@ class TestSubscriptionRequest_createUser(TestSubscriptionSkinsMixin):
erp5_login = [i for i in person.searchFolder(portal_type="ERP5 Login")][0]
self.assertEqual(person.getValidationState(), "draft")
self.assertEqual(erp5_login.getValidationState(), "validated")
self.assertEqual(erp5_login.getReference(), person.getUserId())
self.assertEqual(erp5_login.getReference(), person.getUserId() + "-FIRST-SUBSCRIBER-LOGIN")
class Test0SubscriptionRequestModule_requestSubscriptionProxy(TestSubscriptionSkinsMixin):
......@@ -388,7 +388,8 @@ class TestSubscriptionRequest_applyCondition(TestSubscriptionSkinsMixin):
class SubscriptionRequest_boostrapUserAccount(TestSubscriptionSkinsMixin):
@simulate('SubscriptionRequest_sendAcceptedNotification', 'reference, password',"""assert reference == context.getDefaultEmailText()
@simulate('SubscriptionRequest_sendAcceptedNotification', 'reference, password',"""
assert reference == context.getDefaultEmailText(), "%s != %s" % (reference, context.getDefaultEmailText())
assert password""")
def test_bootstrap_user(self):
email = "abc%s@nexedi.com" % self.new_id
......@@ -405,7 +406,7 @@ assert password""")
subscription_request.plan()
self.assertEqual(len(person.searchFolder(portal_type="Assignment",
validation_state="open")), 0)
validation_state="open")), 2)
subscription_request.SubscriptionRequest_boostrapUserAccount()
......@@ -430,7 +431,7 @@ assert password""")
erp5_login = login_list[0]
self.assertEqual(erp5_login.getReference(), email)
self.assertNotEqual(erp5_login.getPassword(), None)
self.assertNotEqual(erp5_login.getPassword(), None)
self.assertNotEqual(erp5_login.getPassword(), "")
self.assertEqual(erp5_login.getValidationState(), "validated")
......@@ -795,7 +796,7 @@ class TestSubscriptionRequest_sendAcceptedNotification(TestSubscriptionSkinsMixi
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(
event.getTextContent(),'%s %s' % (person.getTitle(), person.getUserId()))
event.getTextContent(),'%s %s-FIRST-SUBSCRIBER-LOGIN' % (person.getTitle(), person.getUserId()))
def test_send_notification_with_password(self):
......@@ -824,7 +825,7 @@ class TestSubscriptionRequest_sendAcceptedNotification(TestSubscriptionSkinsMixi
self.assertEqual(event.getContentType(),'text/html')
self.assertEqual(
event.getTextContent(),'%s %s password' % (person.getTitle(), person.getUserId()))
event.getTextContent(),'%s %s password' % (person.getTitle(), person.getUserId() + "-FIRST-SUBSCRIBER-LOGIN"))
class TestSubscriptionRequest_notifyInstanceIsReady(TestSubscriptionSkinsMixin):
......
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