Distributed Cloud fix for switching between RegionOne and SystemController

Adds custom home lookup function and JS to automatically redirect
when authorization errors are hit to make the transition more seamless

Change-Id: I9dfda59ce216db4d562094b309ac7809c7a80735
Partial-Bug: 1846239
Signed-off-by: Tyler Smith <tyler.smith@windriver.com>
This commit is contained in:
Tyler Smith 2019-10-03 13:14:30 -04:00
parent 6b84718ce9
commit a67f2ea241
3 changed files with 54 additions and 0 deletions

View File

@ -68,6 +68,9 @@ if distributed_cloud_role and distributed_cloud_role in ['systemcontroller',
'subcloud']:
DC_MODE = True
HORIZON_CONFIG["user_home"] = \
"starlingx_dashboard.utils.settings.get_user_home"
OPENSTACK_ENDPOINT_TYPE = "internalURL"
# Override Django tempory file upload directory

View File

@ -0,0 +1,16 @@
/**
* Copyright (c) 2019 Wind River Systems, Inc.
*
* SPDX-License-Identifier: Apache-2.0
*
*/
horizon.addInitFunction(function () {
// This is a workaround to automatically redirect to the login page when an authorization error page is displayed.
// It occurs every time a user switches between RegionOne and SystemController in a distributed cloud setup
// since the same dashboards are not accessible to both regions.
// The login page will see the user is already logged in and redirect to the user's home page.
if ($("#content_body:contains('You are not authorized to access this page')").length > 0){
window.location.replace("/auth/login/")
}
});

View File

@ -0,0 +1,35 @@
#
# Copyright (c) 2019 Wind River Systems, Inc.
#
# SPDX-License-Identifier: Apache-2.0
#
from django.conf import settings
import horizon
from horizon import base
def get_user_home(user):
dashboard = horizon.get_default_dashboard()
dc_mode = getattr(settings, 'DC_MODE', False)
if user.is_superuser:
if getattr(user, 'services_region', None) == 'SystemController':
try:
dashboard = horizon.get_dashboard('dc_admin')
except base.NotRegistered:
pass
if getattr(user, 'services_region', None) == 'RegionOne' and dc_mode:
try:
if user.is_superuser:
dashboard = horizon.get_dashboard('admin'). \
get_panel("inventory")
else:
dashboard = horizon.get_dashboard('project'). \
get_panel("api_access")
except base.NotRegistered:
pass
return dashboard.get_absolute_url()