toolbar: enable toolbar only for devs

This commit is contained in:
Darks 2023-06-07 23:41:27 +02:00
parent b892d9ae68
commit 1c0854cc52
Signed by: Darks
GPG Key ID: 7515644268BE1433
4 changed files with 26 additions and 5 deletions

3
.env
View File

@ -1,3 +1,2 @@
FLASK_APP=V5.py
FLASK_DEBUG=1
FLASK_ENV=DEVLOPPEMENT
FLASK_DEBUG=False

View File

@ -44,7 +44,8 @@ from app import processors
from app import jobs
# Enable flask-debug-toolbar if requested
# If app.config[] is True, will show for everyone
if V5Config.ENABLE_FLASK_DEBUG_TOOLBAR:
from flask_debugtoolbar import DebugToolbarExtension
from app.utils.toolbar import CustomDebugToolbar
app.config['DEBUG_TB_PROFILER_ENABLED'] = True
toolbar = DebugToolbarExtension(app)
toolbar = CustomDebugToolbar(app)

21
app/utils/toolbar.py Normal file
View File

@ -0,0 +1,21 @@
# Override some properties of Flask-Toolbar to allow access to authorized users
from flask import request
from flask_debugtoolbar import DebugToolbarExtension
from flask_login import current_user
class CustomDebugToolbar(DebugToolbarExtension):
def _show_toolbar(self):
"""Return a boolean to indicate if we need to show the toolbar."""
if request.blueprint == 'debugtoolbar':
return False
# Debug mode: visible for everyone
if self.app.debug:
return True
# Developers: toolbar visible
if current_user.is_authenticated and current_user.priv("misc.dev-infos"):
return True
return False

View File

@ -26,7 +26,7 @@ class FlaskApplicationSettings(object):
See: https://flask.palletsprojects.com/en/2.1.x/config/
"""
DEBUG = os.environ.get("FLASK_DEBUG") or LocalConfig.FLASK_DEBUG
DEBUG = os.environ.get('FLASK_DEBUG') or False
SECRET_KEY = os.environ.get('SECRET_KEY') or LocalConfig.SECRET_KEY
SQLALCHEMY_DATABASE_URI = os.environ.get('DATABASE_URL') or \