Check if user.token attribute exists

If the user is admin or don't have an ID the identity panel
will be loaded. In any other case  the project panel will be loaded.
This will also check if the panel is unregistred, and if the
session has expired it will lead to the login screen.

Closes-Bug: #1659818
Change-Id: I27300e928855ec10ca5d2a623d636e50d756b698
(cherry picked from commit a2386d80fb)
This commit is contained in:
Fredrik Starkenberg 2017-01-27 12:27:39 +00:00 committed by Rob Cresswell
parent 100f77d895
commit a8eae317e1

View File

@ -26,21 +26,19 @@ MESSAGES_PATH = getattr(settings, 'MESSAGES_PATH', None)
def get_user_home(user):
dashboard = None
if user.is_superuser:
try:
token = user.token
except AttributeError:
raise exceptions.NotAuthenticated()
# Domain Admin, Project Admin will default to identity
if token.project.get('id') is None or user.is_superuser:
try:
dashboard = horizon.get_dashboard('admin')
dashboard = horizon.get_dashboard('identity')
except base.NotRegistered:
pass
if dashboard is None:
else:
dashboard = horizon.get_default_dashboard()
# Domain Admin, Project Admin will default to identity
if (user.token.project.get('id') is None or
(user.is_superuser and user.token.project.get('id'))):
dashboard = horizon.get_dashboard('identity')
return dashboard.get_absolute_url()