From 1d14e9fdf00b4fb30b9eecdce69b874eccb09639 Mon Sep 17 00:00:00 2001
From: Dominik George <dominik.george@teckids.org>
Date: Sat, 27 Aug 2022 16:02:17 +0200
Subject: [PATCH] Remove Django debug toolbar

The DJDT is tightly coupled with Django templates, which we will not
use for the frontend anymore.
---
 CHANGELOG.rst                     |  3 +++
 aleksis/core/settings.py          | 26 --------------------------
 aleksis/core/urls.py              |  5 -----
 aleksis/core/util/core_helpers.py | 19 -------------------
 pyproject.toml                    |  1 -
 5 files changed, 3 insertions(+), 51 deletions(-)

diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 45dd496a1..cf42ea71b 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -24,6 +24,9 @@ Removed
 ~~~~~~~
 
 * Support for materialize-based frontend views (deprecated in 2.11)
+* Django debug toolbar
+  * It caused major performance issues and is not useful with the new
+    frontend anymore
 
 `2.11`_ - 2022-08-27
 --------------------
diff --git a/aleksis/core/settings.py b/aleksis/core/settings.py
index 43dab10b3..60f934407 100644
--- a/aleksis/core/settings.py
+++ b/aleksis/core/settings.py
@@ -56,29 +56,6 @@ SECRET_KEY = _settings.get("secret_key", "DoNotUseInProduction")
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = _settings.get("maintenance.debug", False)
 INTERNAL_IPS = _settings.get("maintenance.internal_ips", [])
-DEBUG_TOOLBAR_CONFIG = {
-    "RENDER_PANELS": True,
-    "SHOW_COLLAPSED": True,
-    "JQUERY_URL": "",
-    "SHOW_TOOLBAR_CALLBACK": "aleksis.core.util.core_helpers.dt_show_toolbar",
-    "DISABLE_PANELS": {},
-}
-
-DEBUG_TOOLBAR_PANELS = [
-    "debug_toolbar.panels.versions.VersionsPanel",
-    "debug_toolbar.panels.timer.TimerPanel",
-    "debug_toolbar.panels.settings.SettingsPanel",
-    "debug_toolbar.panels.headers.HeadersPanel",
-    "debug_toolbar.panels.request.RequestPanel",
-    "debug_toolbar.panels.sql.SQLPanel",
-    "debug_toolbar.panels.cache.CachePanel",
-    "debug_toolbar.panels.staticfiles.StaticFilesPanel",
-    "debug_toolbar.panels.templates.TemplatesPanel",
-    "debug_toolbar.panels.signals.SignalsPanel",
-    "debug_toolbar.panels.logging.LoggingPanel",
-    "debug_toolbar.panels.profiling.ProfilingPanel",
-    "django_uwsgi.panels.UwsgiPanel",
-]
 
 UWSGI = {
     "module": "aleksis.core.wsgi",
@@ -124,7 +101,6 @@ INSTALLED_APPS = [
     "menu_generator",
     "reversion",
     "phonenumber_field",
-    "debug_toolbar",
     "django_prometheus",
     "django_select2",
     "templated_email",
@@ -178,7 +154,6 @@ MIDDLEWARE = [
     "django.middleware.security.SecurityMiddleware",
     "django.contrib.sessions.middleware.SessionMiddleware",
     "django.contrib.auth.middleware.AuthenticationMiddleware",
-    "debug_toolbar.middleware.DebugToolbarMiddleware",
     "django.middleware.locale.LocaleMiddleware",
     "django.middleware.http.ConditionalGetMiddleware",
     "django.contrib.sites.middleware.CurrentSiteMiddleware",
@@ -282,7 +257,6 @@ else:
     }
 
 INSTALLED_APPS.append("cachalot")
-DEBUG_TOOLBAR_PANELS.append("cachalot.panels.CachalotPanel")
 CACHALOT_TIMEOUT = _settings.get("caching.cachalot.timeout", None)
 CACHALOT_DATABASES = set(["default", "default_oot"])
 SILENCED_SYSTEM_CHECKS += ["cachalot.W001"]
diff --git a/aleksis/core/urls.py b/aleksis/core/urls.py
index 726d8f065..b23b6f1d9 100644
--- a/aleksis/core/urls.py
+++ b/aleksis/core/urls.py
@@ -7,7 +7,6 @@ from django.views.decorators.csrf import csrf_exempt
 from django.views.i18n import JavaScriptCatalog
 
 import calendarweek.django
-import debug_toolbar
 from ckeditor_uploader import views as ckeditor_uploader_views
 from django_js_reverse.views import urls_js
 from health_check.urls import urlpatterns as health_urls
@@ -335,10 +334,6 @@ if hasattr(settings, "TWILIO_ACCOUNT_SID"):
 
     urlpatterns += [path("", include(tf_twilio_urls))]
 
-# Serve javascript-common if in development
-if settings.DEBUG:
-    urlpatterns.append(path("__debug__/", include(debug_toolbar.urls)))
-
 # Automatically mount URLs from all installed AlekSIS apps
 for app_config in apps.app_configs.values():
     if not app_config.name.startswith("aleksis.apps."):
diff --git a/aleksis/core/util/core_helpers.py b/aleksis/core/util/core_helpers.py
index 45a225361..178c8b25c 100644
--- a/aleksis/core/util/core_helpers.py
+++ b/aleksis/core/util/core_helpers.py
@@ -41,25 +41,6 @@ def copyright_years(years: Sequence[int], separator: str = ", ", joiner: str = "
     return separator.join(years_strs)
 
 
-def dt_show_toolbar(request: HttpRequest) -> bool:
-    """Add a helper to determine if Django debug toolbar should be displayed.
-
-    Extends the default behaviour by enabling DJDT for superusers independent
-    of source IP.
-    """
-    from debug_toolbar.middleware import show_toolbar  # noqa
-
-    if not settings.DEBUG:
-        return False
-
-    if show_toolbar(request):
-        return True
-    elif hasattr(request, "user") and request.user.is_superuser:
-        return True
-
-    return False
-
-
 def get_app_packages(only_official: bool = False) -> Sequence[str]:
     """Find all registered apps from the setuptools entrypoint."""
     apps = []
diff --git a/pyproject.toml b/pyproject.toml
index 021d852b2..e2fa977c4 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -57,7 +57,6 @@ secondary = true
 python = "^3.9"
 Django = "^3.2.5"
 django-any-js = "^1.1"
-django-debug-toolbar = "^3.2"
 django-menu-generator-ng = "^1.2.3"
 django-tables2 = "^2.1"
 django-phonenumber-field = {version = "^6.1", extras = ["phonenumbers"]}
-- 
GitLab