Changeset - eea19c23b741
[Not reviewed]
default
0 15 0
Søren Løvborg - 9 years ago 2017-02-23 18:00:56
sorenl@unity3d.com
cleanup: refer less to User.DEFAULT_USER

Down the road we might want to identify the default user in another
way than by username.
15 files changed with 23 insertions and 22 deletions:
0 comments (0 inline, 0 general)
kallithea/controllers/admin/my_account.py
Show inline comments
 
@@ -66,7 +66,7 @@ class MyAccountController(BaseController
 

	
 
    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'))
kallithea/controllers/admin/users.py
Show inline comments
 
@@ -68,7 +68,7 @@ class UsersController(BaseController):
 

	
 
    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()
 

	
kallithea/controllers/api/api.py
Show inline comments
 
@@ -588,7 +588,7 @@ class ApiController(JSONRPCController):
 
            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')
kallithea/lib/auth_modules/auth_internal.py
Show inline comments
 
@@ -87,7 +87,7 @@ class KallitheaAuthPlugin(auth_modules.K
 
        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
kallithea/lib/db_manage.py
Show inline comments
 
@@ -140,9 +140,7 @@ class DbManage(object):
 
        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'
kallithea/lib/middleware/simplegit.py
Show inline comments
 
@@ -122,7 +122,7 @@ class SimpleGit(BaseVCSController):
 
        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,
kallithea/lib/middleware/simplehg.py
Show inline comments
 
@@ -127,7 +127,7 @@ class SimpleHg(BaseVCSController):
 
        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,
kallithea/lib/utils2.py
Show inline comments
 
@@ -546,7 +546,7 @@ def extract_mentioned_users(text):
 
    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
 

	
kallithea/model/db.py
Show inline comments
 
@@ -530,6 +530,10 @@ class User(Base, BaseDbModel):
 
    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 @@ class User(Base, BaseDbModel):
 
        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
kallithea/model/permission.py
Show inline comments
 
@@ -99,7 +99,7 @@ class PermissionModel(BaseModel):
 

	
 
        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)
 

	
kallithea/model/pull_request.py
Show inline comments
 
@@ -54,7 +54,7 @@ class PullRequestModel(BaseModel):
 
        """
 
        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
 

	
kallithea/model/repo_group.py
Show inline comments
 
@@ -202,7 +202,7 @@ class RepoGroupModel(BaseModel):
 

	
 
                # 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
kallithea/model/user.py
Show inline comments
 
@@ -210,7 +210,7 @@ class UserModel(BaseModel):
 
        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 @@ class UserModel(BaseModel):
 
        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 @@ class UserModel(BaseModel):
 
            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"))
kallithea/tests/api/api_base.py
Show inline comments
 
@@ -216,7 +216,7 @@ class _BaseTestApi(object):
 
        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()
kallithea/tests/other/manual_test_vcs_operations.py
Show inline comments
 
@@ -158,11 +158,11 @@ def _add_files_and_push(vcs, DEST, **kwa
 

	
 

	
 
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')
 

	
 

	
0 comments (0 inline, 0 general)