diff rhodecode/model/user.py @ 2657:001c7e2ae986 beta

fixed api issue with changing username during update_user
author Marcin Kuzminski <marcin@python-works.com>
date Wed, 25 Jul 2012 00:38:05 +0200
parents 6ce3387bf0ce
children d2d35cf2b351
line wrap: on
line diff
--- a/rhodecode/model/user.py	Tue Jul 24 22:15:47 2012 +0200
+++ b/rhodecode/model/user.py	Wed Jul 25 00:38:05 2012 +0200
@@ -278,6 +278,28 @@
             log.error(traceback.format_exc())
             raise
 
+    def update_user(self, user, **kwargs):
+        from rhodecode.lib.auth import get_crypt_password
+        try:
+            user = self._get_user(user)
+            if user.username == 'default':
+                raise DefaultUserException(
+                    _("You can't Edit this user since it's"
+                      " crucial for entire application")
+                )
+
+            for k, v in kwargs.items():
+                if k == 'password' and v:
+                    v = get_crypt_password(v)
+                    user.api_key = generate_api_key(user.username)
+
+                setattr(user, k, v)
+            self.sa.add(user)
+            return user
+        except:
+            log.error(traceback.format_exc())
+            raise
+
     def update_my_account(self, user_id, form_data):
         from rhodecode.lib.auth import get_crypt_password
         try: