##// END OF EJS Templates
fixes issue #658, my account edit was missing this functionality
marcink -
r3159:4910b260 beta
parent child Browse files
Show More
@@ -383,6 +383,17 b' class SettingsController(BaseController)'
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 """
@@ -391,21 +402,15 b' class SettingsController(BaseController)'
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
@@ -427,19 +432,25 b' class SettingsController(BaseController)'
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,
@@ -293,30 +293,6 b' class UserModel(BaseModel):'
293 log.error(traceback.format_exc())
293 log.error(traceback.format_exc())
294 raise
294 raise
295
295
296 def update_my_account(self, user_id, form_data):
297 from rhodecode.lib.auth import get_crypt_password
298 try:
299 user = self.get(user_id, cache=False)
300 if user.username == 'default':
301 raise DefaultUserException(
302 _("You can't Edit this user since it's"
303 " crucial for entire application")
304 )
305 for k, v in form_data.items():
306 if k == 'new_password' and v:
307 user.password = get_crypt_password(v)
308 user.api_key = generate_api_key(user.username)
309 else:
310 if k == 'firstname':
311 k = 'name'
312 if k not in ['admin', 'active']:
313 setattr(user, k, v)
314
315 self.sa.add(user)
316 except:
317 log.error(traceback.format_exc())
318 raise
319
320 def delete(self, user):
296 def delete(self, user):
321 user = self._get_user(user)
297 user = self._get_user(user)
322
298
@@ -26,7 +26,11 b''
26 <label for="username">${_('Username')}:</label>
26 <label for="username">${_('Username')}:</label>
27 </div>
27 </div>
28 <div class="input">
28 <div class="input">
29 ${h.text('username',class_="medium")}
29 %if c.ldap_dn:
30 ${h.text('username',class_='medium disabled', readonly="readonly")}
31 %else:
32 ${h.text('username',class_='medium')}
33 %endif:
30 </div>
34 </div>
31 </div>
35 </div>
32
36
@@ -10,10 +10,7 b' class TestJournalController(TestControll'
10 self.log_user()
10 self.log_user()
11 response = self.app.get(url(controller='journal', action='index'))
11 response = self.app.get(url(controller='journal', action='index'))
12
12
13 # Test response...
13 response.mustcontain("""<div class="journal_day">%s</div>""" % datetime.date.today())
14 assert """ <span id="follow_toggle_1" class="following" title="Stop following this repository""" in response.body, 'no info about stop follwoing repo id 1'
15
16 assert """<div class="journal_day">%s</div>""" % datetime.date.today() in response.body, 'no info about action journal day'
17
14
18 def test_stop_following_repository(self):
15 def test_stop_following_repository(self):
19 session = self.log_user()
16 session = self.log_user()
General Comments 0
You need to be logged in to leave comments. Login now