Created
January 13, 2022 07:44
-
-
Save d9k/a638071ce7146ef01c27779a51d96f2b to your computer and use it in GitHub Desktop.
Superset welcome page redirect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import pprint | |
from flask import Flask, redirect | |
from flask_appbuilder import expose, IndexView | |
from superset.typing import FlaskResponse | |
logger = logging.getLogger() | |
logger.warn("Loading config override for Uniweb"); | |
WELCOME_PAGE_REDIRECT_ADMIN="/superset/dashboard/1/" | |
WELCOME_PAGE_REDIRECT_DEFAULT="/dashboard/list/" | |
WELCOME_PAGE_REDIRECT_BY_ROLE={ | |
'Test': '/superset/dashboard/2/', | |
} | |
# Change welcome page | |
# https://stackoverflow.com/a/69930056/1760643 | |
class SupersetDashboardIndexView(IndexView): | |
@expose("/") | |
def index(self) -> FlaskResponse: | |
from superset.views.base import is_user_admin, get_user_roles | |
user_roles = get_user_roles() | |
logger.warn('__DEBUG__ user roles: ' + pprint.pformat(user_roles)) | |
if is_user_admin(): | |
return redirect(WELCOME_PAGE_REDIRECT_ADMIN) | |
else: | |
for role in user_roles: | |
role_name = role.name | |
if role_name in WELCOME_PAGE_REDIRECT_BY_ROLE: | |
return redirect(WELCOME_PAGE_REDIRECT_BY_ROLE[role_name]) | |
return redirect(WELCOME_PAGE_REDIRECT_DEFAULT) | |
FAB_INDEX_VIEW = f"{SupersetDashboardIndexView.__module__}.{SupersetDashboardIndexView.__name__}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works like this: