toolbar: enable toolbar only for devs
This commit is contained in:
parent
b892d9ae68
commit
1c0854cc52
3
.env
3
.env
|
@ -1,3 +1,2 @@
|
|||
FLASK_APP=V5.py
|
||||
FLASK_DEBUG=1
|
||||
FLASK_ENV=DEVLOPPEMENT
|
||||
FLASK_DEBUG=False
|
|
@ -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)
|
|
@ -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
|
|
@ -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 \
|
||||
|
|
Loading…
Reference in New Issue