diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/local/local_settings.d/_30_stx_local_settings.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/local/local_settings.d/_30_stx_local_settings.py index fb7a4c14..52279038 100644 --- a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/local/local_settings.d/_30_stx_local_settings.py +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/local/local_settings.d/_30_stx_local_settings.py @@ -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 diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/static/js/horizon.auto_redirect.js b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/static/js/horizon.auto_redirect.js new file mode 100644 index 00000000..1ac4ab30 --- /dev/null +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/static/js/horizon.auto_redirect.js @@ -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/") + } +}); diff --git a/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/utils/settings.py b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/utils/settings.py new file mode 100644 index 00000000..5513b5e8 --- /dev/null +++ b/starlingx-dashboard/starlingx-dashboard/starlingx_dashboard/utils/settings.py @@ -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()