changeset 3159:4910b2607a29 beta

fixes issue #658, my account edit was missing this functionality
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 10 Jan 2013 23:09:17 +0100
parents 55ff0b9ef89e
children 5d7f6b22d6b4
files rhodecode/controllers/admin/settings.py rhodecode/model/user.py rhodecode/templates/admin/users/user_edit_my_account_form.html rhodecode/tests/functional/test_journal.py
diffstat 4 files changed, 28 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/controllers/admin/settings.py	Thu Jan 10 20:39:22 2013 +0100
+++ b/rhodecode/controllers/admin/settings.py	Thu Jan 10 23:09:17 2013 +0100
@@ -383,6 +383,17 @@
             force_defaults=False
         )
 
+    def _load_my_repos_data(self):
+        repos_list = Session().query(Repository)\
+                     .filter(Repository.user_id ==
+                             self.rhodecode_user.user_id)\
+                     .order_by(func.lower(Repository.repo_name)).all()
+
+        repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list,
+                                                   admin=True)
+        #json used to render the grid
+        return json.dumps(repos_data)
+
     @NotAnonymous()
     def my_account(self):
         """
@@ -391,21 +402,15 @@
         # url('admin_settings_my_account')
 
         c.user = User.get(self.rhodecode_user.user_id)
+        c.ldap_dn = c.user.ldap_dn
 
         if c.user.username == 'default':
             h.flash(_("You can't edit this user since it's"
               " crucial for entire application"), category='warning')
             return redirect(url('users'))
 
-        repos_list = Session().query(Repository)\
-                     .filter(Repository.user_id ==
-                             self.rhodecode_user.user_id)\
-                     .order_by(func.lower(Repository.repo_name)).all()
-
-        repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list,
-                                                   admin=True)
         #json used to render the grid
-        c.data = json.dumps(repos_data)
+        c.data = self._load_my_repos_data()
 
         defaults = c.user.get_dict()
 
@@ -427,19 +432,25 @@
         #           method='put')
         # url('admin_settings_my_account_update', id=ID)
         uid = self.rhodecode_user.user_id
+        c.user = User.get(self.rhodecode_user.user_id)
+        c.ldap_dn = c.user.ldap_dn
         email = self.rhodecode_user.email
         _form = UserForm(edit=True,
                          old_data={'user_id': uid, 'email': email})()
         form_result = {}
         try:
             form_result = _form.to_python(dict(request.POST))
-            UserModel().update_my_account(uid, form_result)
+            skip_attrs = ['admin', 'active']  # skip attr for my account
+            if c.ldap_dn:
+                #forbid updating username for ldap accounts
+                skip_attrs.append('username')
+            UserModel().update(uid, form_result, skip_attrs=skip_attrs)
             h.flash(_('Your account was updated successfully'),
                     category='success')
             Session().commit()
         except formencode.Invalid, errors:
-            c.user = User.get(self.rhodecode_user.user_id)
-
+            #json used to render the grid
+            c.data = self._load_my_repos_data()
             c.form = htmlfill.render(
                 render('admin/users/user_edit_my_account_form.html'),
                 defaults=errors.value,
--- a/rhodecode/model/user.py	Thu Jan 10 20:39:22 2013 +0100
+++ b/rhodecode/model/user.py	Thu Jan 10 23:09:17 2013 +0100
@@ -293,30 +293,6 @@
             log.error(traceback.format_exc())
             raise
 
-    def update_my_account(self, user_id, form_data):
-        from rhodecode.lib.auth import get_crypt_password
-        try:
-            user = self.get(user_id, cache=False)
-            if user.username == 'default':
-                raise DefaultUserException(
-                    _("You can't Edit this user since it's"
-                      " crucial for entire application")
-                )
-            for k, v in form_data.items():
-                if k == 'new_password' and v:
-                    user.password = get_crypt_password(v)
-                    user.api_key = generate_api_key(user.username)
-                else:
-                    if k == 'firstname':
-                        k = 'name'
-                    if k not in ['admin', 'active']:
-                        setattr(user, k, v)
-
-            self.sa.add(user)
-        except:
-            log.error(traceback.format_exc())
-            raise
-
     def delete(self, user):
         user = self._get_user(user)
 
--- a/rhodecode/templates/admin/users/user_edit_my_account_form.html	Thu Jan 10 20:39:22 2013 +0100
+++ b/rhodecode/templates/admin/users/user_edit_my_account_form.html	Thu Jan 10 23:09:17 2013 +0100
@@ -26,7 +26,11 @@
                         <label for="username">${_('Username')}:</label>
                     </div>
                     <div class="input">
-                        ${h.text('username',class_="medium")}
+                      %if c.ldap_dn:
+                          ${h.text('username',class_='medium disabled', readonly="readonly")}
+                      %else:
+                          ${h.text('username',class_='medium')}
+                      %endif:
                     </div>
                  </div>
 
--- a/rhodecode/tests/functional/test_journal.py	Thu Jan 10 20:39:22 2013 +0100
+++ b/rhodecode/tests/functional/test_journal.py	Thu Jan 10 23:09:17 2013 +0100
@@ -10,10 +10,7 @@
         self.log_user()
         response = self.app.get(url(controller='journal', action='index'))
 
-        # Test response...
-        assert """ <span id="follow_toggle_1" class="following" title="Stop following this repository""" in response.body, 'no info about stop follwoing repo id 1'
-
-        assert """<div class="journal_day">%s</div>""" % datetime.date.today() in response.body, 'no info about action journal day'
+        response.mustcontain("""<div class="journal_day">%s</div>""" % datetime.date.today())
 
     def test_stop_following_repository(self):
         session = self.log_user()