[Checkins] SVN: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py In update(Own)LoginName require a success by at least one plugin.

Maurits van Rees cvs-admin at zope.org
Fri Jan 11 12:53:02 UTC 2013


Log message for revision 129035:
  In update(Own)LoginName require a success by at least one plugin.

Changed:
  U   Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py

-=-
Modified: Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py
===================================================================
--- Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py	2013-01-10 17:36:25 UTC (rev 129034)
+++ Products.PluggableAuthService/branches/maurits-login-transform/Products/PluggableAuthService/PluggableAuthService.py	2013-01-11 12:53:01 UTC (rev 129035)
@@ -1275,6 +1275,11 @@
         plugins = self._getOb('plugins')
         updaters = plugins.listPlugins(IUpdateLoginNamePlugin)
 
+        # Call the updaters.  One of them *must* succeed without an
+        # exception, even if it does not change anything.  When a
+        # login name is already taken, we do not want to fail
+        # silently.
+        success = False
         for updater_id, updater in updaters:
             try:
                 updater.updateUser(user_id, login_name)
@@ -1282,7 +1287,13 @@
                 reraise(updater)
                 logger.debug('UpdateLoginNamePlugin %s error' % updater_id,
                              exc_info=True)
+            else:
+                success = True
 
+        if not success:
+            raise ValueError("Cannot update login name of user %r to %r. "
+                             "Possibly duplicate." % (user_id, login_name))
+
     security.declarePublic('updateOwnLoginName')
     def updateOwnLoginName(self, login_name):
         """Update own login name of authenticated user.
@@ -1299,6 +1310,12 @@
         plugins = self._getOb('plugins')
         updaters = plugins.listPlugins(IUpdateLoginNamePlugin)
         logger.info('UpdateLoginNamePlugins: %r', updaters)
+
+        # Call the updaters.  One of them *must* succeed without an
+        # exception, even if it does not change anything.  When a
+        # login name is already taken, we do not want to fail
+        # silently.
+        success = False
         for updater_id, updater in updaters:
             try:
                 updater.updateUser(user_id, login_name)
@@ -1307,8 +1324,13 @@
                 logger.debug('UpdateLoginNamePlugin %s error' % updater_id,
                              exc_info=True)
             else:
+                success = True
                 logger.info("login name changed to: %r", login_name)
 
+        if not success:
+            raise ValueError("Cannot update own login name of user %r to %r. "
+                             "Possibly duplicate." % (user_id, login_name))
+
     security.declareProtected( ManageUsers, 'updateLoginName')
     def updateAllLoginNames(self, quit_on_first_error=True):
         """Update login names of all users to their canonical value.



More information about the checkins mailing list