-
-
Save d9k/a638071ce7146ef01c27779a51d96f2b to your computer and use it in GitHub Desktop.
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__}" |
In superset 2.0.1 I had to replace the import
from superset.typing import FlaskResponse
with
from superset.superset_typing import FlaskResponse
@ChristopherKi Hi where to put this code. There is no file named superset_config_docker.py. Can you provide the path too and other procedure if any.
you have to create it
@ChristopherKi Hi where to put this code. There is no file named superset_config_docker.py. Can you provide the path too and other procedure if any.
The code snipped can be included in your normal superset config file. The exact location will depend on your general superset setup. I suggest you to take a look at the documentation
This works for me, but when someone visits the login page, there is always an "Access is Denied" banner at the top of the screen. Is there any way to avoid this?
This works for me, but when someone visits the login page, there is always an "Access is Denied" banner at the top of the screen. Is there any way to avoid this?
Hi, @rscarborough1996, I just solved the problem by adding the check-out of the username:
if get_username():
return redirect("/dashboard/list/")
else:
return redirect("/login/")
Hello, you have each version of superset ?
Doesn't seem to work on 3.0.1. Has anyone tried yet? Can't find a way to make it work for now :(
Hi,
This works for me in superset v3:
from flask import redirect, g, request
from flask_appbuilder import expose, IndexView
from superset.extensions import (
appbuilder,
)
from superset.utils.core import (
get_user_id,
)
from superset.superset_typing import FlaskResponse
class SupersetIndexView(IndexView):
@expose("/")
def index(self) -> FlaskResponse:
if not g.user or not get_user_id():
# Do steps for anonymous user e.g.
return redirect("/login")
# Do steps for authenticated user e.g.
return redirect("/dashboard/list")
FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"
Hi,
This works for me in superset v3:
from flask import redirect, g, request from flask_appbuilder import expose, IndexView from superset.extensions import ( appbuilder, ) from superset.utils.core import ( get_user_id, ) from superset.superset_typing import FlaskResponse class SupersetIndexView(IndexView): @expose("/") def index(self) -> FlaskResponse: if not g.user or not get_user_id(): # Do steps for anonymous user e.g. return redirect("/login") # Do steps for authenticated user e.g. return redirect("/dashboard/list") FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"
Where do I put this code? @Luiggi370z
Hi,
This works for me in superset v3:from flask import redirect, g, request from flask_appbuilder import expose, IndexView from superset.extensions import ( appbuilder, ) from superset.utils.core import ( get_user_id, ) from superset.superset_typing import FlaskResponse class SupersetIndexView(IndexView): @expose("/") def index(self) -> FlaskResponse: if not g.user or not get_user_id(): # Do steps for anonymous user e.g. return redirect("/login") # Do steps for authenticated user e.g. return redirect("/dashboard/list") FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"Where do I put this code? @Luiggi370z
Put this code in a new file superset_config.py and specify it in your docker file or there is another way you can go through this documentations
Hi,
This works for me in superset v3:from flask import redirect, g, request from flask_appbuilder import expose, IndexView from superset.extensions import ( appbuilder, ) from superset.utils.core import ( get_user_id, ) from superset.superset_typing import FlaskResponse class SupersetIndexView(IndexView): @expose("/") def index(self) -> FlaskResponse: if not g.user or not get_user_id(): # Do steps for anonymous user e.g. return redirect("/login") # Do steps for authenticated user e.g. return redirect("/dashboard/list") FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"Where do I put this code? @Luiggi370z
Put this code in a new file superset_config.py and specify it in your docker file or there is another way you can go through this documentations
@ameen7626 Thank you for your response; it's working.
Hi,
This works for me in superset v3:from flask import redirect, g, request from flask_appbuilder import expose, IndexView from superset.extensions import ( appbuilder, ) from superset.utils.core import ( get_user_id, ) from superset.superset_typing import FlaskResponse class SupersetIndexView(IndexView): @expose("/") def index(self) -> FlaskResponse: if not g.user or not get_user_id(): # Do steps for anonymous user e.g. return redirect("/login") # Do steps for authenticated user e.g. return redirect("/dashboard/list") FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"Where do I put this code? @Luiggi370z
Put this code in a new file superset_config.py and specify it in your docker file or there is another way you can go through this documentations
Hello, how to redo this code for Superset 3.1.1 to verify the user's role?
if it is an admin, then return redirect("/superset/dashboard/9/?standalone=2"), if public then return redirect("/superset/dashboard/10/?standalone=2")
"Getting too many redirect errors" 4.1.1. version. Plz help
"Getting too many redirect errors" 4.1.1. version. Plz help
Works like this:
# redirect by user
import logging
import pprint
from flask import redirect, g, request
from flask_appbuilder import expose, IndexView
from superset import security_manager
from superset.extensions import appbuilder
from superset.utils.core import get_user_id
from superset.superset_typing import FlaskResponse
logger = logging.getLogger()
class SupersetIndexView(IndexView):
@expose("/")
def index(self) -> FlaskResponse:
if not g.user or not get_user_id():
# Steps for anonymous user
return redirect("/login")
# Steps for authenticated user
user_roles = security_manager.get_user_roles()
logger.warning('__DEBUG__ user roles: %s', pprint.pformat(user_roles))
for role in user_roles:
role_name = role.name
#logger.warning('__DEBUG__ role: %s', pprint.pformat(role))
if role_name == "CUSTOM_ROLE":
return redirect("/dashboard/1")
# Default redirect if no specific role matched
return redirect("/dashboard/list")
FAB_INDEX_VIEW = f"{SupersetIndexView.__module__}.{SupersetIndexView.__name__}"
#get_user_roles has been moved to security manager
#This worked for me:
from superset import security_manager
user_roles = security_manager.get_user_roles()