GitHub user paulsonkevgit added a comment to the discussion: Is there an
inbuilt class in Superset called SuperstDashboardIndexView
@dosu So will this make the user to redirect to the required pages as said in
the follwing code??
class SupersetDashboardIndexView(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(WELCOME_PAGE_REDIRECT_DEFAULT)
And where do i do this in the follwoing code , cuz there is already another
function called view1 which had been defined and assigned to the
FLASK_APP_MUTATOR already
Can u say where exactly should i add the code ...
def view1(SupersetsetApp):
from superset.views.user_D.views import DashboardModelView1
import time
# Cache to store user info and timestamps
user_info_cache = {}
CACHE_TTL = 10 # Time in seconds to keep cached results
appbuilder.add_view_no_menu(DashboardModelView1)
appbuilder.add_link(
"User Details",
label=("User Details"),
href="/userdetails/form",
icon="fa-dashboard",
category="",
category_icon="",
)
@SupersetsetApp.before_request
def track_user_visit():
try:
if request.path.startswith('/api/v1/dashboard'):
username = g.user.username
security_manager = appbuilder.sm
current_time = time.time()
fresh_data = False
if (username in user_info_cache and
current_time - user_info_cache[username]['timestamp'] <
CACHE_TTL):
AU, BU, CU, WU = user_info_cache[username]['data']
else:
if hasattr(security_manager, 'Viteuserinfocall'):
AU, BU, CU, WU =
security_manager.Viteuserinfocall(username)
user_info_cache[username] = {
'timestamp': current_time,
'data': (AU, BU, CU, WU)
}
fresh_data = True
if fresh_data:
session: Session = SQLA().session
try:
stmt1 = update(CustomUser).values(
businessunit_id=BU,
account_id=AU,
customer_id=CU,
warehouse_id=WU
).where(CustomUser.username == username)
session.execute(stmt1)
session.commit()
print("Updated user preferences in DB based on
dashboard visit.")
except Exception as e:
session.rollback()
print(f"Error updating user info for user visiting
dashboard: {e}")
except Exception as e:
print(f"Error in track_user_visit: {e}")
return SupersetsetApp
FLASK_APP_MUTATOR=view1
GitHub link:
https://github.com/apache/superset/discussions/34594#discussioncomment-14033721
----
This is an automatically sent email for [email protected].
To unsubscribe, please send an email to:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]