From d48a308cc63d5645a21e06c5a45557ed119395c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Thu, 24 Aug 2017 13:56:18 +0200 Subject: [PATCH] Renamed pillar.auth.current_web_user to pillar.auth.current_user This is an in-between change. In the future, we want to always set g.current_user so that it's never None (but rather an AnonymousUser instance). However, there is still some code that assumes that when g.current_user is not None the user is logged in. This should be addressed first. --- pillar/auth/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/pillar/auth/__init__.py b/pillar/auth/__init__.py index 13ef6877..8ebe6e97 100644 --- a/pillar/auth/__init__.py +++ b/pillar/auth/__init__.py @@ -4,7 +4,7 @@ import collections import logging import typing -from flask import session +from flask import session, g import flask_login import flask_oauthlib.client from werkzeug.local import LocalProxy @@ -55,7 +55,7 @@ class UserClass(flask_login.UserMixin): user.roles = db_user.get('roles') or [] user.group_ids = db_user.get('groups') or [] user.email = db_user.get('email') or '' - user.username = db_user['username'] + user.username = db_user.get('username') or '' user.full_name = db_user.get('full_name') or '' # Derived properties @@ -251,11 +251,16 @@ def config_oauth_login(app): return oauth_blender_id -def _get_current_web_user() -> UserClass: - """Returns the current web user as a UserClass instance.""" +def _get_current_user() -> UserClass: + """Returns the current user as a UserClass instance. - return flask_login.current_user + Never returns None; returns an AnonymousUser() instance instead. + """ + + from ..api.utils.authentication import current_user + + return current_user() -current_web_user: UserClass = LocalProxy(_get_current_web_user) -"""The current web user.""" +current_user: UserClass = LocalProxy(_get_current_user) +"""The current user."""