1
0
Fork 0
mirror of https://codeberg.org/Mo8it/AdvLabDB.git synced 2024-11-08 21:21:06 +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.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))