diff --git a/advlabdb/customClasses.py b/advlabdb/customClasses.py index 1201834..2d23d06 100644 --- a/advlabdb/customClasses.py +++ b/advlabdb/customClasses.py @@ -1,6 +1,7 @@ from flask_admin import AdminIndexView from flask_admin.contrib.sqla import ModelView from flask_security import current_user +from flask import redirect, request, url_for def adminViewIsAccessible(): @@ -11,6 +12,10 @@ class SecureAdminIndexView(AdminIndexView): def is_accessible(self): return adminViewIsAccessible() + def inaccessible_callback(self, name, **kwargs): + # Redirect to login page if user doesn't have access + return redirect(url_for("security.login", next=request.url)) + class SecureModelView(ModelView): can_export = True @@ -26,3 +31,7 @@ class SecureModelView(ModelView): def is_accessible(self): return adminViewIsAccessible() + + def inaccessible_callback(self, name, **kwargs): + # Redirect to login page if user doesn't have access + return redirect(url_for("security.login", next=request.url))