Mercurial > kallithea
changeset 5545:ba30adf2fb8a
auth: introduce AuthUser.is_default_user attribute
This makes makes a number of checks more readable.
The username of the default user is presently hardcoded to "default" (in
db.User.DEFAULT_USER); this is currently what defines the default user,
and this commit doesn't change that. (Even if the check that defines
is_default_user is a comparison between user IDs and not usernames,
the anonymous_user object used in the comparison is loaded by looking
up the user named "default".)
author | Søren Løvborg <sorenl@unity3d.com> |
---|---|
date | Tue, 06 Oct 2015 19:22:22 +0200 |
parents | feef81a369b3 |
children | 95bc1801d480 |
files | kallithea/controllers/admin/gists.py kallithea/controllers/login.py kallithea/controllers/summary.py kallithea/lib/auth.py |
diffstat | 4 files changed, 10 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/controllers/admin/gists.py Mon Aug 24 22:51:07 2015 +0200 +++ b/kallithea/controllers/admin/gists.py Tue Oct 06 19:22:22 2015 +0200 @@ -69,7 +69,7 @@ def index(self): """GET /admin/gists: All items in the collection""" # url('gists') - not_default_user = c.authuser.username != User.DEFAULT_USER + not_default_user = not c.authuser.is_default_user c.show_private = request.GET.get('private') and not_default_user c.show_public = request.GET.get('public') and not_default_user
--- a/kallithea/controllers/login.py Mon Aug 24 22:51:07 2015 +0200 +++ b/kallithea/controllers/login.py Tue Oct 06 19:22:22 2015 +0200 @@ -78,11 +78,10 @@ else: c.came_from = url('home') - not_default = self.authuser.username != User.DEFAULT_USER ip_allowed = AuthUser.check_ip_allowed(self.authuser, self.ip_addr) # redirect if already logged in - if self.authuser.is_authenticated and not_default and ip_allowed: + if self.authuser.is_authenticated and not self.authuser.is_default_user and ip_allowed: raise HTTPFound(location=c.came_from) if request.POST:
--- a/kallithea/controllers/summary.py Mon Aug 24 22:51:07 2015 +0200 +++ b/kallithea/controllers/summary.py Tue Oct 06 19:22:22 2015 +0200 @@ -114,8 +114,9 @@ def index(self, repo_name): _load_changelog_summary() - username = '' - if self.authuser.username != User.DEFAULT_USER: + if self.authuser.is_default_user: + username = '' + else: username = safe_str(self.authuser.username) _def_clone_uri = _def_clone_uri_by_id = c.clone_uri_tmpl
--- a/kallithea/lib/auth.py Mon Aug 24 22:51:07 2015 +0200 +++ b/kallithea/lib/auth.py Tue Oct 06 19:22:22 2015 +0200 @@ -509,7 +509,8 @@ is_user_loaded = self._fill_data(self.anonymous_user) # The anonymous user is always "logged in". - if self.user_id == self.anonymous_user.user_id: + self.is_default_user = (self.user_id == self.anonymous_user.user_id) + if self.is_default_user: self.is_authenticated = True if not self.username: @@ -626,7 +627,7 @@ % (self.user_id, self.username, self.is_authenticated) def set_authenticated(self, authenticated=True): - if self.user_id != self.anonymous_user.user_id: + if not self.is_default_user: self.is_authenticated = authenticated def to_cookie(self): @@ -816,9 +817,7 @@ log.debug('Checking if user is not anonymous @%s', cls) - anonymous = self.user.username == User.DEFAULT_USER - - if anonymous: + if self.user.is_default_user: return redirect_to_login(_('You need to be a registered user to ' 'perform this action')) else: @@ -848,9 +847,7 @@ else: log.debug('Permission denied for %s %s', cls, self.user) - anonymous = self.user.username == User.DEFAULT_USER - - if anonymous: + if self.user.is_default_user: return redirect_to_login(_('You need to be signed in to view this page')) else: raise HTTPForbidden()