diff roundup/roundupdb.py @ 5976:71c68961d9f4

- issue2550920 - Optionally detect duplicate username at registration. Added config option to allow detection of duplicate username when the user tries to register. Previously user was rejected when dupliate name found at confirmation step. Optional as it can make username guessing easier. Testing is in place for this. Also attempted to make the unfriendly error message: 'node with key "username" exists' into a translatable friendly error: "Username 'username' already exists." This is missing any test. It is also fragile as I capture the ValueError exception and see that the exception matches: 'node with key "username" exists' If it does reassert the friendly message. Otherwise just re-raise existing exception. If the "node with key..." message is translated the friendly override will not trigger.
author John Rouillard <rouilj@ieee.org>
date Sat, 09 Nov 2019 16:33:42 -0500
parents 11a9c5b2efd4
children 2b53c310089f
line wrap: on
line diff
--- a/roundup/roundupdb.py	Sat Nov 09 00:41:53 2019 -0500
+++ b/roundup/roundupdb.py	Sat Nov 09 16:33:42 2019 -0500
@@ -119,8 +119,24 @@
         cl = self.user
 
         props['roles'] = self.config.NEW_WEB_USER_ROLES
-        userid = cl.create(**props)
-        # clear the props from the otk database
+        try:
+            # ASSUME:: ValueError raised during create due to key value
+            # conflict. I an use message in exception to determine
+            # when I should intercept the exception with a more
+            # friendly error message. If i18n is used to translate
+            # original exception message this will fail and translated
+            # text (probably unfriendly) will be used.
+            userid = cl.create(**props)
+        except ValueError as e:
+            username = props['username']
+            # Try to make error message less cryptic to the user.
+            if str(e) == 'node with key "%s" exists' % username:
+                raise ValueError(
+                    _("Username '%s' already exists."%username))
+            else:
+                raise
+
+            # clear the props from the otk database
         self.getOTKManager().destroy(otk)
         # commit cl.create (and otk changes)
         self.commit()

Roundup Issue Tracker: http://roundup-tracker.org/