diff --git a/rhodecode/controllers/admin/settings.py b/rhodecode/controllers/admin/settings.py --- a/rhodecode/controllers/admin/settings.py +++ b/rhodecode/controllers/admin/settings.py @@ -383,6 +383,17 @@ class SettingsController(BaseController) 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 @@ class SettingsController(BaseController) # 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 @@ class SettingsController(BaseController) # 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, diff --git a/rhodecode/model/user.py b/rhodecode/model/user.py --- a/rhodecode/model/user.py +++ b/rhodecode/model/user.py @@ -293,30 +293,6 @@ class UserModel(BaseModel): 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) diff --git a/rhodecode/templates/admin/users/user_edit_my_account_form.html b/rhodecode/templates/admin/users/user_edit_my_account_form.html --- a/rhodecode/templates/admin/users/user_edit_my_account_form.html +++ b/rhodecode/templates/admin/users/user_edit_my_account_form.html @@ -26,7 +26,11 @@