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