floriandeutsch89 commented on issue #34422:
URL: https://github.com/apache/superset/issues/34422#issuecomment-3758878126

   > from flask_appbuilder import expose, IndexView from superset.typing import 
FlaskResponse
   > 
   > class MyCustomIndexView(IndexView): 
[@expose](https://github.com/expose)('/') def index(self) -> FlaskResponse: 
return redirect("/chart/list/") pass
   > 
   > def mutate_app(app): from superset.extensions import appbuilder 
appbuilder.indexview = MyCustomIndexView
   > 
   > FLASK_APP_MUTATOR = mutate_app
   > 
   > I tried the above , but the redirection is not working i am landing to the 
superset/welcome page itself
   
   
   Here's a workaround to start with. But that's _really_ dirty:
   
   ```
   LOGO_TARGET_PATH = '/superset/dashboard/14/'
   
   def _role_based_redirect(source: str) -> FlaskResponse:
       logging.debug(
           "Role redirect: invoked from %s for path=%s", source, request.path
       )
   
       if not g.user or not get_user_id():
           logging.debug("Role redirect: anonymous user detected; redirect to 
/login")
           return redirect("/login")
   
       try:
           from superset.extensions import appbuilder as current_appbuilder
   
           security_mgr = getattr(current_appbuilder, "sm", security_manager)
       except Exception:  # pragma: no cover - fallback for initialization edge 
cases
           security_mgr = security_manager
   
       user_roles = security_mgr.get_user_roles()
       logging.debug(
           "Role redirect: evaluating user_id=%s with security manager %s; 
roles=%s",
           get_user_id(),
           security_mgr.__class__.__name__,
           pprint.pformat(user_roles),
       )
   
       for role in user_roles:
           role_name = role.name
           logging.debug("Role redirect: inspecting role %s -- %s", role_name, 
role)
   
           if role_name == "Admin":
               logging.debug(
                   "Role redirect: Admin matched; redirecting user_id=%s to %s",
                   get_user_id(),
                   LOGO_TARGET_PATH,
               )
               return redirect(LOGO_TARGET_PATH)
   
       logging.debug(
           "Role redirect: no specific role matched for user_id=%s; redirecting 
to /dashboard/list",
           get_user_id(),
       )
       return redirect("/dashboard/list")
   
   def mutate_app(app):
       from superset.extensions import appbuilder
   
       logging.debug(
           "Role redirect: registered custom IndexView for role-based redirect"
       )
   
       @app.before_request
       def _role_redirect_before_request():
           if request.method != "GET":
               return None
   
           if request.path in {"", "/"}:
               logging.debug(
                   "Role redirect: before_request intercept for path=%s", 
request.path
               )
               return _role_based_redirect("before_request")
   
           return None
   
       return app
   
   FLASK_APP_MUTATOR = mutate_app
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to