# HG changeset patch # User Søren Løvborg # Date 1487869256 -3600 # Node ID eea19c23b7410d8e3f4509ec3b933c9804fa56ab # Parent 884d2c24657031eea52bbc9b8ad25b515dd9cab2 cleanup: refer less to User.DEFAULT_USER Down the road we might want to identify the default user in another way than by username. diff -r 884d2c246570 -r eea19c23b741 kallithea/controllers/admin/my_account.py --- a/kallithea/controllers/admin/my_account.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/controllers/admin/my_account.py Thu Feb 23 18:00:56 2017 +0100 @@ -66,7 +66,7 @@ def __load_data(self): c.user = User.get(request.authuser.user_id) - if c.user.username == User.DEFAULT_USER: + if c.user.is_default_user: h.flash(_("You can't edit this user since it's" " crucial for entire application"), category='warning') raise HTTPFound(location=url('users')) diff -r 884d2c246570 -r eea19c23b741 kallithea/controllers/admin/users.py --- a/kallithea/controllers/admin/users.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/controllers/admin/users.py Thu Feb 23 18:00:56 2017 +0100 @@ -68,7 +68,7 @@ def index(self, format='html'): c.users_list = User.query().order_by(User.username) \ - .filter(User.username != User.DEFAULT_USER) \ + .filter_by(is_default_user=False) \ .order_by(func.lower(User.username)) \ .all() diff -r 884d2c246570 -r eea19c23b741 kallithea/controllers/api/api.py --- a/kallithea/controllers/api/api.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/controllers/api/api.py Thu Feb 23 18:00:56 2017 +0100 @@ -588,7 +588,7 @@ user.get_api_data() for user in User.query() .order_by(User.username) - .filter(User.username != User.DEFAULT_USER) + .filter_by(is_default_user=False) ] @HasPermissionAnyDecorator('hg.admin') diff -r 884d2c246570 -r eea19c23b741 kallithea/lib/auth_modules/auth_internal.py --- a/kallithea/lib/auth_modules/auth_internal.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/lib/auth_modules/auth_internal.py Thu Feb 23 18:00:56 2017 +0100 @@ -87,7 +87,7 @@ if userobj.active: from kallithea.lib import auth password_match = auth.check_password(password, userobj.password) - if userobj.username == User.DEFAULT_USER and userobj.active: + if userobj.is_default_user and userobj.active: log.info('user %s authenticated correctly as anonymous user', username) return user_data diff -r 884d2c246570 -r eea19c23b741 kallithea/lib/db_manage.py --- a/kallithea/lib/db_manage.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/lib/db_manage.py Thu Feb 23 18:00:56 2017 +0100 @@ -140,9 +140,7 @@ Fixes a old default user with some 'nicer' default values, used mostly for anonymous access """ - def_user = self.sa.query(User) \ - .filter(User.username == User.DEFAULT_USER) \ - .one() + def_user = self.sa.query(User).filter_by(is_default_user=True).one() def_user.name = 'Anonymous' def_user.lastname = 'User' diff -r 884d2c246570 -r eea19c23b741 kallithea/lib/middleware/simplegit.py --- a/kallithea/lib/middleware/simplegit.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/lib/middleware/simplegit.py Thu Feb 23 18:00:56 2017 +0100 @@ -122,7 +122,7 @@ log.debug('Repository path is %s', repo_path) # CHECK LOCKING only if it's not ANONYMOUS USER - if user.username != User.DEFAULT_USER: + if not user.is_default_user: log.debug('Checking locking on repository') (make_lock, locked, diff -r 884d2c246570 -r eea19c23b741 kallithea/lib/middleware/simplehg.py --- a/kallithea/lib/middleware/simplehg.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/lib/middleware/simplehg.py Thu Feb 23 18:00:56 2017 +0100 @@ -127,7 +127,7 @@ log.debug('Repository path is %s', repo_path) # CHECK LOCKING only if it's not ANONYMOUS USER - if user.username != User.DEFAULT_USER: + if not user.is_default_user: log.debug('Checking locking on repository') (make_lock, locked, diff -r 884d2c246570 -r eea19c23b741 kallithea/lib/utils2.py --- a/kallithea/lib/utils2.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/lib/utils2.py Thu Feb 23 18:00:56 2017 +0100 @@ -546,7 +546,7 @@ result = set() for name in extract_mentioned_usernames(text): user = User.get_by_username(name, case_insensitive=True) - if user is not None and user.username != User.DEFAULT_USER: + if user is not None and not user.is_default_user: result.add(user) return result diff -r 884d2c246570 -r eea19c23b741 kallithea/model/db.py --- a/kallithea/model/db.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/model/db.py Thu Feb 23 18:00:56 2017 +0100 @@ -530,6 +530,10 @@ def is_admin(self): return self.admin + @hybrid_property + def is_default_user(self): + return self.username == User.DEFAULT_USER + @property def AuthUser(self): """ @@ -570,9 +574,8 @@ the default user. ''' user = super(User, cls).get_or_404(id_) - if allow_default == False: - if user.username == User.DEFAULT_USER: - raise DefaultUserException + if not allow_default and user.is_default_user: + raise DefaultUserException() return user @classmethod diff -r 884d2c246570 -r eea19c23b741 kallithea/model/permission.py --- a/kallithea/model/permission.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/model/permission.py Thu Feb 23 18:00:56 2017 +0100 @@ -99,7 +99,7 @@ try: # stage 1 set anonymous access - if perm_user.username == User.DEFAULT_USER: + if perm_user.is_default_user: perm_user.active = str2bool(form_result['anonymous']) self.sa.add(perm_user) diff -r 884d2c246570 -r eea19c23b741 kallithea/model/pull_request.py --- a/kallithea/model/pull_request.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/model/pull_request.py Thu Feb 23 18:00:56 2017 +0100 @@ -54,7 +54,7 @@ """ for user_spec in seq: user = User.guess_instance(user_spec) - if user is None or user.username == User.DEFAULT_USER: + if user is None or user.is_default_user: raise UserInvalidException(user_spec) yield user diff -r 884d2c246570 -r eea19c23b741 kallithea/model/repo_group.py --- a/kallithea/model/repo_group.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/model/repo_group.py Thu Feb 23 18:00:56 2017 +0100 @@ -202,7 +202,7 @@ # private repos will not allow to change the default permissions # using recursive mode - if obj.private and user.username == User.DEFAULT_USER: + if obj.private and user.is_default_user: return # we set group permission but we have to switch to repo diff -r 884d2c246570 -r eea19c23b741 kallithea/model/user.py --- a/kallithea/model/user.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/model/user.py Thu Feb 23 18:00:56 2017 +0100 @@ -210,7 +210,7 @@ from kallithea.lib.auth import get_crypt_password skip_attrs = skip_attrs or [] user = self.get(user_id, cache=False) - if user.username == User.DEFAULT_USER: + if user.is_default_user: raise DefaultUserException( _("You can't edit this user since it's " "crucial for entire application")) @@ -232,7 +232,7 @@ from kallithea.lib.auth import get_crypt_password user = User.guess_instance(user) - if user.username == User.DEFAULT_USER: + if user.is_default_user: raise DefaultUserException( _("You can't edit this user since it's" " crucial for entire application") @@ -251,7 +251,7 @@ cur_user = getattr(get_current_authuser(), 'username', None) user = User.guess_instance(user) - if user.username == User.DEFAULT_USER: + if user.is_default_user: raise DefaultUserException( _("You can't remove this user since it is" " crucial for the entire application")) diff -r 884d2c246570 -r eea19c23b741 kallithea/tests/api/api_base.py --- a/kallithea/tests/api/api_base.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/tests/api/api_base.py Thu Feb 23 18:00:56 2017 +0100 @@ -216,7 +216,7 @@ id_, params = _build_data(self.apikey, 'get_users', ) response = api_call(self, params) ret_all = [] - _users = User.query().filter(User.username != User.DEFAULT_USER) \ + _users = User.query().filter_by(is_default_user=False) \ .order_by(User.username).all() for usr in _users: ret = usr.get_api_data() diff -r 884d2c246570 -r eea19c23b741 kallithea/tests/other/manual_test_vcs_operations.py --- a/kallithea/tests/other/manual_test_vcs_operations.py Mon Feb 20 19:21:34 2017 +0100 +++ b/kallithea/tests/other/manual_test_vcs_operations.py Thu Feb 23 18:00:56 2017 +0100 @@ -158,11 +158,11 @@ def set_anonymous_access(enable=True): - user = User.get_by_username(User.DEFAULT_USER) + user = User.get_default_user() user.active = enable Session().commit() print '\tanonymous access is now:', enable - if enable != User.get_by_username(User.DEFAULT_USER).active: + if enable != User.get_default_user().active: raise Exception('Cannot set anonymous access')