1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-12-20 23:41:20 +00:00

Redirect to login if no access

This commit is contained in:
Mo 2021-07-01 14:02:23 +02:00
parent 0a91f4a331
commit 6e153d9c09

View file

@ -1,6 +1,7 @@
from flask_admin import AdminIndexView from flask_admin import AdminIndexView
from flask_admin.contrib.sqla import ModelView from flask_admin.contrib.sqla import ModelView
from flask_security import current_user from flask_security import current_user
from flask import redirect, request, url_for
def adminViewIsAccessible(): def adminViewIsAccessible():
@ -11,6 +12,10 @@ class SecureAdminIndexView(AdminIndexView):
def is_accessible(self): def is_accessible(self):
return adminViewIsAccessible() 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): class SecureModelView(ModelView):
can_export = True can_export = True
@ -26,3 +31,7 @@ class SecureModelView(ModelView):
def is_accessible(self): def is_accessible(self):
return adminViewIsAccessible() 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))