From 634dfe4d7f127faba7d840572013f632a825b236 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois-Xavier=20Algrain?= <fxalgrain@tiolive.com>
Date: Tue, 31 May 2011 11:28:24 +0200
Subject: [PATCH] Add test when create credential recovery

We should test the response before send submit the credential recovery.
Fix typo by using named parameters
---
 ...entialRequest_sendAcceptedNotification.xml |  2 +-
 .../ERP5Site_newCredentialRecovery.xml        | 36 +++++++++++++------
 bt5/erp5_credential/bt/revision               |  2 +-
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/CredentialRequest_sendAcceptedNotification.xml b/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/CredentialRequest_sendAcceptedNotification.xml
index 7ff7e96a55..49da12053a 100644
--- a/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/CredentialRequest_sendAcceptedNotification.xml
+++ b/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/CredentialRequest_sendAcceptedNotification.xml
@@ -68,7 +68,7 @@ if password:\n
 \n
 #Get message from catalog\n
 notification_reference = \'crendential_request-confirmation-%s\' % notification_type\n
-notification_message = context.NotificationTool_getDocumentValue(notification_reference, recipient.getLanguage())\n
+notification_message = context.NotificationTool_getDocumentValue(reference=notification_reference, language=recipient.getLanguage())\n
 if notification_message is None:\n
   raise ValueError, \'Unable to found Notification Message with reference "%s".\' % notification_reference\n
 \n
diff --git a/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/ERP5Site_newCredentialRecovery.xml b/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/ERP5Site_newCredentialRecovery.xml
index 6106279228..09cdcf782d 100644
--- a/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/ERP5Site_newCredentialRecovery.xml
+++ b/bt5/erp5_credential/SkinTemplateItem/portal_skins/erp5_credential/ERP5Site_newCredentialRecovery.xml
@@ -55,31 +55,47 @@
   Proxy : Manager proxy role is required to make possible for \n
 anonymous to create a new Credential Recovery\n
 \'\'\'\n
-\n
-person_module = context.getDefaultModule(\'Person\')\n
+portal = context.getPortalObject()\n
+person_module = portal.getDefaultModule(\'Person\')\n
 result = person_module.searchFolder(reference=reference)\n
 if len(result) != 1:\n
-  portal_status_message = context.Base_translateString("Can\'t find corresponding person, it\'s not possible to update your credentials.")\n
+  portal_status_message = portal.Base_translateString("Can\'t find corresponding person, it\'s not possible to update your credentials.")\n
   return context.Base_redirect(\'\', keep_items = dict(portal_status_message=portal_status_message ))\n
 \n
 person = result[0].getObject()\n
-# create the credential recovery\n
-module = context.getDefaultModule(portal_type=\'Credential Recovery\')\n
-credential_recovery = module.newContent(\n
+\n
+# Check the response\n
+question_free_text = person.getDefaultCredentialQuestionQuestionFreeText()\n
+question_title = person.getDefaultCredentialQuestionQuestionTitle()\n
+question_answer = person.getDefaultCredentialQuestionAnswer().lower()\n
+answer = default_credential_question_answer and default_credential_question_answer.lower() or \'\'\n
+\n
+if (question_title or question_title) and (answer == question_answer):\n
+  # create the credential recovery\n
+  module = portal.getDefaultModule(portal_type=\'Credential Recovery\')\n
+  credential_recovery = module.newContent(\n
 \t\tportal_type="Credential Recovery",\n
                 reference=reference,\n
                 default_credential_question_answer=default_credential_question_answer,\n
                 destination_decision=person.getRelativeUrl(),\n
                 language=portal.Localizer.get_selected_language())\n
-credential_recovery.submit()\n
+  credential_recovery.submit()\n
+  message = "Credential Recovery Created."\n
+  keep_items = {}\n
+  dialog_id = \'login_form\'\n
+else:\n
+  message = "You didn\'t enter the correct answer."\n
+  keep_items = {\'default_credential_question_question_free_text\': question_free_text,\n
+                \'default_credential_question_question_title\': question_title,\n
+                \'reference\': reference}\n
 \n
-portal_status_message = context.Base_translateString("Credential Recovery Created.")\n
-return context.Base_redirect(\'login_form\', keep_items = dict(portal_status_message=portal_status_message ))\n
+keep_items[\'portal_status_message\'] = portal.Base_translateString(message)\n
+return context.Base_redirect(dialog_id, keep_items = keep_items)\n
 </string> </value>
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>reference=None, default_credential_question_answer=None, **kw</string> </value>
+            <value> <string>reference=None, default_credential_question_answer=None, dialog_id=None, **kw</string> </value>
         </item>
         <item>
             <key> <string>_proxy_roles</string> </key>
diff --git a/bt5/erp5_credential/bt/revision b/bt5/erp5_credential/bt/revision
index 8db9866c84..4f37670799 100644
--- a/bt5/erp5_credential/bt/revision
+++ b/bt5/erp5_credential/bt/revision
@@ -1 +1 @@
-332
\ No newline at end of file
+333
\ No newline at end of file
-- 
2.30.9