From 1172bac8863d3816d23423a07d1d48025e60a1c5 Mon Sep 17 00:00:00 2001 From: kiblik <5609770+kiblik@users.noreply.github.com> Date: Thu, 16 Jan 2025 22:47:54 +0100 Subject: [PATCH] feat(ui): Add option to define custom css and js --- dojo/context_processors.py | 2 ++ dojo/settings/settings.dist.py | 11 +++++++++++ dojo/templates/base.html | 15 +++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/dojo/context_processors.py b/dojo/context_processors.py index 782cf767ce2..79a21166c52 100644 --- a/dojo/context_processors.py +++ b/dojo/context_processors.py @@ -26,6 +26,8 @@ def globalize_vars(request): "DOCUMENTATION_URL": settings.DOCUMENTATION_URL, "API_TOKENS_ENABLED": settings.API_TOKENS_ENABLED, "API_TOKEN_AUTH_ENDPOINT_ENABLED": settings.API_TOKEN_AUTH_ENDPOINT_ENABLED, + "CUSTOM_CSS": settings.CUSTOM_CSS, + "CUSTOM_JS": settings.CUSTOM_JS, } diff --git a/dojo/settings/settings.dist.py b/dojo/settings/settings.dist.py index ed1ee76c5c9..4a488a1a058 100644 --- a/dojo/settings/settings.dist.py +++ b/dojo/settings/settings.dist.py @@ -304,6 +304,9 @@ # For HTTP requests, how long connection is open before timeout # This settings apply only on requests performed by "requests" lib used in Dojo code (if some included lib is using "requests" as well, this does not apply there) DD_REQUESTS_TIMEOUT=(int, 30), + # Add custom styles and/or scripts to UI. All files need to be stored in "static" dir and path need to relative to this dir + DD_CUSTOM_CSS=(list, []), + DD_CUSTOM_JS=(list, []), ) @@ -820,6 +823,14 @@ def generate_url(scheme, double_slashes, user, password, host, port, path, param }, ] +# ------------------------------------------------------------------------------ +# UI +# ------------------------------------------------------------------------------ + +# Add custom styles and/or scripts to UI +CUSTOM_CSS = env("DD_CUSTOM_CSS") +CUSTOM_JS = env("DD_CUSTOM_JS") + # ------------------------------------------------------------------------------ # APPS # ------------------------------------------------------------------------------ diff --git a/dojo/templates/base.html b/dojo/templates/base.html index 5470baf13bd..6aaa61e5d61 100644 --- a/dojo/templates/base.html +++ b/dojo/templates/base.html @@ -61,6 +61,13 @@ + {% if CUSTOM_JS %} + + {% for one_js in CUSTOM_JS %} + + {% endfor %} + {% endif %} + @@ -96,6 +103,14 @@ {% block add_styles %} {% endblock %} + + {% if CUSTOM_CSS %} + + {% for one_css in CUSTOM_CSS %} + + {% endfor %} + {% endif %} +