comparison rhodecode/model/user.py @ 713:1bb0fcdec895 beta

fixed #72 show warning on removal when user still is owner of existing repositories cleaned up exceptions
author Marcin Kuzminski <marcin@python-works.com>
date Thu, 18 Nov 2010 03:29:23 +0100
parents 9e9f1b919c0c
children 1377a9d4bdb9
comparison
equal deleted inserted replaced
712:131c1e335fa7 713:1bb0fcdec895
25 25
26 from pylons.i18n.translation import _ 26 from pylons.i18n.translation import _
27 from rhodecode.model.caching_query import FromCache 27 from rhodecode.model.caching_query import FromCache
28 from rhodecode.model.db import User 28 from rhodecode.model.db import User
29 from rhodecode.model.meta import Session 29 from rhodecode.model.meta import Session
30 from rhodecode.lib.exceptions import *
30 import logging 31 import logging
31 import traceback 32 import traceback
32 33
33 log = logging.getLogger(__name__) 34 log = logging.getLogger(__name__)
34 35
35 class DefaultUserException(Exception):pass 36
36 37
37 class UserModel(object): 38 class UserModel(object):
38 39
39 def __init__(self): 40 def __init__(self):
40 self.sa = Session() 41 self.sa = Session()
126 new_user = self.get(user_id, cache=False) 127 new_user = self.get(user_id, cache=False)
127 if new_user.username == 'default': 128 if new_user.username == 'default':
128 raise DefaultUserException( 129 raise DefaultUserException(
129 _("You can't Edit this user since it's" 130 _("You can't Edit this user since it's"
130 " crucial for entire application")) 131 " crucial for entire application"))
132
131 for k, v in form_data.items(): 133 for k, v in form_data.items():
132 if k == 'new_password' and v != '': 134 if k == 'new_password' and v != '':
133 new_user.password = v 135 new_user.password = v
134 else: 136 else:
135 setattr(new_user, k, v) 137 setattr(new_user, k, v)
167 user = self.get(user_id, cache=False) 169 user = self.get(user_id, cache=False)
168 if user.username == 'default': 170 if user.username == 'default':
169 raise DefaultUserException( 171 raise DefaultUserException(
170 _("You can't remove this user since it's" 172 _("You can't remove this user since it's"
171 " crucial for entire application")) 173 " crucial for entire application"))
174 if user.repositories:
175 raise UserOwnsReposException(_('This user still owns %s '
176 'repositories and cannot be '
177 'removed. Switch owners or '
178 'remove those repositories') \
179 % user.repositories)
172 self.sa.delete(user) 180 self.sa.delete(user)
173 self.sa.commit() 181 self.sa.commit()
174 except: 182 except:
175 log.error(traceback.format_exc()) 183 log.error(traceback.format_exc())
176 self.sa.rollback() 184 self.sa.rollback()