Mercurial > kallithea
comparison rhodecode/controllers/admin/settings.py @ 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 | 0226b6d6b2b5 |
children | cd50d1b5f35b 11b005b2d5e8 |
comparison
equal
deleted
inserted
replaced
3158:55ff0b9ef89e | 3159:4910b2607a29 |
---|---|
381 defaults={}, | 381 defaults={}, |
382 encoding="UTF-8", | 382 encoding="UTF-8", |
383 force_defaults=False | 383 force_defaults=False |
384 ) | 384 ) |
385 | 385 |
386 def _load_my_repos_data(self): | |
387 repos_list = Session().query(Repository)\ | |
388 .filter(Repository.user_id == | |
389 self.rhodecode_user.user_id)\ | |
390 .order_by(func.lower(Repository.repo_name)).all() | |
391 | |
392 repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list, | |
393 admin=True) | |
394 #json used to render the grid | |
395 return json.dumps(repos_data) | |
396 | |
386 @NotAnonymous() | 397 @NotAnonymous() |
387 def my_account(self): | 398 def my_account(self): |
388 """ | 399 """ |
389 GET /_admin/my_account Displays info about my account | 400 GET /_admin/my_account Displays info about my account |
390 """ | 401 """ |
391 # url('admin_settings_my_account') | 402 # url('admin_settings_my_account') |
392 | 403 |
393 c.user = User.get(self.rhodecode_user.user_id) | 404 c.user = User.get(self.rhodecode_user.user_id) |
405 c.ldap_dn = c.user.ldap_dn | |
394 | 406 |
395 if c.user.username == 'default': | 407 if c.user.username == 'default': |
396 h.flash(_("You can't edit this user since it's" | 408 h.flash(_("You can't edit this user since it's" |
397 " crucial for entire application"), category='warning') | 409 " crucial for entire application"), category='warning') |
398 return redirect(url('users')) | 410 return redirect(url('users')) |
399 | 411 |
400 repos_list = Session().query(Repository)\ | |
401 .filter(Repository.user_id == | |
402 self.rhodecode_user.user_id)\ | |
403 .order_by(func.lower(Repository.repo_name)).all() | |
404 | |
405 repos_data = RepoModel().get_repos_as_dict(repos_list=repos_list, | |
406 admin=True) | |
407 #json used to render the grid | 412 #json used to render the grid |
408 c.data = json.dumps(repos_data) | 413 c.data = self._load_my_repos_data() |
409 | 414 |
410 defaults = c.user.get_dict() | 415 defaults = c.user.get_dict() |
411 | 416 |
412 c.form = htmlfill.render( | 417 c.form = htmlfill.render( |
413 render('admin/users/user_edit_my_account_form.html'), | 418 render('admin/users/user_edit_my_account_form.html'), |
425 # Or using helpers: | 430 # Or using helpers: |
426 # h.form(url('admin_settings_my_account_update'), | 431 # h.form(url('admin_settings_my_account_update'), |
427 # method='put') | 432 # method='put') |
428 # url('admin_settings_my_account_update', id=ID) | 433 # url('admin_settings_my_account_update', id=ID) |
429 uid = self.rhodecode_user.user_id | 434 uid = self.rhodecode_user.user_id |
435 c.user = User.get(self.rhodecode_user.user_id) | |
436 c.ldap_dn = c.user.ldap_dn | |
430 email = self.rhodecode_user.email | 437 email = self.rhodecode_user.email |
431 _form = UserForm(edit=True, | 438 _form = UserForm(edit=True, |
432 old_data={'user_id': uid, 'email': email})() | 439 old_data={'user_id': uid, 'email': email})() |
433 form_result = {} | 440 form_result = {} |
434 try: | 441 try: |
435 form_result = _form.to_python(dict(request.POST)) | 442 form_result = _form.to_python(dict(request.POST)) |
436 UserModel().update_my_account(uid, form_result) | 443 skip_attrs = ['admin', 'active'] # skip attr for my account |
444 if c.ldap_dn: | |
445 #forbid updating username for ldap accounts | |
446 skip_attrs.append('username') | |
447 UserModel().update(uid, form_result, skip_attrs=skip_attrs) | |
437 h.flash(_('Your account was updated successfully'), | 448 h.flash(_('Your account was updated successfully'), |
438 category='success') | 449 category='success') |
439 Session().commit() | 450 Session().commit() |
440 except formencode.Invalid, errors: | 451 except formencode.Invalid, errors: |
441 c.user = User.get(self.rhodecode_user.user_id) | 452 #json used to render the grid |
442 | 453 c.data = self._load_my_repos_data() |
443 c.form = htmlfill.render( | 454 c.form = htmlfill.render( |
444 render('admin/users/user_edit_my_account_form.html'), | 455 render('admin/users/user_edit_my_account_form.html'), |
445 defaults=errors.value, | 456 defaults=errors.value, |
446 errors=errors.error_dict or {}, | 457 errors=errors.error_dict or {}, |
447 prefix_error=False, | 458 prefix_error=False, |